Route lookup
Build a routing table, pick a destination, and see which route wins by longest prefix match.
The address in the packet's destination field.
5 routes match; /26 is the longest, so traffic goes via R4.
Routing table
Edit any row. Order does not matter.
- Match10.1.2.70 AND /0 → 0.0.0.0 = 0.0.0.0
- Match10.1.2.70 AND /8 → 10.0.0.0 = 10.0.0.0
- Match10.1.2.70 AND /16 → 10.1.0.0 = 10.1.0.0
- Match10.1.2.70 AND /24 → 10.1.2.0 = 10.1.2.0
- Winner10.1.2.70 AND /26 → 10.1.2.64 = 10.1.2.64
How a router picks a route
For every packet the router compares the destination address with each route. A route matches when the destination, ANDed with the route's mask, equals the route's network. That is the line under each row.
Several routes can match at once, because big blocks contain smaller ones. The router uses longest prefix match: the matching route with the most network bits (the highest /number) is the most specific, so it wins. A /26 beats a /24, which beats a /16.
The default route 0.0.0.0/0 has zero network bits, so it matches everything and always loses to any other match. With no default route and no match, the packet is dropped.