How the OSI and TCP/IP models work
medium 40 minA network request is a message wrapped in headers, one per layer, like dolls inside dolls.
See it run
Follow one HTTPS request down the stack, across the network, and up again. Watch which headers each device reads and changes.
Operations
Encapsulation
Each layer puts its header in front of what it got from above. 57 bytes become 137.
Step 1 of 5
The message
One frame, outermost header first
- HTTP
Bytes
- 57
57 bytes of HTTP: the request line, Host, Accept and an empty line. Only the app knows what they mean.
Step 1: The message
msg = b"GET /orders HTTP/1.1..." # 57 bytes, L7rec = tls_record(msg) # +22 -> 79seg = tcp_header(51514, 443) + rec # +20 -> 99pkt = ip_header(src, dst, ttl=64) + seg # +20 -> 119frame = eth(gw_mac, my_mac) + pkt # +14 -> 133, card adds FCS 4- Bytes or round trips
- +80 bytes
- Who reads it
- 4 headers
- Fits in MTU 1500?
- 119 bytes: yes
Count the headers out loud: 14 + 20 + 20, plus 4 at the end. Interviewers love the numbers.
In the real world
The same how the osi and tcp/ip models work doing real jobs. Pick one and step through it.
Sam can ping the internet but the shop's page will not load. Go up one layer at a time.
Step 1 of 4
Layer 3 works
| Layer | Check | Result | |
|---|---|---|---|
| 1 | L3 | ping 8.8.8.8 | ok |
| 2 | L7 DNS | dig shop.example | |
| 3 | L4 | connect to :443 | |
| 4 | L6 | TLS handshake | |
| 5 | L7 | HTTP status |
ping 8.8.8.8 answers. Link, neighbour and route are fine for ICMP.
Step 1: Layer 3 works
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Treating ping as proof that the app works
majorICMP tests layer 3. Firewalls, DNS, TLS and the app port can all still fail.
Wrongping shop.example # works, so the network is fineRightdig shop.examplecurl -v https://shop.example/Blocking all ICMP
criticalPath MTU discovery needs ICMP type 3 code 4. Without it, large packets vanish and transfers hang.
Wrongdrop icmp anyRightallow icmp type 3 code 4allow icmp type 11Saying routers change IP addresses
majorRouters change MAC addresses and the TTL. Only NAT changes addresses and ports.
Wrongrouter: rewrite(src_ip)Rightrouter: new_l2(); ttl -= 1nat: rewrite(src_ip, src_port)Reading refused and timeout as the same
majorRefused is a RST from a live host with no listener. A timeout is silence from a drop. Different layers, different fixes.
Wrongexcept OSError: print("network down")Rightexcept ConnectionRefusedError: check_listener()except TimeoutError: check_firewall_and_route()Forcing every protocol into one OSI box
minorTLS, ARP and QUIC cross layers. Interviewers want to hear that you know where they really run.
WrongTLS is layer 6. Full stop.RightTLS does presentation work but runs inside the app on top of TCP.
Interview tips
How to explain it
- Link: next door by MAC.
- Internet: across networks by IP.
- Transport: program to program by port.
- Application: what the bytes mean.
Memory trick
- Dolls: green, red, blue, note.
- Each layer reads only its twin's header.
- Refused is an answer, a timeout is silence.
Always say
- The lowest layer that fails.
- The command that proves it.
- What that result rules out.
- Which device touches which header.
Numbers to know
- Ethernet 14 + 4, IPv4 20, TCP 20, UDP 8.
- MTU 1500, MSS 1460, IPv6 minimum 1280.
- TTL 64 on Linux, ports 32768 to 60999.
- About 3 RTT to the first HTTPS byte.