AlgoViz

How the OSI and TCP/IP models work

medium 40 min

A 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

  1. HTTP

Bytes

  1. 57
total = 57 bytes

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

LayerCheckResult
1L3ping 8.8.8.8ok
2L7 DNSdig shop.example
3L4connect to :443
4L6TLS handshake
5L7HTTP 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

    major

    ICMP tests layer 3. Firewalls, DNS, TLS and the app port can all still fail.

    Wrong
    ping shop.example   # works, so the network is fine
    Right
    dig shop.examplecurl -v https://shop.example/
  • Blocking all ICMP

    critical

    Path MTU discovery needs ICMP type 3 code 4. Without it, large packets vanish and transfers hang.

    Wrong
    drop icmp any
    Right
    allow icmp type 3 code 4allow icmp type 11
  • Saying routers change IP addresses

    major

    Routers change MAC addresses and the TTL. Only NAT changes addresses and ports.

    Wrong
    router: rewrite(src_ip)
    Right
    router: new_l2(); ttl -= 1nat:    rewrite(src_ip, src_port)
  • Reading refused and timeout as the same

    major

    Refused is a RST from a live host with no listener. A timeout is silence from a drop. Different layers, different fixes.

    Wrong
    except OSError: print("network down")
    Right
    except ConnectionRefusedError: check_listener()except TimeoutError: check_firewall_and_route()
  • Forcing every protocol into one OSI box

    minor

    TLS, ARP and QUIC cross layers. Interviewers want to hear that you know where they really run.

    Wrong
    TLS is layer 6. Full stop.
    Right
    TLS 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.