Routing: Getting Packets Across Networks

When you click a link, the packets of your request rarely reach the far-off web server in a single leap. They travel across a vast web of separate networks — your home network, your provider's network, national backbones, the server's data centre — and the machines that stitch all those networks together are called routers. A router's whole job is to take a packet that has arrived from one network and forward it onward, one hop closer to its destination on another network.

The surprising part is how little any single router knows. No router holds a map of the entire internet, and none plans the whole journey. Each one simply reads the packet's destination IP address, looks it up in its own routing table, picks the best next hop, and passes the packet along. The full path emerges from a long chain of these small, local decisions — a bit like a parcel that is handed from one sorting office to the next, each office knowing only "which road sends this postcode roughly the right way".

One packet, many hops

Step through the diagram below. A packet leaves your computer and crosses a mesh of routers to reach the destination server. Watch how at each router the packet takes just one more hop — the router doesn't send it all the way, it only chooses where to send it next.

Every dark line is a physical link between two routers. The highlighted path is the journey this one packet actually took. Notice that plenty of other routes existed — the routers cooperated, each choosing a sensible next hop, to build an efficient path overall.

The routing table: a router's decision sheet

How does a router decide where to send a packet next? It keeps a routing table: a lookup of which neighbouring link to use for which destinations. When a packet arrives, the router reads its destination IP, finds the matching row, and sends the packet out of the link named in that row. That link leads to the next hop — the very next router (or the final device) on the way.

A real table lists networks (ranges of addresses), not single devices, so one row can cover millions of destinations. Each row typically records three things:

Metrics: choosing the efficient route

Usually there is more than one way to reach a destination, so a router needs a way to compare them and choose. That comparison is done with a metric — a number that measures how "expensive" a route is. The router prefers the route with the lowest metric.

The two metrics you should know for A-level are:

Finding the route with the smallest total cost is exactly a shortest-path problem — the same kind of "least-total-weight route through a network of connected points" that graph algorithms solve. Real routing protocols run algorithms of this family behind the scenes to keep every router's table pointing along efficient paths.

In the figure above, the route with the fewest hops is not the cheapest route. Counting routers, the top path is shorter; but add up the link costs and the longer-looking bottom path wins. Which one a router chooses depends entirely on the metric it has been told to use.

Routes that heal themselves

Because routers make local next-hop decisions from a table — rather than following one fixed, pre-planned path — a packet-switched network can adapt when something breaks. Routers constantly share reachability information with their neighbours, so if a link goes down or a router fails, the news spreads and each affected router updates its table. The broken route is removed and traffic is steered along the next-best path instead.

Step through it: the packet is happily using the direct route, that link is cut, and the routers recompute — the very next packet is sent a different way and still arrives. There was never a single fixed path to lose, which is exactly why the internet is so hard to knock over.

Two different jobs: routing vs switching

It is easy to blur routers together with the switches inside a local network, but they do genuinely different jobs, at different scales, using different addresses.

Two exam traps live on this page — keep both straight.

1. No single router knows the whole path. It is tempting to imagine one clever machine plotting the entire route from you to the server. Nothing does that! Each router knows only its own routing table and picks the best next hop from it — the complete journey is built from many independent, local decisions. A router cannot tell you the full path a packet will take; it only knows where to send it next.

2. Routing is not switching. Routing happens between networks and uses IP addresses; switching happens within one LAN and uses MAC addresses. Same idea of "forwarding data", completely different scale and address type — don't swap the terms.

If every router only makes a local decision, what stops a packet bouncing between two routers endlessly when their tables briefly disagree? Every IP packet carries a small counter in its header — the Time To Live (TTL) — that is reduced by one at every hop. If it reaches zero, the packet is discarded rather than circulating forever, and the sender can try again once the tables have settled. It is a simple safety valve that stops temporary routing muddles from clogging the network.