Route selection and forwarding
How a router installs routes (administrative distance, metric) versus how it forwards packets (longest-prefix match, then next hop).
Longest-prefix match
The three rules in order
- Forwarding decision (packet in hand): longest-prefix match wins — always, regardless of route source.
- Installation decision (two sources offer the SAME prefix): lowest administrative distance wins the RIB.
- Within one protocol (same prefix, same protocol): lowest metric wins.
Longest-prefix match is the forwarding rule: for a destination, the router picks the most specific route that contains it. A /24 always beats a /16 and a default /0 never wins while anything more specific exists. Route source and AD are irrelevant at this step — the table only contains winning candidates.
- Table
- S 10.0.0.0/8 [1/0], O 10.1.0.0/16 [110/20], C 10.1.5.0/24 (Gi0/1)
- Packet
- to 10.1.5.9
- Candidates: /8 (S), /16 (O), /24 (C) — all match 10.1.5.9.
- Longest prefix wins → /24 connected route forwards directly out Gi0/1.
- The static and OSPF routes never see this packet despite their sources.
AD never entered the picture — the connected /24 is simply the most specific match.
AD and metric
Administrative distance selects between *candidate* routes for the *same* prefix: connected (0) beats static (1) beats OSPF (110). The loser never enters the table — it exists only as a protocol backup. AD never compares a /24 to a /16.
Metric breaks ties inside one routing protocol for the same prefix — OSPF uses interface bandwidth-derived cost, EIGRP a composite, RIP hop count. Metrics across protocols are incomparable.
- Candidates
- OSPF 10.2.0.0/24 [110/20], static 10.2.0.0/24 [120/0]
- Same prefix → AD decides: 110 < 120 → OSPF installs.
- The static (deliberately at 120) sits ready — it installs only when OSPF's route disappears.
- This is the floating static pattern: backup by inflated AD.
AD 120 lost to 110 for the identical /24 — by design.
Applied scenarios
Which rule applies when
| Situation | Decided by |
|---|---|
| /24 via OSPF vs /16 via static — packet to a host in the /24 | Longest prefix → the /24 wins |
| 10.0.0.0/24 learned via OSPF and via static | AD → static (1) beats OSPF (110) |
| 10.0.0.0/24 learned twice inside OSPF | Metric → lower cost path wins |
| Only a default route exists | Longest prefix → 0.0.0.0/0 matches |
| Two static routes for the same prefix, different next hops | Same AD → both install; ECMP load-balances |
Verifying the decision
show ip route <address>shows the actual match the router will use — the single best debug.- If the match is a more-specific route than you expected, the table is working correctly — your expectation wasn't.
show ip ospf rib/ protocol-specific views show the losing candidates that never installed.
Common mistakes
- Believing lower AD beats a more-specific route — specificity always wins for forwarding.
- Comparing metrics between OSPF and EIGRP — meaningless cross-protocol.
- Expecting a default route to win when anything more specific exists — /0 is the last resort only.
- Thinking ECMP means two ADs — ECMP requires same source, same prefix, same metric.
Observation: Packets to 10.1.5.9 exit via the WAN router instead of the directly-connected LAN.
- A more-specific route on the WAN path
- The connected interface isn't actually connected/up
- Asymmetric return path confusion
| Check | Indicates |
|---|---|
show ip route 10.1.5.9 | Names the actual route and next hop used — ends the guessing. |
| Interface status of the 'expected' path | A down interface removes its connected route silently. |
Correction: Remove the stray more-specific route or restore the connected path.
show ip route selects the intended route and traffic follows it.
Related resources
Sources
- Cisco CCNA 200-301 v1.1 Exam Topics (official PDF) — reviewed 2026-11-02
Targets CCNA 200-301 v1.1 objectives. Supplemental blocks are labeled beyond exam scope.