Encapsulation & Decapsulation — Segments → Packets → Frames → Bits
Encapsulation is what turns an abstract layered diagram into actual bytes on a wire. On the way down the stack, every layer wraps whatever the layer above handed it inside its own header — nesting dolls, envelopes inside envelopes. On the way up, every layer strips its own header and hands the rest along. The single rule that makes the whole internet composable falls out of this: each layer reads and writes only its own header, and treats everything inside as opaque cargo it never opens. That one picture explains routing, the MAC-versus-IP split, why encryption doesn't break forwarding, and why tiny packets waste bandwidth.
Key Components
- Encapsulation / decapsulation
- Encapsulation is the downward journey on the sending host: each layer takes the unit it received from above, prepends its own header, and passes the result down. Decapsulation is the exact mirror on the receiving side: each layer validates and removes its own header, then hands what remains upward. Nothing is ever rewritten in the middle — only wrapped and unwrapped at the ends.
- PDU (Protocol Data Unit)
- The name for "one unit of data at a given layer", including that layer's header. The word itself pins the layer: data (application), segment (TCP) or datagram (UDP), packet (IP), frame (Ethernet), bits (physical). Saying "the frame was dropped" versus "the packet was routed" is a statement about where something happened.
- Header and trailer
- A fixed-format block of control fields a layer attaches to its payload. Headers are prepended — added to the front — which is why the original application bytes sit untouched in the middle of the final frame. Layer 2 is the one layer that also appends a trailer: Ethernet's 4-byte FCS checksum, which must come last because it is computed over everything before it.
- The opaque-payload rule
- A layer parses its own header and nothing else. Ethernet has no idea it is carrying IP; IP never peeks at TCP; TCP never parses HTTP. The payload is bytes to be carried, not bytes to be understood. This is the layering principle made physical, and it is what lets a protocol change without every other layer changing with it.
- Demultiplexing (demuxing)
- The receiver's problem: given a blob of bytes, which upper-layer protocol should it be handed to? Solved by a pointer field in each header that names what is nested inside it — Ethernet's EtherType, IP's Protocol number, TCP's destination port. Follow the chain of signposts and you unwrap correctly every time, without guessing.
- MTU (Maximum Transmission Unit)
- The largest payload a single link-layer frame may carry — 1500 bytes on standard Ethernet. It caps how much application data one frame can amortize its fixed header cost across, which is why header overhead and MTU are the same conversation.
Concrete Example
Take a browser issuing GET / HTTP/1.1 over TCP to a web server. Follow those bytes down the sending host's stack and watch each layer wrap what it was given:
L7 App │ GET / HTTP/1.1 ... │ ← "Data"
L4 Transport │[TCP hdr]│ GET / ... │ │ ← "Segment"
L3 Network │[IP hdr]│[TCP hdr]│ GET / ... │ │ ← "Packet"
L2 Data Link │[Eth hdr]│[IP hdr]│[TCP hdr]│ GET / ... │[Eth FCS]│ ← "Frame"
L1 Physical │ 010101101000101110100101110001010110... │ ← "Bits"
Three details in that picture do most of the work. First, each layer's payload is the entire PDU from the layer above — header and all. IP does not carry "the HTTP request"; it carries "the TCP segment", which happens to contain the HTTP request. Dolls inside dolls. Second, headers are prepended, so the original application bytes never move; they simply end up further from the front. Third, L2 alone adds a trailer as well as a header.
The vocabulary is not decoration — each PDU name identifies a layer and what that layer contributed:
| Layer | PDU name | What that layer added |
|---|---|---|
| L7–5 Application | Data / message | the raw content itself |
| L4 Transport | Segment (TCP) / Datagram (UDP) | ports plus reliability control |
| L3 Network | Packet | source/destination IP, TTL |
| L2 Data Link | Frame | source/destination MAC, plus a trailer |
| L1 Physical | Bits | signalling only — no header |
The load-bearing header fields
Roughly 58 bytes of header get added to that request, and almost every field is one of the addressing ideas from the layer model turned into concrete bytes:
L4 TCP header (~20 B) src/dst PORT which application process
seq / ack # ordering and confirmation
flags SYN / ACK / FIN / RST
window flow control
checksum
L3 IP header (~20 B) src/dst IP end-to-end; never changes en route
TTL hop counter, −1 per router, 0 = drop
Protocol what L4 is inside (6=TCP 17=UDP 1=ICMP)
checksum
L2 Ethernet (14 B + 4 B) dst/src MAC one hop only; rewritten every hop
EtherType what L3 is inside (0x0800=IPv4,
0x0806=ARP, 0x86DD=IPv6)
FCS (trailer) error detection
Read the three address fields together and the hierarchy is literal, stacked in bytes: TCP carries ports (which application), IP carries end-to-end addresses (fixed for the whole journey), Ethernet carries MACs (valid for exactly one hop).
Demultiplexing: how the receiver knows how to unwrap
Bits arriving off a wire are just bits. The receiving machine never guesses what is inside them, because every header contains a "what's nested in me" pointer:
Ethernet ──EtherType 0x0800──► payload is IPv4
IP ──Protocol 6────────► payload is TCP
TCP ──Dest Port 443──────► hand to the HTTPS server process
Decapsulation is then just that chain walked in order. Each layer validates its own header, strips it, and uses the pointer to choose who gets the rest:
Bits → L2 (is this my MAC? is the FCS ok?) strip → EtherType says IPv4, up
→ L3 (is this my IP? TTL/checksum ok?) strip → Protocol says TCP, up
→ L4 (which port / which connection?) strip → port 443, hand to app
→ L7 application reads "GET / HTTP/1.1"
What routers and switches actually unwrap
Devices in the middle decapsulate only as far as their job requires — never further. A switch unwraps to L2, reads the destination MAC, forwards the frame out a port, and never looks at the IP or TCP inside. A router unwraps to L3, reads the destination IP, decides the next hop, and then does something that surprises people the first time they see it: it discards the entire Ethernet frame and builds a brand-new one for the next link.
Router: strip L2 → read/keep IP packet → decide next hop → TTL−1 → wrap in NEW L2 frame → send
The IP packet inside is handed on essentially untouched (only TTL and the header checksum change); the TCP and HTTP inside it are never opened at all. This is exactly why IP is end-to-end while MAC is rewritten every hop: the IP packet is the durable inner doll that travels the whole way, and the Ethernet frame is a disposable outer doll torn off and rebuilt at every router.
What the headers cost
TCP (20) + IP (20) + Ethernet header+trailer (18) ≈ 58 bytes of overhead per frame
That cost is fixed regardless of how much data rides inside it. A 1-byte payload still puts about 59 bytes on the wire — roughly 98% overhead. A full 1500-byte MTU-sized frame amortizes the same 58 bytes down to under 4%. That single ratio is why small, chatty packets hurt throughput and why MTU sizing matters at all.
Visual Model
Think of posting a letter through an office. You write the letter (the data). Your assistant seals it in an envelope marked with a room number (the TCP port). That envelope goes into a bigger one addressed to a building across the country (the IP addresses). That one goes into a courier bag addressed only to the van waiting outside (the MAC addresses) — a bag that gets thrown away and replaced at every depot along the route, while the country-wide envelope inside is never opened once. Nobody along the way reads the letter. They don't need to; each wrapper tells them exactly what they need, and each wrapper also carries a note saying what kind of thing is inside it, so whoever opens it knows who to pass it to next.
Step through it below. The first five steps wrap the request going down the sending stack — watch the PDU name on the right change as each header lands. The last five unwrap it on the receiving host, following the pointer chain at the bottom: EtherType names IP, IP's Protocol field names TCP, TCP's port names the application.
Loading…
Deeper — Edge Cases & Gotchas
The opaque-payload rule is what makes encryption possible
An HTTPS request is TLS-encrypted application data sitting inside a TCP segment inside an IP packet. Every router along the path forwards it correctly while being completely unable to read it — because a router was never reading it in the first place. It parses the IP header, consults a routing table, decrements TTL, rebuilds the frame, and sends. Encryption lives strictly inside the payload, and the payload is exactly the part nobody in the middle touches. The envelope is legible; the letter is not; delivery only ever needed the envelope.
The same property is why new application protocols can be deployed without upgrading a single router, and why a switch that has never heard of IPv6 still forwards IPv6 frames without complaint.
Only the final destination unwraps all the way to L7
Decapsulation is not an all-or-nothing operation. A switch unwraps to L2 and stops; a router unwraps to L3 and stops; only the endpoint continues to L4 and L7. Each device unwraps precisely as far as its forwarding decision requires and no further — which is both a performance property and a security property.
WRONG mental model — "each hop readdresses the packet":
hop 1: src IP 10.0.0.5 dst IP 10.0.0.1 (the router)
hop 2: src IP 10.0.0.1 dst IP 93.184.x.x
RIGHT — src/dst IP are constant end-to-end; only L2 is rebuilt:
hop 1: [Eth: me → router] [IP: 10.0.0.5 → 93.184.x.x] TTL 64
hop 2: [Eth: router → next] [IP: 10.0.0.5 → 93.184.x.x] TTL 63
Why it breaks: if IP addresses changed per hop, the destination would have no idea who to reply to and the end-to-end abstraction would collapse. MAC addresses are local — they only ever name "the next device on this link" — so they must be rewritten. IP addresses name the endpoints of the whole journey, so they must not be. The one deliberate exception is NAT, which rewrites IP addresses (and ports) on purpose. That is precisely why NAT is described as a layering violation and a special hack rather than normal routing: it breaks the invariant everything else depends on.
"the packet was dropped by the switch" ← a switch handles FRAMES
"the frame was routed to the next AS" ← routing acts on PACKETS
"the packet was retransmitted by TCP" ← TCP retransmits SEGMENTS
Why it matters: headers are prepended, so the layer name and the position in the byte stream line up — outermost header = lowest layer. And each PDU name pins the exact layer at which something happened, which is the fastest diagnostic signal there is. "Frames are being dropped" points at cabling, duplex mismatch or FCS errors; "packets are being dropped" points at routing, TTL expiry or congestion; "segments are being retransmitted" points at loss or window behaviour above IP. Collapsing the vocabulary throws away the layer information for free.
Overhead, MTU, and why chatty traffic is expensive
The ~58 bytes of TCP+IP+Ethernet overhead are paid per frame, not per byte of useful data. Sending 1500 bytes of payload as one full-MTU frame costs 58 bytes of headers; sending the same 1500 bytes as 30 small 50-byte writes costs 30 × 58 = 1740 bytes of headers — more overhead than payload. This is the arithmetic underneath Nagle's algorithm, message batching, and the general advice to avoid tiny writes on a socket. It is also why the L2 MTU propagates upward as a constraint on L4 segment sizing: the frame is the unit the overhead is charged against.
See Also
OSI 7-Layer Model Encapsulation is the OSI layer split made physical — the PDU names and the switch-versus-router distinction come straight from there. TCP/IP Model The stack these headers actually belong to; the narrow waist is why the IP header is the one wrapper every hop must agree on. How the Internet Works End-to-End The full journey in which this wrapping and per-hop re-framing happens, alongside DNS, ARP and the handshakes. Ethernet — Frame Format, MAC Addresses & EtherType The outermost doll in detail: the 14-byte header, the FCS trailer, the EtherType demux field and the 1500-byte MTU. Bandwidth vs Throughput vs Latency vs Jitter Where header overhead shows up as a measurable gap between raw link bandwidth and useful application throughput.Sources consulted
- RFC 1122 — Requirements for Internet Hosts (1989)
- IEEE 802.3 — Ethernet frame format
Test Yourself
A packet crosses 5 routers on its way to a server. How many times is the Ethernet frame rebuilt, and how many times do the IP source and destination change?
Bits arrive off the wire. How does the receiving machine know whether the Ethernet payload is IP or ARP, and then whether the IP payload is TCP or UDP?
Why can a router forward HTTPS traffic perfectly well even though it cannot read any of it? Connect your answer to a rule stated earlier.