The wire fails in five ways, and everything else follows
A network link promises only best effort. Each protocol above it exists to hide one of these failures.
Last lesson, the operating system gave programs one machine. Now two machines must talk, and between them is a wire you cannot trust. Send three packets, and five things can go wrong. They can arrive late: seventy milliseconds across a continent, at best. A router with a full queue can simply throw one away. They can arrive in the wrong order, because each packet is routed on its own. One can arrive twice, when a retry and its original both get through. And noise can flip a bit. The wire promises only best effort. Every protocol in this lesson exists to hide one of these five.
Why networks are layered · Going deeper · 1 of 2
The five failures, with real rates
Signals travel at about two-thirds the speed of light. Loss of 0.01% is healthy; above 1 to 5%, a reliable protocol turns into stop-and-go traffic. Routers crash and routes change too: a full buffer loses a packet in microseconds, a route change can stall traffic for tens of seconds.
Why networks are layered · Going deeper · 2 of 2
The stack and what each layer masks
Remove TCP and the network does not become reliable; the wire’s behaviour just stops being hidden from the application. That is the whole design.
Encapsulation
Each layer seals the one above inside its own envelope
Encapsulation: every layer adds a header for its own job and never looks inside. That is why each could evolve alone.
No single protocol could handle signals, addresses, reliability and meaning all at once. So the work is split into layers, each wrapped inside the next. In the middle is what you actually asked for: an HTTP request. TCP seals it in a segment, and makes the bytes complete and in order. IP seals that in a packet, and gets it to the right machine anywhere in the world. A router on the way opens only the outer two envelopes. Wifi or Ethernet seals that in a frame, and gets it to the next device. A frame holds at most fifteen hundred bytes, so a page travels as many packets.
Encapsulation · Going deeper · 1 of 2
Headers, layer by layer
Each layer prepends a header and strips it on receive. Real systems cross the lines for speed: network cards do TCP segmentation and TLS in hardware, and firewalls read inside HTTP on purpose. Layering is the abstraction, not always the implementation.
Encapsulation · Going deeper · 2 of 2
Two kinds of address on one link
Ethernet uses 48-bit MAC addresses; IP uses 32 or 128 bits. ARP bridges them: the host broadcasts “who has 192.168.1.5?” and the owner replies with its MAC. Across a router the MAC pair changes at every hop while the IP pair survives end to end.
Routing
No router knows the route; each one only knows the next hop
IP gives every machine a number. Routers pass a packet along by matching its address against a table of prefixes.
A packet has to reach any machine on Earth, across networks owned by different companies. Follow it to router two. This router has never heard of the server. All it has is a table of address prefixes, each with a next hop. It checks which entries match the destination. Anything matches the first. The second matches sixteen leading bits. The third matches twenty-four, and the most specific match wins. So the packet goes to router three. Every router does the same, making one local choice. Nobody plans the path; it is whatever those choices add up to.
Routing · Going deeper · 1 of 4
Prefixes and subnets
93.184.216.0/24 covers 256 addresses; the number after the slash counts the bits that name the network. Each bit borrowed from the host part doubles the subnets and halves their size. Two addresses per subnet are reserved.
Routing · Going deeper · 2 of 4
Longest-prefix match in action
Traceroute reveals the path with a trick: every router subtracts one from a packet’s time-to-live and reports back when it hits zero, so sending probes with TTL 1, 2, 3 names each hop in turn.
Routing · Going deeper · 3 of 4
Between companies: BGP
Each operator is an autonomous system. BGP announcements carry the list of systems a route has crossed, which detects loops. Operators prefer customer routes over peers over paid upstreams, so routes follow money as much as physics. Anycast announces one address from many sites, so each user reaches the nearest.
Routing · Going deeper · 4 of 4
Sharing one public address: NAT
A NAT rewrites the source address and port of outgoing packets and keeps a table to reverse it on replies. One public address has only 65,535 ports, so heavy users behind one NAT can run out.
TCP reliability
TCP numbers every byte, so anything missing can be asked for again
TCP builds a reliable stream from unreliable packets: number the bytes, acknowledge them, resend what was not acknowledged.
IP delivers packets, maybe. TCP turns that into a stream you can rely on. First a handshake of three short messages, so each side learns where the other’s byte numbering starts. That is one full round trip before any data moves. Then data. Every byte has a number, and each acknowledgement names the next byte the receiver expects. Now a segment is lost on the way. The one after it arrives fine. But the receiver has a gap, so it acknowledges fourteen sixty-one again. That repeat tells the sender exactly what is missing. The sender resends only that piece, and the stream is complete and in order.
TCP reliability · Going deeper
Handshake and acknowledgements in detail
Starting numbers are random so an outsider cannot guess them and inject data. Acks are cumulative; selective acks (SACK) let the receiver list exactly which ranges it holds. Two windows limit the sender: the receiver’s buffer, and the sender’s own estimate of what the network can take.
Check yourself
The receiver holds bytes 1001 – 1460 and 1921 – 2380. What does it acknowledge?
An acknowledgement always names the next byte expected in order. Repeating it is how the sender learns what to resend.
Congestion control
Senders find the network’s speed by probing: climb slowly, fall fast
Congestion control is an agreement among strangers: back off when a packet drops, so the shared link does not collapse.
Nobody tells a sender how fast the network is. It has to find out. A new connection may have ten packets in flight, and doubles that every round trip: twenty, forty, eighty. Then one packet is lost. The sender takes that as a sign of congestion and cuts its window in half. From there it grows by just one packet per round trip. Twenty-six round trips later it is still only at sixty-six. Climb slowly, fall fast. Because every sender follows the same rule, they end up sharing a busy link fairly. And it is why one lost packet on a long path costs far more than the bytes it carried.
Congestion control · Going deeper · 1 of 2
Slow start, then additive increase
Most web requests finish before leaving slow start. CUBIC, the Linux default, grows as a cubic function of time since the last loss. BBR measures bandwidth and round-trip time directly instead of waiting for loss. Oversized router buffers hide loss and add delay (bufferbloat); CoDel drops early to keep latency low.
Congestion control · Going deeper · 2 of 2
When reliability is the wrong goal: UDP
UDP has an 8-byte header and no connection, ordering or resending. A video frame 200 ms late is useless, so real-time traffic prefers it. TCP also has head-of-line blocking: one lost segment holds back everything behind it. QUIC, built on UDP, gives each stream its own recovery.
DNS
DNS turns a name into a number by asking three servers in turn
DNS is a worldwide, cached lookup with no central owner. Your resolver walks the tree once and remembers the answer.
People remember names. Routers need numbers. Your laptop asks one question of a resolver, usually run by your internet provider. The resolver asks a root server, which does not know the answer but knows who runs dot com. The dot com servers do not know either, but they know which servers belong to example dot com. Those servers hold the real answer. Two referrals, one answer. The resolver passes it back and remembers it for as long as the answer allows: minutes if the owner needs to switch servers quickly, days if it never changes.
DNS · Going deeper
Records, lifetimes and privacy
A records map a name to IPv4, AAAA to IPv6, CNAME is an alias, MX names mail servers, TXT holds proofs. Plain DNS is unencrypted and unauthenticated: DNS over HTTPS hides the question, and DNSSEC signs the answer. Treat a TTL as a minimum time to propagate, not a promise.
Idempotency and retries
A request can arrive twice, so make repeating it harmless
HTTP is a verb, headers and a body, answered by a status code. Because retries happen, safe systems make requests idempotent.
On top of all this sits HTTP, the language of the web. Every exchange has the same shape. A request: a verb, a path, headers, a body. A reply: a status code, headers, a body. The first digit of the code tells you what happened. Now the trap. The client sends a payment, and the server charges the card. The reply is lost on the way back. The client hears nothing, so it tries again, and the card is charged twice. The fix is to make repeats harmless. Send a unique key with the request. The server recognises the repeat and returns the first result. GET, PUT and DELETE are safe to repeat by design. POST is not.
Idempotency and retries · Going deeper · 1 of 2
Anatomy of a request
Most engineering lives in the headers: Authorization for credentials, Content-Type for format, Cache-Control for lifetime, If-None-Match for a conditional fetch that returns 304 instead of the body. Caching is the hardest part: many “works for me” bugs trace back to a cache header.
Idempotency and retries · Going deeper · 2 of 2
Three wire formats, one meaning
HTTP/1.1 is text, one request at a time per connection, so browsers open six. HTTP/2 interleaves many streams on one TCP connection, but one lost packet stalls them all. HTTP/3 runs on QUIC, where a loss stalls only its own stream.
Check yourself
A client’s payment request times out. It cannot tell whether the server processed it. What makes a retry safe?
The client cannot know which half failed. Only the server can tell a repeat from a new request, and only if the request carries something to recognise it by.
TLS key exchange
TLS lets two strangers agree a secret key in public
TLS is the S in HTTPS: one round trip to agree a key and prove the server’s identity, then everything is encrypted.
Everything so far travels in the open. TLS fixes that. Your browser says hello and sends a public value, A. The server replies with its own public value, B, plus a certificate and a signature. Each side combines the other’s public value with a secret of its own, and both arrive at the same key. Anyone watching sees A and B, and cannot work out the key. From here, everything is encrypted. That took one round trip. But a key shared with an impostor is worthless, so the certificate matters. It is signed by an authority, which is signed by a root authority your browser already trusts. One broken link and the browser refuses.
TLS key exchange · Going deeper · 1 of 2
The TLS 1.3 handshake
The key exchange is elliptic-curve Diffie-Hellman; bulk data then uses AES-GCM or ChaCha20 at gigabits per second. Resumed connections can send data on the first packet (0-RTT), which is faster but replayable, so only safe for idempotent requests.
TLS key exchange · Going deeper · 2 of 2
Walking the certificate chain
A certificate is a public key, a name and a signature. Leaves last about 90 days, intermediates years, roots decades. A stolen intermediate means thousands of certificates to reissue; a stolen root could impersonate any site until browsers ship an update.
Check yourself
On a live video call, one packet is lost. What should the transport do?
A late frame is worthless. That is why calls use UDP: TCP would hold everything behind the gap.
Summary
Opening one web page uses every layer, and costs four round trips
Each layer hides one failure of the wire so the layer above can pretend. Next: instructions, the languages programs are written in.
Put the lesson together by opening one page on a server seventy milliseconds away. DNS turns the name into a number. The TCP handshake sets up a reliable stream: one round trip. The TLS handshake makes it private and proves who the server is: another round trip. Only then does the HTTP request go out and the reply come back. About two hundred and thirty milliseconds before the first byte. The newest version, HTTP three, merges the two handshakes into one and saves a whole trip. Each layer hides one failure of the wire, so the layer above can pretend it is not there.
Lesson complete
You finished “Networking”
Answer the questions along the way to see your score here.