Origin Academy
← Back to course

Network Protocol Developer Phase 0 is free

Join the waitlist

Phase 0 · Module 1 of 6

Layers: what really happens when you load a web page

OSI and TCP/IP models · 11 min read

Networking is built in layers, each solving one problem and relying on the one below. The OSI model has seven; the TCP/IP model that the internet actually runs on has four. Protocol developers use both: OSI for vocabulary, TCP/IP for how the code is organised.

The four TCP/IP layers

  • Link (OSI 1–2): getting a frame to the next device. Ethernet, Wi-Fi, MAC addresses, ARP.
  • Internet (OSI 3): getting a packet across networks. IPv4, IPv6, routing, ICMP.
  • Transport (OSI 4): getting data to the right program, reliably or not. TCP and UDP, ports.
  • Application (OSI 5–7): what the programs say to each other. DNS, HTTP, TLS, MQTT.

Encapsulation

Each layer wraps the data from the layer above in its own header. An HTTP request becomes the payload of a TCP segment, which becomes the payload of an IP packet, which becomes the payload of an Ethernet frame. The receiver unwraps them in reverse. Every protocol you will implement in this course is one of these wrappers: a header format, plus rules for what to do when one arrives.

Watch it happen

# in one terminal: capture DNS and HTTP traffic (Linux; needs root)
$ sudo tcpdump -n -i any 'port 53 or port 80'

# in another: fetch a page over plain HTTP
$ curl -s http://example.com > /dev/null

In the capture you'll see, in order: a DNS query and its answer over UDP port 53 (turning the name into an IP address), a TCP three-way handshake (SYN, SYN-ACK, ACK) to port 80, the HTTP request and response carried in TCP segments, and finally the connection being closed with FIN packets. Every line is a layer doing its job.

Try it

  • Run the capture and label each packet with the layer that matters most for it.
  • Repeat with https://example.com. What can you still see, and what has TLS hidden?
  • Use dig example.com and compare its output with the DNS packets you captured.

In the full course you go from here to writing these protocols yourself: sockets in C, packet capture with libpcap, TCP internals, implementing from RFCs, IoT protocols, TLS and high-performance I/O.

Next in Phase 0

Ethernet, MAC addresses and ARP

Continue →