Use it when traffic follows an unexpected route, or a new route seems to be ignored.
Longest Prefix Match · RIB / FIB / CEF
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.
show ip route 10.1.2.3Verification & 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 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
- Checking AD before prefix length.
- Forgetting /32 local routes.
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.
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
| Route | Contains 10.20.30.77? | Length |
|---|---|---|
| 0.0.0.0/0 | Yes | 0 |
| 10.0.0.0/8 | Yes | 8 |
| 10.20.0.0/16 | Yes | 16 |
| 10.20.30.0/24 | Yes | 24 → chosen |
| 10.20.30.128/25 | No | — |
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)
| Entry | Memory |
|---|---|
| /32 host routes, local addresses, ARP entries | Exact-match hash |
| /31 and shorter | Longest-prefix-match memory (or TCAM on older ASICs) |
Consequences
| Situation | Effect |
|---|---|
| More specific route leaked from elsewhere | Traffic for that range follows it, even past firewalls |
| Summary plus a more specific route | The specific route wins for its range |
| Default route only | Used only when nothing else matches |
| Null0 summary route | Drops 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.
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
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 → 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%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.
Quick lookup tables
Route lookup decision order
Keep prefix selection, source preference and protocol metric separate
| Stage | Decision | Example |
|---|---|---|
| 1 | Longest matching prefix | /32 beats /24 beats /0 |
| 2 | Route-source preference for same prefix | lower Cisco AD wins between sources |
| 3 | Protocol-specific path choice | OSPF cost, EIGRP DUAL/metric, BGP best-path logic |
| 4 | Multipath/install constraints | equal/eligible paths may coexist |
| 5 | FIB/CEF programming | recursive next hop and adjacency become forwarding state |