How Networks Work Module 1: What a network is Lesson 1.3 14 min

Layers: envelopes inside envelopes

A web page request is wrapped in a TCP header, then an IP header, then an Ethernet frame. Unwrap a real packet byte by byte and see which device reads which part.

Your laptop’s request for a web page has to answer a lot of questions on its way. Which program on the server should get it? Which computer on the internet is that server? Which device on this cable should pick it up next? And did any bit get damaged on the way?

No single header answers all of that. Instead, the request is wrapped several times, like a letter put in an envelope, which is put in a bigger envelope, which is put in a parcel. Each wrapping has its own address label, written for a different reader.

Unwrap one packet

Here a laptop asks a web server on the same network for a page, with curl (a tool that fetches a web page and prints it). Go to step 6, where the request itself leaves the laptop. The Bytes view shows that one frame as nested boxes, with the real bytes beside them. Point at any field to light up its bytes.

One web request, unwrapped

  1. laptop: curl http://web.example.test/ Before the request, three short messages open a connection (Module 5). Skip ahead to step 6.
    Time
    0 µs
    Cable
    laptop eth0 → sw1 1
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    SYN
    seq / ack
    0 / – (relative)
    On the wire
    70 bytes
    laptop TCP
    SYN-SENT → SYN-SENT
  2. sw1 floods: it does not know 00:80 yet sw1 writes down where 02:00:00:00:00:0a is: port 1. sw1 has no entry for 02:00:00:00:00:80 in its MAC table, so it floods the frame out of every other port (2).
    Time
    100.56 µs
    Cable
    sw1 2 → web eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    SYN
    seq / ack
    0 / – (relative)
    On the wire
    70 bytes
    sw1 MAC table
    learned 02:00:00:00:00:0a → port 1
  3. web: TCP SYN-ACK seq=0 ack=1 web agrees: SYN-ACK. It acknowledges the SYN and picks its own starting number. web's connection is now SYN-RECEIVED.
    Time
    201.12 µs
    Cable
    web eth0 → sw1 2
    Ethernet
    02:00:00:00:00:80 → 02:00:00:00:00:0a
    IP
    192.168.1.80 → 192.168.1.10
    TTL
    64
    TCP ports
    80 → 60465
    TCP flags
    SYN ACK
    seq / ack
    0 / 1 (relative)
    On the wire
    70 bytes
    web TCP
    LISTEN → SYN-RECEIVED
  4. sw1 forwards it out of port 1 only sw1 writes down where 02:00:00:00:00:80 is: port 2. sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
    Time
    301.68 µs
    Cable
    sw1 1 → laptop eth0
    Ethernet
    02:00:00:00:00:80 → 02:00:00:00:00:0a
    IP
    192.168.1.80 → 192.168.1.10
    TTL
    64
    TCP ports
    80 → 60465
    TCP flags
    SYN ACK
    seq / ack
    0 / 1 (relative)
    On the wire
    70 bytes
    sw1 MAC table
    learned 02:00:00:00:00:80 → port 2
  5. laptop: TCP ACK seq=1 ack=1 laptop acknowledges what it has received. laptop's connection is now ESTABLISHED.
    Time
    402.24 µs
    Cable
    laptop eth0 → sw1 1
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    ACK
    seq / ack
    1 / 1 (relative)
    On the wire
    64 bytes
    laptop TCP
    SYN-SENT → ESTABLISHED
  6. laptop: HTTP GET / laptop sends GET / HTTP/1.1.
    Time
    402.752 µs
    Cable
    laptop eth0 → sw1 1
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    PSH ACK
    seq / ack
    1 / 1 (relative)
    HTTP
    GET / HTTP/1.1
    On the wire
    138 bytes
  7. sw1 forwards it out of port 2 only sw1 knows 02:00:00:00:00:80 is on port 2, so only that port gets the frame.
    Time
    502.752 µs
    Cable
    sw1 2 → web eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    ACK
    seq / ack
    1 / 1 (relative)
    On the wire
    64 bytes
  8. sw1 forwards it out of port 2 only sw1 knows 02:00:00:00:00:80 is on port 2, so only that port gets the frame.
    Time
    503.856 µs
    Cable
    sw1 2 → web eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    PSH ACK
    seq / ack
    1 / 1 (relative)
    HTTP
    GET / HTTP/1.1
    On the wire
    138 bytes
  9. web receives TCP ACK seq=1 ack=1 web gets the frame. web's connection is now ESTABLISHED.
    Time
    603.264 µs
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    ACK
    seq / ack
    1 / 1 (relative)
    On the wire
    64 bytes
    web TCP
    SYN-RECEIVED → ESTABLISHED
  10. web: HTTP 200 The page comes back wrapped the same way, in the opposite direction.
    Time
    604.96 µs
    Cable
    web eth0 → sw1 2
    Ethernet
    02:00:00:00:00:80 → 02:00:00:00:00:0a
    IP
    192.168.1.80 → 192.168.1.10
    TTL
    64
    TCP ports
    80 → 60465
    TCP flags
    PSH ACK
    seq / ack
    1 / 81 (relative)
    HTTP
    HTTP/1.1 200 OK
    On the wire
    153 bytes
  11. sw1 forwards it out of port 1 only sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
    Time
    706.184 µs
    Cable
    sw1 1 → laptop eth0
    Ethernet
    02:00:00:00:00:80 → 02:00:00:00:00:0a
    IP
    192.168.1.80 → 192.168.1.10
    TTL
    64
    TCP ports
    80 → 60465
    TCP flags
    PSH ACK
    seq / ack
    1 / 81 (relative)
    HTTP
    HTTP/1.1 200 OK
    On the wire
    153 bytes
  12. laptop: TCP FIN-ACK seq=81 ack=96 laptop has nothing more to send: FIN. laptop's connection is now FIN-WAIT-1. laptop prints: <h1>Hello!</h1>
    Time
    807.408 µs
    Cable
    laptop eth0 → sw1 1
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    FIN ACK
    seq / ack
    81 / 96 (relative)
    On the wire
    64 bytes
    laptop TCP
    ESTABLISHED → FIN-WAIT-1
  13. sw1 forwards it out of port 2 only sw1 knows 02:00:00:00:00:80 is on port 2, so only that port gets the frame.
    Time
    907.92 µs
    Cable
    sw1 2 → web eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    FIN ACK
    seq / ack
    81 / 96 (relative)
    On the wire
    64 bytes
  14. web: TCP FIN-ACK seq=96 ack=82 web has nothing more to send: FIN. web's connection is now CLOSE-WAIT. web's connection is now LAST-ACK.
    Time
    1.008 ms
    Cable
    web eth0 → sw1 2
    Ethernet
    02:00:00:00:00:80 → 02:00:00:00:00:0a
    IP
    192.168.1.80 → 192.168.1.10
    TTL
    64
    TCP ports
    80 → 60465
    TCP flags
    FIN ACK
    seq / ack
    96 / 82 (relative)
    On the wire
    64 bytes
    web TCP
    ESTABLISHED → CLOSE-WAIT
    web TCP
    CLOSE-WAIT → LAST-ACK
  15. sw1 forwards it out of port 1 only sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
    Time
    1.109 ms
    Cable
    sw1 1 → laptop eth0
    Ethernet
    02:00:00:00:00:80 → 02:00:00:00:00:0a
    IP
    192.168.1.80 → 192.168.1.10
    TTL
    64
    TCP ports
    80 → 60465
    TCP flags
    FIN ACK
    seq / ack
    96 / 82 (relative)
    On the wire
    64 bytes
  16. laptop: TCP ACK seq=82 ack=97 laptop acknowledges what it has received. laptop's connection is now FIN-WAIT-2. laptop's connection is now TIME-WAIT.
    Time
    1.209 ms
    Cable
    laptop eth0 → sw1 1
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    ACK
    seq / ack
    82 / 97 (relative)
    On the wire
    64 bytes
    laptop TCP
    FIN-WAIT-1 → FIN-WAIT-2
    laptop TCP
    FIN-WAIT-2 → TIME-WAIT
  17. sw1 forwards it out of port 2 only sw1 knows 02:00:00:00:00:80 is on port 2, so only that port gets the frame.
    Time
    1.31 ms
    Cable
    sw1 2 → web eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    ACK
    seq / ack
    82 / 97 (relative)
    On the wire
    64 bytes
  18. web receives TCP ACK seq=82 ack=97 web gets the frame. web's connection is now CLOSED.
    Time
    1.41 ms
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:80
    IP
    192.168.1.10 → 192.168.1.80
    TTL
    64
    TCP ports
    60465 → 80
    TCP flags
    ACK
    seq / ack
    82 / 97 (relative)
    On the wire
    64 bytes
    web TCP
    LAST-ACK → CLOSED

From the inside out, step 6’s frame is:

  1. HTTP (application layer): the request itself, plain text: GET / HTTP/1.1, then which website (Host:) and a few more lines. This is what the browser and the web server care about.
  2. TCP (transport layer): port numbers, which say which program on each computer this belongs to (the web server listens on port 80), plus numbers that let the receiver put pieces in order and notice a missing one.
  3. IP (internet layer): the IP address of the sender and of the final receiver. Routers read this to carry the packet across networks.
  4. Ethernet (link layer): the MAC address of the next device on this cable, and at the very end a 4-byte check (FCS) that lets the receiver notice damaged bits.

Wrapping data in a header is called encapsulation. Unwrapping it at the other end, layer by layer, is the reverse.

Why layers help

Each layer only reads its own header and trusts the others to do their job.

  • The switch in the lab read the Ethernet header and nothing else. It works the same for web pages, games and video calls, because it never looks inside.
  • The browser and the web server only care about HTTP. They do not know or care whether the bytes crossed Wi-Fi, a fibre or a cable.
  • A layer can change without the others noticing. Your laptop can move from Wi-Fi to a cable in the middle of a download, and HTTP never knows.

The trade-off is size: every layer adds bytes. Here, 58 of the 138 bytes on the cable were wrapping around an 80-byte request.

In the real world

You may see layers numbered 1 to 7. That is the OSI model, a reference drawn up in the 1980s: 1 physical (the signal on the wire), 2 data link (Ethernet), 3 network (IP), 4 transport (TCP, UDP), 5 session, 6 presentation, 7 application. The internet really uses the four layers in this lesson, and nobody draws 5 and 6 separately, but engineers still say “a layer 2 problem” for an Ethernet or Wi-Fi fault and “layer 7” for the application.

Recap

  • A request is wrapped in headers: HTTP inside TCP inside IP inside an Ethernet frame (encapsulation).
  • Each layer has its own reader: switches read Ethernet, routers read IP, the two ends read TCP and HTTP.
  • TCP adds port numbers, which pick the program; IP adds the end-to-end addresses; Ethernet the next hop.
  • Layers can change independently, at the cost of a few bytes of header each.

Quick check

  1. Which layer adds the port numbers that pick the program on each computer?
  2. A router carries a packet from one network to the next. Which header does it read to decide where to send it?
  3. What is the main advantage of splitting networking into layers?

Your progress is saved in this browser. Sign in to keep it on every device. Free, no password.

Join the discussion