← All lessons
Routing and network security · Lesson 1 of 7

Routing tables

A routing table is a list of networks and where to send packets for each one. Every router has one, and so does your computer. Each row has a destination network (a prefix like 10.1.0.0/16), a next hop (the router to hand the packet to) or an interface to send it out of, and a cost.

Destination      Next hop      Interface
10.1.0.0/16      10.0.0.2      eth1
10.1.5.0/24      10.0.0.3      eth1
192.168.1.0/24   (direct)      eth0
0.0.0.0/0        203.0.113.1   eth2

When a packet arrives, the router finds every row whose prefix contains the destination address, then picks the most specific one: the longest prefix match. A packet for 10.1.5.9 matches both 10.1.0.0/16 and 10.1.5.0/24, so it goes to 10.0.0.3, because /24 is more specific than /16. A packet for 10.1.9.9 only matches the /16, so it goes to 10.0.0.2.

0.0.0.0/0 matches every address, with a prefix length of zero, so it only wins when nothing else does. It's the default route: "if you don't know, send it this way". Your computer's default route points at its default gateway; a home router's default route points at the internet provider.

Networks a router is plugged into directly are added for it. Others are added either by hand (static routes) or learned from other routers using a routing protocol, which is the next lesson. If no row matches at all and there's no default route, the packet is dropped and an error goes back to the sender.

Practice

Using the table above, which next hop gets a packet for 10.1.5.20?

More info

Quick reference

Routing tableDestination prefix → next hop or interface.
Longest prefix matchThe most specific matching route wins.
0.0.0.0/0Default route: matches everything, used last.
Next hopThe router to hand the packet to.
Static routeSet by hand.

The other networking courses