Pcornel
Browse topics
Options
Recent
Favorites
Networking · Technical reference

Longest Prefix Match · RIB / FIB / CEF

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
Key commandshow ip route 10.1.2.3
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.

3 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 First 30 seconds Verify boundary

Immediate answer: List every matching route for the destination and identify the longest installed prefix before examining administrative distance or metrics.

Verification chain: destination address → matching prefixes → longest prefix → selected RIB entry → CEF entry → adjacency

Stop condition: Administrative distance and metric compare routes to the same prefix; they do not override a more-specific installed prefix.

Step 2 Commands Verify boundary
show ip route 10.1.2.3          ! longest match in the RIB
show ip cef 10.1.2.3 detail     ! entry used for forwarding
show ip cef exact-route 10.0.0.1 10.1.2.3
Step 3 Common mistakes Narrow the fault
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.
ReferenceWhat it is1 section · depth on demand

What it is

Longest-prefix match chooses the most-specific route whose prefix contains the destination. A /32 beats a matching /24, which beats a matching /16, regardless of administrative distance between those different prefix lengths.

ReferenceImportant terms & boundaries3 sections · depth on demand

Key points

  • Prefix length is compared before AD/metric across different matching prefixes
  • AD chooses between route sources for the same prefix
  • Protocol metric chooses among candidates within the relevant routing process/protocol logic
  • A default route is only used when no more-specific installed route matches.

In depth

Longest prefix match

When several routes contain a destination address, the router uses the most specific one. RFC 1812, in its CIDR section, states this requirement: routers must use the most specific matching route, the longest matching network prefix, when forwarding traffic.

Example lookup for 10.20.30.77

RouteContains 10.20.30.77?Length
0.0.0.0/0Yes0
10.0.0.0/8Yes8
10.20.0.0/16Yes16
10.20.30.0/24Yes24 → chosen
10.20.30.128/25No—

The routing source doesn't matter at this stage: a /24 from RIP beats a /16 from OSPF for this destination.

R1# show ip route 10.20.30.77
Routing entry for 10.20.30.0/24
  Known via "eigrp 100", distance 90, metric 3072, type internal
R1# show ip cef 10.20.30.77
10.20.30.0/24
  nexthop 10.0.14.2 GigabitEthernet0/0/3
R1# show ip cef 10.20.30.200
10.20.30.128/25
  nexthop 10.0.15.2 GigabitEthernet0/0/4

In hardware (Cisco Catalyst 9000 technote)

EntryMemory
/32 host routes, local addresses, ARP entriesExact-match hash
/31 and shorterLongest-prefix-match memory (or TCAM on older ASICs)

Consequences

SituationEffect
More specific route leaked from elsewhereTraffic for that range follows it, even past firewalls
Summary plus a more specific routeThe specific route wins for its range
Default route onlyUsed only when nothing else matches
Null0 summary routeDrops unmatched destinations within the summary

Using longest match in design

Traffic engineering often relies on it: advertise a summary from two sites and a more specific prefix from the preferred site, and traffic for that prefix follows the specific route.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Worked example

Longest prefix match is the fundamental rule of IP forwarding: of all the routes that contain a destination address, the router chooses the one with the longest prefix. Only when several routes have the same prefix length do administrative distance and metric decide. The worked example walks through three overlapping routes to show which one each destination uses.

Longest prefix match: the router selects the route with the most specific prefix that contains the destination address; AD and metric only matter between routes with the same prefix length.

Worked example: routes 10.0.0.0/8 (OSPF), 10.20.0.0/16 (static), 10.20.30.0/24 (EIGRP). Destination 10.20.30.40 → /24 via EIGRP; 10.20.99.1 → /16 static; 10.99.0.1 → /8 OSPF. Hardware forwarding uses the FIB (CEF) built from the RIB with the same rule.

show ip cef 10.20.30.40
show ip cef exact-route 10.0.0.5 10.20.30.40     ! which ECMP path a flow uses
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 → RIB / FIB / CEF → 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%
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
LPMmost specific routelongest prefix
Embedded reference data

Quick lookup tables

Route lookup decision order

Keep prefix selection, source preference and protocol metric separate

StageDecisionExample
1Longest matching prefix/32 beats /24 beats /0
2Route-source preference for same prefixlower Cisco AD wins between sources
3Protocol-specific path choiceOSPF cost, EIGRP DUAL/metric, BGP best-path logic
4Multipath/install constraintsequal/eligible paths may coexist
5FIB/CEF programmingrecursive next hop and adjacency become forwarding state
Confirmation

Confirm action

Continue?