Routing tables are the unsung heroes of the internet, quietly dictating the path every single packet takes from its origin to its destination.

Let’s see this in action. Imagine a router, the traffic cop of your network. It receives a packet destined for a server across the globe. The router doesn’t know where that server is inherently; it consults its routing table.

Destination Network | Next Hop | Interface | Metric
-------------------|----------|-----------|--------
192.168.1.0/24     | 192.168.0.1 | eth0      | 10
0.0.0.0/0          | 10.0.0.1  | eth1      | 100
172.16.0.0/16      | 192.168.0.2 | eth0      | 20

This table is a map. Each row represents a route. The Destination Network is a range of IP addresses. The Next Hop is the IP address of the next router the packet should be sent to. The Interface is the physical or virtual port on this router that leads to that next hop. The Metric is a cost associated with a route; lower is better.

When a packet arrives, the router looks for the most specific match in its routing table. If a packet’s destination IP is 192.168.1.50, it matches 192.168.1.0/24 (a /24 subnet mask means 255.255.255.0, covering 256 IPs). The router then forwards the packet to 192.168.0.1 via its eth0 interface.

If there’s no specific match, it falls back to the default route, often 0.0.0.0/0 (which means "anywhere"). In our example, 0.0.0.0/0 points to 10.0.0.1 via eth1, typically your connection to the internet service provider. This is how packets get to destinations outside of your local network.

The problem routing tables solve is how to efficiently and dynamically direct traffic across complex, interconnected networks like the internet. Without them, routers would have no way to know where to send packets beyond their immediate neighbors. They enable scalability by allowing routers to learn about distant networks from their peers, rather than needing a complete map of the entire internet.

The magic happens with routing protocols. Protocols like OSPF (Open Shortest Path First) or BGP (Border Gateway Protocol) are how routers build these tables. They exchange information about network reachability and preferred paths. OSPF is common within an organization to find the best path to internal servers, while BGP is used between large networks (like ISPs) to route traffic across the internet.

When you configure a static route, like ip route add 10.10.10.0/24 via 192.168.1.254 dev eth0, you’re manually adding an entry to the table. This tells the router: "To reach any IP in the 10.10.10.0/24 network, send the packet to 192.168.1.254 using the eth0 interface." This is useful for small, stable networks or specific overrides.

The metric value is crucial for choosing between multiple paths to the same destination. If a router learns two routes to 172.16.0.0/16, one with a metric of 20 and another with 30, it will prefer the route with the metric of 20. This allows administrators to influence traffic flow, preferring faster or more reliable links.

What most people don’t realize is that the "longest prefix match" is the fundamental rule for selecting a route. If a packet’s destination IP matches multiple entries in the routing table, the router doesn’t pick the one with the lowest metric or the first one it finds. It picks the entry whose destination network is the most specific match – meaning it has the longest common prefix with the destination IP address. For example, if a table has routes for 192.168.1.0/24 and 192.168.1.128/25, and the destination IP is 192.168.1.130, the /25 route will be chosen because it’s a more specific match.

The next concept to grapple with is how routing tables handle dynamic changes and network failures.

Want structured learning?

Take the full Computer Networking course →