Every time you load a page, a message travels across the planet, through a dozen machines you'll never see, and back — usually in under a tenth of a second. That this works at all, reliably, between devices built by different vendors running different software, is one of computing's quiet miracles. The trick behind it is layering: instead of one impossibly complex system, networking is a stack of small, independent problems, each solved once and reused everywhere.
The Layered Model
The classic teaching tool is the OSI model — seven conceptual layers describing how data flows down the stack on the sender, across the wire, and back up on the receiver.
The OSI model is useful for vocabulary ("that's a layer-7 load balancer," "this is a layer-2 switch"), but real networks run the leaner TCP/IP model, which collapses those seven into four practical layers:
The point of layering is independence: each layer talks only to the one above and below it through a fixed interface. TCP doesn't care whether your packets travel over fiber or WiFi; HTTP doesn't care whether TCP retransmitted a lost segment. You can swap Ethernet for WiFi, or IPv4 for IPv6, without rewriting a single web server. This is the same modularity principle that governs good software design — narrow interfaces, hidden implementations.
Grand Analogy: Sending a letter through a corporate mail system. You write the letter (Application). You seal it in a tracked envelope (Transport). You write the destination address (Internet). The mail carrier drives it to the next post office (Link). Nobody at any step needs to understand the others' jobs — the address-writer doesn't drive the truck, and the driver doesn't read your letter.
Encapsulation
How does one layer hand data to the next without the layers getting tangled? Each layer wraps the data from the layer above in its own header — like nesting dolls. The receiver unwraps them in reverse.
A useful vocabulary note that trips up beginners: the same bundle of bytes has a different name at each layer. At the Transport layer it's a segment (TCP) or datagram (UDP); at the Internet layer it's a packet; at the Link layer it's a frame. Same data, different wrapper.
IP Addresses
An IP address is the globally meaningful "where" of networking — it identifies a host anywhere on the internet.
IPv4 is a 32-bit address written as four octets, like 192.168.1.100. That's about 4.3 billion addresses — which sounded infinite in 1981 and ran out years ago. IPv6 uses 128 bits (2001:0db8:85a3::8a2e:0370:7334), enough to give every grain of sand on Earth billions of addresses. We've spent two decades slowly migrating, propped up by workarounds like NAT (below).
Certain IPv4 ranges are private — reserved for use inside local networks and never routed on the public internet: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. Your home devices almost certainly have addresses in one of these.
An address has two parts: a network portion (which network you're on) and a host portion (which device on that network). The dividing line is set by the subnet mask, written in CIDR shorthand as a slash and a bit count.
Analogy: The network portion is the street name; the host portion is the house number. Every house on the same street shares the street name. Routers care about getting your letter to the right street; only the final local delivery cares about the house number.
The Local Hop — MAC Addresses and ARP
IP addresses get a packet to the right network, but the actual hardware on a local network (your WiFi, an office Ethernet) delivers frames using MAC addresses — a permanent 48-bit identifier burned into each network card. IP is logical and routable; MAC is physical and local.
So when your laptop wants to send a packet to 192.168.1.1 (your router), it needs that router's MAC address. It finds it with ARP (Address Resolution Protocol): it shouts to the whole local network, "Who has 192.168.1.1?" and the owner replies with its MAC. This is why the link layer exists as a separate concern — IP is a global abstraction layered on top of whatever local delivery mechanism is actually present.
One more link-layer detail every engineer eventually meets: the MTU (Maximum Transmission Unit), the largest frame a link can carry — typically 1500 bytes on Ethernet. Packets larger than the MTU must be fragmented, which hurts performance, so TCP negotiates a segment size that fits.
Routing — Finding the Way
A packet rarely reaches its destination in one hop. Routers forward it toward its destination one step at a time, each consulting a routing table that maps destination networks to the next router along the way:
| Destination | Next Hop | Interface |
|---|---|---|
| 10.0.0.0/8 | 192.168.1.1 | eth0 |
| 172.16.0.0/16 | 10.0.0.1 | eth1 |
| 0.0.0.0/0 (default route) | 10.0.0.254 | eth1 |
The last entry, 0.0.0.0/0, is the default route — "if nothing else matches, send it here." It's how your home router handles every address it doesn't specifically know about: it just forwards to your ISP.
Analogy: Routing is like asking for directions in an unfamiliar country. You don't need the whole route — you ask a local, who says "head to the highway." At the highway, a sign says "city center, exit 5." Each step gets you closer, and no single person knows the entire path.
TCP vs UDP — Two Philosophies of Delivery
The Internet layer (IP) makes no promises: packets can be lost, duplicated, or arrive out of order. The Transport layer decides what to do about that, and offers two opposite answers.
Analogy: TCP is registered mail with tracking — you know it arrived, in what order, and lost items are resent. UDP is shouting across a room — fast, but some words may be lost. For a live video call you'd rather drop a frame than pause to recover it, so UDP wins; for a bank transfer, correctness is everything, so TCP wins.
Inside TCP
TCP turns IP's unreliable packet delivery into a reliable, ordered byte stream. It's worth understanding the three mechanisms that make this work — they show up constantly in performance debugging.
The three-way handshake establishes a connection before any data flows, so both sides agree on starting sequence numbers and that the other is reachable.
Sequence numbers and acknowledgements provide reliability. Every byte is numbered; the receiver acknowledges what it has received. If the sender doesn't get an ACK in time, it retransmits:
Sender: "Here are bytes 1–100" (SEQ=1)
Receiver: "Got it, send from 101" (ACK=101)
Sender: "Here are bytes 101–200" (SEQ=101)
... (packet lost, no ACK) ...
Sender: (timeout) "Here are 101–200 again"
The sliding window is what makes TCP fast. Rather than waiting for an ACK after every packet (which would waste a full round-trip each time), the sender keeps multiple packets "in flight" up to the window size. As ACKs return, the window slides forward.
Congestion control is the final piece — and a genuinely beautiful piece of distributed cooperation. TCP starts slow ("slow start"), ramps up its sending rate, and backs off sharply the moment it detects packet loss (a signal of congestion). Because every TCP connection on Earth follows this discipline, the internet shares its capacity gracefully instead of collapsing under load.
Analogy: Congestion control is highway driving. You start gently, speed up as the road stays clear, and slam the brakes when you see tail lights ahead (loss) — then cautiously accelerate again. Millions of drivers doing this independently keep traffic flowing without a central controller.
DNS — The Phone Book of the Internet
Humans remember names; machines route to numbers. DNS (Domain Name System) translates www.google.com into an IP address. It's a globally distributed, cached, hierarchical database — and the lookup walks down that hierarchy:
Analogy: DNS is like directory assistance. You ask the operator for "Google," they don't know offhand, so they ask whoever manages
.com, who points to Google's own records. Once anyone learns the answer, they remember it (cache it) for a while.
Caching is what keeps DNS fast: your browser, your OS, and your resolver all cache results for the duration of each record's TTL (time-to-live). The vast majority of lookups are answered from cache and never touch the root servers.
Ports and Sockets
An IP address gets you to a machine. But a machine runs many services at once — a web server, a database, an SSH daemon. A port number identifies which service.
The combination of IP address, port, and protocol is a socket — the endpoint of a connection. A full connection is a pair of sockets, and it's this four-tuple (source IP/port + destination IP/port) that uniquely identifies every conversation your machine is having, which is how one server handles thousands of simultaneous clients on a single port.
Analogy: If an IP address is a building's street address, the port is the apartment number. Mail to "123 Main St, Apt 443" reaches the HTTPS tenant specifically.
NAT — One Public IP, Many Devices
Your home has a dozen devices but typically one public IP from your ISP. NAT (Network Address Translation), running in your router, lets them all share it by rewriting addresses and ports as traffic passes through, then reversing the translation on the way back.
NAT was invented as a stopgap for IPv4 exhaustion, but it has a lasting side effect: devices behind NAT aren't directly reachable from the internet, which acts as an accidental firewall — and also why peer-to-peer apps (video calls, games) need clever "hole-punching" tricks to connect two devices that are both behind NAT.
HTTP — The Language of the Web
Atop TCP sits HTTP, the request/response protocol that powers the web. A client sends a request; the server returns a response. Both are plain, structured text (in HTTP/1.1):
HTTP methods describe the intent of a request. The key property to understand is idempotency — whether repeating a request has the same effect as making it once. This matters enormously for retries: a client can safely retry an idempotent request after a network hiccup, but retrying a POST might create a duplicate order.
| Method | Purpose | Idempotent? |
|---|---|---|
| GET | Retrieve data | Yes |
| POST | Create / submit data | No |
| PUT | Replace a resource | Yes |
| PATCH | Partially update | No |
| DELETE | Remove a resource | Yes |
Status codes tell the client what happened, grouped by their first digit:
| Range | Meaning | Examples |
|---|---|---|
| 1xx | Informational | 101 Switching Protocols |
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirection | 301 Moved Permanently, 304 Not Modified |
| 4xx | Client error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found |
| 5xx | Server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
A reliable mnemonic: 4xx is your fault (the client sent something wrong), 5xx is the server's fault (it failed to handle a valid request).
HTTP Versions — The Quest to Kill Latency
HTTP has evolved to fight one enemy: head-of-line blocking, where one slow item holds up everything behind it.
Analogy: HTTP/1.1 is a one-lane road — one car at a time. HTTP/2 is a multi-lane highway — many cars, one road, but one accident still blocks every lane. HTTP/3 is several independent roads — if one is blocked, the others keep flowing.
HTTPS is simply HTTP carried over an encrypted TLS channel. The next chapter unpacks exactly how that encryption is established without ever sending a secret key in the clear.
The Life of a Web Request
It's worth stitching every layer together with one concrete story — typing example.com and pressing Enter:
- DNS resolves
example.comto an IP address (cache → resolver → root → TLD → authoritative). - Your OS finds the route; ARP discovers the router's MAC for the local hop.
- TCP performs its three-way handshake with the server on port 443.
- TLS negotiates an encrypted channel (Chapter 18).
- HTTP sends
GET / HTTP/1.1; the request is encapsulated down the stack, routed hop by hop across the internet, and reassembled on the server. - The server responds; TCP guarantees the bytes arrive complete and in order; your browser renders the page.
Every concept in this chapter participated in that one tenth of a second. That's the payoff of layering: each piece does one job, and together they make the impossible routine.