Type a branch, a subject or a topic — “round robin”, “paging”, “civil”.

Encapsulation of One Message

Follow five bytes down four layers, across the wire, and back up the other side.

Skip to the animation

Encapsulation 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.

LayerAnswersAddsUnit
Applicationwhat does this mean?HTTP, DNS, SMTPmessage
Transportwhich program, and did it arrive?ports, sequence numberssegment
Networkwhich machine, and by what route?IP addressespacket
Linkhow do I cross this one hop?MAC addresses, checksumframe
Physicalhow 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

loading visualisation…

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.

What is the correct name for the unit at each layer, going down?
A layer adds its header to the front of what it received. What does it do with the contents?
At the receiving host, decapsulation happens in which order?
Five bytes of user data arrive at the far end wrapped in four headers. What is the overhead argument?

0 / 4

4 still unanswered — the dots above jump straight to them.