Encapsulation of One Message
Follow five bytes down four layers, across the wire, and back up the other side.
Skip to the animationEncapsulation is the rule that each layer wraps the data from the layer above in its own header, so that every layer solves exactly one problem and can be replaced without disturbing the others.
Why layers at all
Getting a message from one program to another across the world needs several unrelated things solved: finding a route, surviving loss, identifying the right program, and physically moving bits. Solving them together produces something no one can change. Solving them separately means Wi-Fi can replace Ethernet without TCP noticing.
| Layer | Answers | Adds | Unit |
|---|---|---|---|
| Application | what does this mean? | HTTP, DNS, SMTP | message |
| Transport | which program, and did it arrive? | ports, sequence numbers | segment |
| Network | which machine, and by what route? | IP addresses | packet |
| Link | how do I cross this one hop? | MAC addresses, checksum | frame |
| Physical | how is a bit a signal? | — | bits |
OSI has seven layers and TCP/IP has four. The extra OSI layers — session and presentation — never found a real implementation, so the four-layer model is what the internet actually runs.
The vocabulary
- Protocol data unit
- What the thing is called at each layer: segment at transport, packet at network, frame at link. Different names for the same bytes with different amounts of header wrapped round them.
- Encapsulation
- A layer treats everything it receives from above as opaque payload and prepends its own header. It never looks inside, which is precisely what makes layers replaceable.
- Peer layers
- A layer only ever meaningfully talks to the same layer at the other end. TCP at one end reads the header TCP at the other end wrote, and nothing in between touches it.
- Propagation vs transmission delay
- Propagation is how long a bit takes to travel the distance — set by physics. Transmission is how long it takes to push all the bits out — set by bandwidth. Only the second improves when you buy a faster link.
- Round-trip time (RTT)
- Send to reply. Every acknowledgement-based protocol is ultimately paced by this, which is why the interesting question is always how much you can send before one arrives.
What is different about each header
- TCP header — survives end to end, untouched by anything in between. Ports and sequence numbers only mean anything to the two endpoints.
- IP header — also survives end to end, but every router reads it to decide where next. The TTL field is decremented at each hop.
- Ethernet header — stripped and rewritten at every hop. Its MAC addresses identify this link's two ends, not the conversation's two ends. This is the one students most often get wrong.
So a packet's IP addresses stay the same all the way across the internet while its MAC addresses change a dozen times. That difference is the whole distinction between routing and forwarding.
What layering costs
A five-byte GET / picks up roughly 20 bytes of TCP header, 20 of IP and 14 of Ethernet — around 54 bytes of overhead on 5 bytes of content. For bulk transfer that is negligible against a 1500-byte frame; for lots of tiny messages it dominates, which is why chatty protocols perform so badly.
Watch it work
Check yourself
question 1 / 4
One question at a time. Pick an answer to see why it is right or wrong, then move on — there is no score to keep and nothing is saved.