Use it when traffic follows an unexpected route, or a new route seems to be ignored.
Longest Prefix Match · Forwarding Decision
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.
1. show ip route <dst> — which prefix matched, from which source?
2. More specific than expected → longer-prefixes on the expected block: who injects it?
3. Less specific than expected (summary or default) → the specific route is missing.
4. show ip cef <dst> — does forwarding agree?
5. Fix the source of the unwanted or missing route, not the metric.
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Thinking the route with the lowest AD always wins — a longer prefix wins first.
- Forgetting that a /32 host route overrides everything for that address.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
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.
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.
ReferenceHow it works1 section · depth on demand
How it works
When several routes match a destination, the router uses the one with the longest prefix (most specific mask) — before administrative distance or metric are considered. Example: for 10.1.2.3, a /24 route beats a /16 and the default route, even if the /16 has a lower AD. AD and metric only choose between routes for the same prefix.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
The selection order
1. Longest prefix match across all usable routes (RFC 1812 next-hop selection).
2. Only for the same prefix and length learned from several sources: lowest administrative distance decides which one enters the RIB.
3. Within one protocol: lowest metric, then equal-cost load sharing.
AD and metric never compare routes of different lengths.
Worked binary example
Destination 10.1.2.3 = 00001010.00000001.00000010.00000011
| Route | Prefix bits | Matches? | Length |
|---|---|---|---|
| 0.0.0.0/0 | — | yes | 0 |
| 10.0.0.0/8 | 00001010 | yes | 8 |
| 10.1.0.0/16 | 00001010.00000001 | yes | 16 |
| 10.1.2.0/23 | 00001010.00000001.0000001 | yes | 23 |
| 10.1.2.0/25 | ...00000010.0 | yes (3 < 128) | 25 ← wins |
| 10.1.2.128/25 | ...00000010.1 | no | — |
Commands that show the decision
| Command | Purpose |
|---|---|
show ip route 10.1.2.3 | Shows the single entry selected for that address |
show ip cef 10.1.2.3 | Same decision in the FIB, with the resolved adjacency |
show ip route 10.1.0.0 255.255.0.0 longer-prefixes | All more-specific routes under a block |
show ip route supernets-only | Summaries and default routes |
Practical consequences
- A more specific route from any source beats a summary from a "better" protocol — a stray /32 static overrides an OSPF /24.
- A summary pointing to Null0 only catches traffic for which no longer match exists, which is exactly its purpose.
- Prefix hijacks and traffic-engineering with more specifics both work because of this rule.
Example
| Route | Matches 10.1.2.3? | Length |
|---|---|---|
| 0.0.0.0/0 | Yes | 0 |
| 10.0.0.0/8 | Yes | 8 |
| 10.1.0.0/16 | Yes | 16 |
| 10.1.2.0/24 | Yes | 24 ← used |
Check: show ip route 10.1.2.3, show ip cef 10.1.2.3.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Routing → Forwarding Decision → Longest Prefix Match. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.cisco.com/c/en/us/support/ios-nx-os-software/ios-xe-17/series.html · confidence 94%