Encapsulation: Frames, Packets, Segments and Datagrams
What encapsulation means
Encapsulation means carrying higher-layer data inside a lower-layer protocol unit, typically by adding control information. A header precedes the carried data; a trailer follows it when the protocol uses one. Payload is relative to the layer: an IP packet’s payload may be a complete TCP segment, including its own header. A protocol data unit (PDU) is the unit exchanged by a protocol. Common names are TCP segment, UDP datagram, IP packet (also called an IP datagram), and Ethernet frame. Packet is also used informally as a broad term.
A 32-byte request, step by step
Assume an invented 32-byte application request over an established TCP connection, contained in one segment. Use IPv4 and TCP headers of 20 bytes each (no options), untagged Ethernet II with a 14-byte header and 4-byte frame check sequence (FCS). No fragmentation, tunneling or padding is needed. One byte is eight bits. The diagram counts the whole frame from Ethernet destination address through FCS, excluding preamble and interframe gap; capture tools may omit FCS.
Application: [32 B data]TCP: [20 B TCP | 32 B data] = 52 BIPv4: [20 B IP | 52 B TCP segment] = 72 BEthernet: [14 B Eth | 72 B IP packet | 4 B FCS] = 90 BThe TCP header identifies transport endpoints and stream position, IP carries source and destination addresses and forwarding information, and Ethernet includes local source/destination MAC addresses and a payload-type field. FCS helps detect transmission errors. The application sends 32 bytes, but the illustrative frame occupies 90 bytes under these assumptions.
What changes at a router?
Assume A and B are on different Ethernet LANs with router R1 between them. Switches S1 and S2 provide local forwarding.
A ---- S1 ---- R1 ---- S2 ---- B LAN 1 LAN 2A sends an Ethernet frame addressed to R1’s LAN 1 interface. R1 processes the IP packet, decreases IPv4 TTL (a forwarding lifetime limit) and updates the IPv4 header checksum. It sends a new Ethernet frame from its LAN 2 interface toward B. Without NAT or other modifying middleboxes, the source and destination IP addresses and TCP ports remain the same in this example. B processes the link framing, IP and transport information; the TCP stack delivers stream bytes to the application. This removal and interpretation of wrapping is called decapsulation.
Compare a UDP datagram
If the application instead sends 32 bytes using ordinary UDP, its 8-byte header gives a 40-byte UDP datagram. With the same 20-byte IPv4 header, the IP packet is 60 bytes; the Ethernet frame is 78 bytes including FCS. No TCP connection or TCP header is present. This is a separate example, not a way to make an existing TCP application switch protocols. Real TCP streams can span multiple segments; one application write is not guaranteed to match a segment. IP and TCP options, VLAN tags, padding and tunnels can change actual sizes.
Practice without sending traffic
Repeat the calculation with a 64-byte application payload and the same headers. Label each nested unit and describe which addresses change at the router. The accompanying offline fixture is a length and field model, not a captured packet or runnable network program. Next, study the physical media that carry these signals.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Encapsulation: Frames, Packets, Segments and Datagrams — knowledge check
Apply layered networking concepts to offline scenarios.
With 32 bytes of application data and a 20-byte TCP header, how large is the TCP segment?
With a 52-byte TCP segment and 20-byte IPv4 header, how large is the IPv4 packet?
Which information normally changes when an ordinary router forwards a packet onto a new Ethernet LAN, assuming no NAT?
A 32-byte application payload uses ordinary UDP with an 8-byte header. What is the UDP datagram size?
Why might a capture report 86 bytes for the example 90-byte Ethernet frame?