How the Internet Works: OSI and TCP/IP
Understand the layered models of networking, what each layer is responsible for, and how a packet is encapsulated from your app down to the wire and back.
Beginner · about 5 hours · difficulty 2/5
Networking is easiest to learn as a stack of layers, each solving one problem and relying on the one below. Interviewers use the models as a map, so you should be able to place any protocol or device on it.
The two models
- OSI (7 layers): Physical, Data Link, Network, Transport, Session, Presentation, Application. A teaching model.
- TCP/IP (4 or 5 layers): Link, Internet (IP), Transport (TCP/UDP), Application (HTTP, DNS, SMTP). This is what the real internet runs on.
What each layer does
- Physical: bits on copper, fibre or radio.
- Data link: frames between directly connected machines, MAC addresses, error detection (CRC), switches, Ethernet, Wi-Fi.
- Network: routing packets across networks with IP addresses; routers live here.
- Transport: process-to-process delivery using ports; reliability (TCP) or speed (UDP).
- Application: the protocols your software speaks.
Encapsulation
Your HTTP request becomes a TCP segment (adds ports), then an IP packet (adds IPs), then an Ethernet frame (adds MACs). Each hop's router strips the frame, reads the IP header, and re-frames it for the next link. ARP resolves an IP to a MAC on the local network.
Devices and terms
Hub (layer 1), switch (layer 2), router (layer 3), and gateway; LAN vs WAN; bandwidth vs latency vs throughput; circuit vs packet switching.
Good enough to move on: you can narrate, layer by layer, what happens when you type a URL and press Enter, which is one of the most common networking interview questions.
Key concepts
- OSI model layers
- TCP/IP model
- Encapsulation and headers
- MAC addresses and ARP
- Hubs, switches and routers
- Bandwidth, latency, throughput
- What happens when you type a URL
Mini project
Capture your own traffic with Wireshark while loading a website and annotate one request through every layer: Ethernet frame, IP header, TCP segment and HTTP payload, noting source and destination at each level.
Check yourself
When a packet crosses three routers to reach a server, which addresses change at each hop and which stay the same?
Free resources
- Computer Networking: A Top-Down Approach (author resources) (Kurose and Ross)
- MDN: How does the Internet work? (MDN)
- Cloudflare Learning Center: What is the OSI model? (Cloudflare)