Longest Prefix Match
Cheat sheet · https://pcornel.dk/topic.php?topic=1070
Answer
When several routes match a destination, the router uses the one with the longest prefix — the most specific. A /32 beats a /24, which beats a default route /0. Administrative distance and metric only decide between routes for the same prefix.
Remember
Specificity first, then administrative distance, then metric. A more specific route from any source wins over a less specific one from a "better" protocol. Summary and default routes catch only what nothing more specific matches.
First checks
show ip route <dst>— the route actually chosen for that address.show ip route <prefix> <mask> longer-prefixes— every more specific route under a block.show ip cef <dst>— the forwarding entry used.show ipv6 route <dst>— the same for IPv6.
Commands
show ip route 10.1.2.3show ip cef 10.1.2.3show ip route 10.1.0.0 255.255.0.0 longer-prefixesshow ip route supernets-only
Verify in this order
destination address → all routes that contain it → the longest prefix selected → its next hop resolved → CEF entry matches
Where it usually breaks
underlay/interface reachability → protocol adjacency/session → received/originated state → policy → best path/RIB → FIB/adjacency → traffic path
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=1070