Pcornel
Browse topics
Options
Recent
Favorites
Networking · Technical reference

Longest Prefix Match · Forwarding Decision

Direct 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.

When to use this

Use it when traffic follows an unexpected route, or a new route seems to be ignored.

First 30 seconds

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.

Operational verification

destination address → all routes that contain it → the longest prefix selected → its next hop resolved → CEF entry matches

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Cisco IOS / IOS XE
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformCisco IOS / IOS XE · Cisco IOS XE · IOS/IOS XE
Scope / prerequisiteUse it when traffic follows an unexpected route, or a new route seems to be ignored.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Command lookup Jump straight to Cisco syntax
Key points

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.

Key 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.
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

RoutePrefix bitsMatches?Length
0.0.0.0/0—yes0
10.0.0.0/800001010yes8
10.1.0.0/1600001010.00000001yes16
10.1.2.0/2300001010.00000001.0000001yes23
10.1.2.0/25...00000010.0yes (3 < 128)25 ← wins
10.1.2.128/25...00000010.1no—

Commands that show the decision

CommandPurpose
show ip route 10.1.2.3Shows the single entry selected for that address
show ip cef 10.1.2.3Same decision in the FIB, with the resolved adjacency
show ip route 10.1.0.0 255.255.0.0 longer-prefixesAll more-specific routes under a block
show ip route supernets-onlySummaries 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.
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docCisco IOS / IOS XE Current documentation reviewed 2026-09-14

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%
Confirmation

Confirm action

Continue?