Course contents

02. Networking and Internet Lesson 1 of 10

How the Internet Works

Follow packets from your laptop through home router, ISP and transit networks to a server: DNS first, hop-by-hop routing, BGP paths and rerouting on failure.

12 minBeginner8 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • The internet is tens of thousands of autonomous systems that exchange traffic at routers.
  • Data is split into packets; each router forwards each packet one hop closer by longest prefix match.
  • Names are resolved to IP addresses before any packet goes to the server.
  • BGP tells networks which prefixes are reachable through whom; choices follow policy, and failures trigger withdrawals and reconvergence.
  • Light in fibre covers about 200 km per millisecond, so distance puts a floor under every round trip.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

The internet is a network of networks. Tens of thousands of independently operated networks, called autonomous systems (AS), each identified by a number, agree to carry traffic for each other. Your ISP is one, a cloud provider is one, a large university is one. They connect directly (peering, often at internet exchange points) or pay larger transit providers to reach everyone else.

What travels between them is IP packets: small units of data, each with a header that carries a source and a destination address. Routers at every junction read the destination and forward each packet one hop closer. Nobody controls the whole thing, and no device knows the full path.

Why it exists

A single global network run by one operator would be a single point of failure and a single point of control. Packet switching between independent networks lets each operator run its part its own way, lets links fail without stopping communication, and lets many conversations share the same cables efficiently. The price is that delivery is best effort: packets can be delayed, lost, duplicated or reordered, and the endpoints have to cope.

How it works

1. Resolve the name. A browser asked for example.com first resolves it to an IP address via DNS. The query and the answer are ordinary packets to and from a resolver, usually the one the ISP or the network configured. Only then can anything go to the server.

2. Packetise. The sender's network stack splits data into packets that fit the path's MTU, commonly 1,500 bytes on Ethernet. TCP (or QUIC over UDP) numbers the data so that the receiver can put it back in order and ask for what is missing; IP itself does not.

3. Forward hop by hop. Each router has a forwarding table of prefixes (203.0.113.0/24, 0.0.0.0/0 for "everything else") mapped to next hops. For each packet it picks the longest matching prefix and sends the packet to that neighbour. It also decrements the packet's TTL (hop limit in IPv6); a packet whose TTL reaches zero is dropped and an ICMP "time exceeded" message is sent back. Traceroute uses exactly that to reveal the routers on a path. A home router's table is tiny (local network, plus a default route to the ISP); a router in the default-free zone of the internet carries roughly a million IPv4 prefixes and a couple of hundred thousand IPv6 prefixes in 2026.

4. Exchange routes with BGP. Routers inside one network learn routes from an internal protocol (OSPF, IS-IS). Between networks, the Border Gateway Protocol carries reachability: "prefix 203.0.113.0/24 can be reached through AS 64501, AS 64510". Each network decides which announcements to accept, which to prefer and which to pass on. Best-path selection starts with policy, such as local preference that favours a cheaper customer or peer link over paid transit, and then uses attributes such as AS-path length. BGP knows nothing about current latency or congestion.

5. Route around failure. When a link or router fails, the BGP sessions over it drop and the routes learned through it are withdrawn. Neighbours fall back to their next-best paths and announce the change onward. This convergence takes from well under a second (with fast failure detection inside a network) to minutes across the internet, and during it some packets are dropped or loop until their TTL runs out.

6. Distance sets latency. Light in fibre travels about 200,000 km/s, roughly 5 µs per kilometre. A 6,000 km path costs at least 30 ms each way before any router, queue or server adds anything. Every round trip (DNS, TCP handshake, TLS handshake, each request that waits for a response) pays it again.

When to use it

This model is the background for nearly every latency and availability decision: placing servers or CDN edges near users, counting round trips in a protocol, choosing regions, understanding why a "network blip" happened, and reading traceroute output during an incident.

When not to

  • Do not design as if the path is fixed or private. Routes change under you and traffic crosses networks you do not control; encrypt in transit and expect variable latency.
  • Do not treat a single ISP or transit link as reliable infrastructure for critical sites; multihome with more than one upstream.
  • Inside a data centre the same principles apply, but the topology (leaf-spine fabrics) and timescales (microseconds) are very different from the public internet.

Trade-offs

Choice You gain You pay
Packet switching (shared links) Efficient use of capacity, resilience to failures Variable delay, possible loss and reordering
Policy-based BGP routing Each network controls its own traffic and costs Paths are not the fastest; misconfiguration can spread globally
Serving from one region Simple operations, one copy of the data Distant users pay long round trips
Serving from many edges (CDN, anycast) Short round trips, absorbs attacks Cost, cache consistency, more moving parts

Alternatives

  • Private backbones: large cloud and content providers carry traffic across their own global networks and hand it to the public internet as close to the user as possible.
  • Dedicated interconnects (cloud direct-connect products, leased lines): predictable paths between your sites and a provider, without crossing the public internet.
  • Overlay networks and VPNs: tunnel traffic over the internet with their own routing on top (SD-WAN, mesh VPNs).

Failure modes

  • Route leaks and hijacks: a network announces prefixes it should not, and traffic is diverted or blackholed. RPKI route origin validation, now widely deployed, rejects announcements from unauthorised origins; it does not stop every leak.
  • Slow convergence: after a failure, packets are dropped or loop for seconds to minutes.
  • Fibre cuts and congested peering links: latency jumps or traffic reroutes onto longer paths.
  • MTU problems: tunnels shrink the usable packet size; if ICMP is filtered, large packets silently disappear ("path MTU blackhole").
  • DNS failure: the network works, but nothing can be found by name.

In production

Teams pick regions close to their users, put static and cacheable content on a CDN, and use anycast or global load balancers so users reach a nearby edge. Critical sites are multihomed (several upstream providers) and sign their prefixes with RPKI. During incidents, traceroute and mtr from several vantage points show where along the path latency or loss appears; BGP looking glasses and route collectors show what the rest of the internet sees.

Common misconceptions

  • "The internet is one network someone runs." It is many networks with separate owners and policies.
  • "My packets take the shortest path." They take the path each network's policy prefers, which can be much longer.
  • "Faster servers fix latency for distant users." Propagation delay does not shrink with server speed; only moving closer or saving round trips helps.
  • "A request is one packet." Most requests and nearly all responses span many packets, plus handshake packets before them.

Interview angle

You will rarely be asked to explain BGP, but you will be expected to reason about the consequences: distant users mean long round trips, so put a CDN or regional deployment in front; handshakes and DNS add round trips, so reuse connections; networks fail and reroute, so design for retries and variable latency. Being able to estimate RTT from distance (about 1 ms of round trip per 100 km of fibre) is a quick way to show you understand where latency comes from.

Model assumptions

This lesson is a scripted walk-through, not a simulation: every packet is placed by hand to show the order of hops, and routing tables and BGP state are labels. One-way latencies are illustrative (3 ms over Wi-Fi to the home router, 10 ms on the access line to the ISP, 6 ms to and from the transit network, 30 ms across a long-haul backbone link of about 6,000 km, 2 ms inside the hosting network, about 1 ms per router to forward). Real paths have more routers (often 10–20 hops), queueing delay and loss. The response is shown retracing the request's path for clarity; on the internet, return paths are often different (asymmetric routing). BGP reconvergence is compressed to a few tens of milliseconds.

The lesson as textEvery step of the simulation, written out.
  1. 1. A network of networks

    The internet is not one network. It is tens of thousands of independently run networks, called autonomous systems (AS), that agree to carry each other’s traffic. Your home network connects to your ISP; the ISP connects to transit providers and peers; the company hosting example.com connects to them too.

    Where networks meet sit routers. Each one only decides the next hop for a packet. No device knows the whole path. (This lesson is a scripted illustration: packets are drawn by hand, not simulated.)

    Scene: Your laptop, a home router, the ISP router with its DNS resolver, two transit networks (A with two routers, B with one), the hosting provider’s router and the example.com server. Labels name each network and its AS number.

    Key idea: The internet is independent networks (autonomous systems) joined by routers; each router only picks the next hop.

  2. 2. First, a name becomes an address

    You open https://example.com. Routers forward by IP address, not by name, so the laptop first asks a DNS resolver, usually the one the ISP handed out (the DNS lesson follows that lookup in detail).

    The question and the answer are packets too: laptop → home router → ISP → resolver, and back. About 35 ms later the laptop knows the address: 203.0.113.10. Not a single packet has gone towards the server yet.

    Scene: The laptop sends a DNS query through the home router and the ISP router to the ISP’s resolver, which answers with 203.0.113.10. Nothing is sent towards the server yet.

    Key idea: Before the first packet to a server, the client resolves its name to an IP address.

  3. 3. Every router picks the next hop

    Now the first packet leaves for 203.0.113.10. Watch it hop: the home router has one rule, “everything not local goes to the ISP”. The ISP router looks up the longest matching prefix in its table, 203.0.113.0/24, and forwards to Transit A. Transit A carries it across its backbone; the hosting router sees the address is on its own network and delivers it.

    Every router also lowers the packet’s TTL (hop limit) by one; a packet stuck in a loop dies when it reaches zero. Six hops, about 62 ms one way.

    Scene: One packet travels laptop → home router → ISP router → Transit A west → Transit A east → hosting router → server. Labels show each router’s forwarding decision and the TTL dropping from 64 to 59.

    Key idea: Routing is hop-by-hop: each router matches the destination against its table and forwards to one neighbour.

  4. 4. Data travels in independent packets

    A request or a web page rarely fits in one packet. The sender splits data into packets of up to about 1,500 bytes (the usual Ethernet MTU), each with its own header carrying source and destination addresses.

    Here three packets leave two milliseconds apart. Each is forwarded on its own, so several are on the wire at once, on different links. IP makes no promise that they arrive, or arrive in order; putting them back together, and asking for missing ones, is the job of TCP at the two ends (see the TCP and UDP lesson). Routers in between never reassemble anything.

    Scene: Three packets leave the laptop two milliseconds apart and follow the same six hops; at times several are in flight on different links. The server reassembles them.

    Key idea: IP moves independent packets on a best-effort basis; ordering and reliability are added at the endpoints.

  5. 5. Distance sets the floor on latency

    The server answers, and the response retraces the hops back to the laptop. The full round trip takes about 125 ms, and most of it is one link: 30 ms across Transit A’s backbone, roughly 6,000 km of fibre. Light in fibre covers about 200 km per millisecond, so no amount of server tuning removes that time.

    Every round trip pays it again: the DNS lookup, the TCP and TLS handshakes, each request. That is why CDNs put servers near users and why protocols work hard to save round trips.

    Scene: A request goes to the server and the response comes back the same way. The round trip takes about 125 ms; the long Transit A backbone link accounts for 60 ms of it.

    Key idea: Propagation delay (≈ 5 µs per km of fibre) puts a hard floor under every round trip.

  6. 6. Networks announce routes to each other

    How did the ISP know to send 203.0.113.0/24 to Transit A? The hosting network announced that prefix with BGP, the protocol networks use to tell each other which addresses they can reach. The announcement spread through both transits, so the ISP has two routes.

    BGP picks one by policy first (here the ISP gives Transit A a higher *local preference* because that contract is cheaper) and only then by attributes such as AS-path length. It is not “the fastest path”: BGP knows nothing about current latency or load.

    Scene: The hosting router announces its address block. The announcement reaches the ISP through Transit A and through Transit B; the ISP keeps both routes and prefers the one via Transit A.

    Key idea: BGP spreads reachability between networks and chooses routes by policy, not by measured speed.

  7. 7. A router fails, traffic reroutes

    Transit A’s east router fails. The next packet still goes to Transit A, whose west router has no working path any more and reports back that the destination is unreachable.

    BGP sessions over the dead router drop and Transit A withdraws the route. The ISP falls back to its backup, and the retry goes through Transit B. The page loads, a little slower on the longer path. In reality reconvergence takes from under a second to minutes; here the gap is compressed.

    Scene: Transit A’s east router is down. A packet reaches Transit A’s west router and an unreachable error comes back. After the route is withdrawn, the retry goes laptop → home → ISP → Transit B → hosting router → server, and the response returns the same way.

    Key idea: Redundant paths plus BGP withdrawals let the internet route around failures, after a convergence delay.

  8. 8. What happens between click and response

    A name is resolved to an address. Data is cut into packets. Each router along the way forwards each packet one hop closer, using tables that BGP keeps up to date between networks. The response comes back the same way, and the distance travelled sets a floor on every round trip.

    For system design that means: count round trips, put servers near users when latency matters, and remember that paths between networks can change under you.

    Scene: The full picture: laptop, home router, ISP router and resolver, two transit networks (Transit A east still down), the hosting router and the server.

    Key idea: Resolve, packetise, forward hop by hop; distance and round trips decide latency.