Apply the router's real selection order — longest-prefix match, then administrative distance, then metric — to predict exactly which route forwards a packet.
Week 4 · Lesson 5 · Active ~32 min · Optional video ~6 min · Practice ~12 min · Domain: IP Connectivity
You should be able to read S, C, and O routes with their [AD/metric] brackets, and know that static routes are AD 1 and the default route is the least specific match.
Prerequisites: static-routes-ipv4, default-and-floating-static-routes
Baseline check
A router's table has two entries that both match the destination 10.1.1.50: O 10.1.0.0/16 [110/20] learned by OSPF, and S 10.1.1.0/24 [1/0] a static route. Before reading on: which one forwards the packet — the OSPF route with the lower cost, the static route with the lower AD, or the more specific prefix?
Commit to an answer. Whether you reached for AD, metric, or prefix length tells you which of the three rules you are about to nail down.
When several routes could carry a packet, the router applies three tests in a fixed order and stops at the first that decides. Get the order right and every route-selection question becomes mechanical:
- Longest-prefix match (LPM) — of all routes whose prefix contains the destination, the one with the most specific (longest) prefix wins. This is decided first, before anything else, and it is decided on the destination address alone.
- Administrative distance (AD) — only if two or more routes match at the same longest prefix length but come from different sources, the source with the lower AD is installed.
- Metric — only if the tie is still unresolved because two routes to the same prefix come from the same protocol, the lower metric wins.
The order matters because the tests are not equal citizens. LPM is not "one factor among several" — it is the gate everything else passes through. A more specific prefix wins even if it has a worse AD and a worse metric, because AD and metric are never consulted for prefixes of different lengths. That is the answer to the baseline: S 10.1.1.0/24 wins for 10.1.1.50, not because AD 1 beats AD 110, but because /24 is more specific than /16. The router matches the longest prefix and never gets to the AD comparison at all.
Why longest-prefix match makes sense. A more specific route reflects more precise knowledge about a destination. 10.1.1.0/24 says "I know specifically about this /24"; 10.1.0.0/16 says "I know about this larger block generally." Following the more specific route sends the packet toward the router with the finer-grained information — which is almost always the more correct path. The default route 0.0.0.0/0 is the logical endpoint of this idea: the least specific route, used only when nothing more specific matches at all.
Read a table where prefixes overlap
R2# show ip route
Codes: C - connected, L - local, S - static, O - OSPF
* - candidate default
Gateway of last resort is 203.0.113.1 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 203.0.113.1
10.0.0.0/8 is variably subnetted, 6 subnets, 4 masks
O 10.1.0.0/16 [110/20] via 10.9.9.1, 00:12:04, GigabitEthernet0/2
S 10.1.1.0/24 [1/0] via 10.9.9.5
C 10.1.1.0/26 is directly connected, GigabitEthernet0/0
L 10.1.1.1/32 is directly connected, GigabitEthernet0/0
Three routes overlap the destination 10.1.1.50: the OSPF /16, the static /24, and the connected /26. Apply LPM: /26 (0–63) is the most specific prefix that contains .50, so C 10.1.1.0/26 wins — even though OSPF and static also match, and even though the connected route was never "chosen" by AD here. For a destination like 10.1.1.200 (outside the /26 range 0–63), the /26 no longer matches; the next-most-specific is the S 10.1.1.0/24, so the static route wins. And for 10.2.5.5, none of the specific 10.1.x prefixes match, so the packet falls to the OSPF /16 if it is covered (it is not — 10.2 ≠ 10.1), then finally to the default. Same table, different destinations, different winners — all decided by prefix length first.
Administrative distance ranks route sources; it is consulted only for the same prefix. Two protocols can both learn a route to the exact same prefix — say both OSPF and a static route describe 10.1.5.0/24. LPM cannot break that tie (identical prefix length), so the router asks: which source do I trust more? Lower AD wins. The values you must know:
| Route source | Default AD |
|---|---|
| Connected interface | 0 |
| Static route | 1 |
| EIGRP (internal) | 90 |
| OSPF | 110 |
| RIP | 120 |
| EIGRP (external) | 170 |
| Unreachable (route never used) | 255 |
So for the same prefix, a static route (AD 1) beats OSPF (AD 110), which beats RIP (AD 120). A connected route (AD 0) beats everything — which is why you never write a static route for a directly attached subnet. AD is a belief setting: it does not measure the path, it encodes how much the administrator trusts each source of information. This is precisely the mechanism a floating static route exploited last lesson — raising a static route's AD above the primary's so it loses the AD comparison until the primary disappears.
Metric is the within-protocol tiebreaker, and it never crosses protocol lines. If the surviving candidates are two routes to the same prefix from the same protocol — two OSPF paths, for instance — the router compares their metric and installs the lower one (OSPF adds the cost along each path; lower total cost is better). Each protocol computes metric its own way: OSPF uses cost derived from bandwidth, EIGRP a composite of bandwidth and delay, RIP a hop count. Because the units are incompatible, a router never compares an OSPF cost of 20 against an EIGRP metric of 3072 — that comparison is meaningless, and it is exactly why AD exists to arbitrate between protocols before metric is ever considered.
Put the three together: why can't a lower metric ever rescue a route that lost on AD or LPM?
Because the tests run in order and each is only reached if the previous one tied. If a competing route has a longer prefix, LPM ends the contest immediately — AD and metric are never examined, so no metric could help. If prefixes tie but a competitor has a lower AD, the AD test ends it — again metric is never examined. Metric is only reached when prefix length and source (protocol) are identical. A brilliant metric on an OSPF route is irrelevant if a static route covers the same prefix, because the static route wins on AD long before OSPF's metric is looked at. The order is a filter, not a weighted score.
Free CCNA | Dynamic Routing | Day 24 | CCNA 200-301 Complete Course
~6 min
Confirm how AD ranks different route sources and how longest-prefix match is applied before AD is even considered.
Optional. Skip if the written selection order and the decision walkthrough already let you predict the winning route confidently.
Watch on YouTubeEnrichment only — the decision walkthrough below is the primary practice.
Use this table. For each destination, apply the order and name the winning line before revealing.
S* 0.0.0.0/0 [1/0] via 203.0.113.1
O 10.1.0.0/16 [110/20] via 10.9.9.1
S 10.1.5.0/24 [1/0] via 10.9.9.5
O 10.1.5.0/24 [110/30] via 10.9.9.1
D 172.16.0.0/16 [90/2816] via 10.9.9.9
Pause and predict
- Destination 10.1.5.40 — which line wins, and by which test (LPM, AD, or metric)?
- Destination 10.1.9.20 — which line wins, and why?
- Destination 172.16.4.4 versus destination 8.8.8.8 — which line does each use?
Reveal answer
S 10.1.5.0/24 [1/0] via 10.9.9.5wins by AD. Two routes tie at the longest prefix /24 — the static and the OSPF route, both for 10.1.5.0/24. LPM cannot separate them, so AD decides: static AD 1 beats OSPF AD 110. (The OSPF /16 also matches but is less specific, so it was eliminated by LPM first.) Metric is never consulted.O 10.1.0.0/16 [110/20]wins by LPM. 10.1.9.20 is inside 10.1.0.0/16 but not inside 10.1.5.0/24, so only the /16 (among the 10.1 routes) matches. It beats the default purely on being more specific — AD is irrelevant because no other route matches this destination at a longer prefix.- 172.16.4.4 →
D 172.16.0.0/16 [90/2816](EIGRP), the only specific match. 8.8.8.8 →S* 0.0.0.0/0, the default, because nothing more specific matches it. Neither decision needed AD or metric — LPM alone settled both.
OSPF is up but traffic ignores it
Symptom. R2 runs OSPF and learns 10.1.5.0/24 from a neighbor, and you expect traffic to 10.1.5.20 to follow the OSPF path out Gi0/2. Instead it leaves via 10.9.9.5, an old link. OSPF adjacency is full and the OSPF route is being advertised, yet the traffic takes the "wrong" path.
Isolate. Ask the router which entry it actually installed for that destination:
R2# show ip route 10.1.5.20
Routing entry for 10.1.5.0/24
Known via "static", distance 1, metric 0
Routing Descriptor Blocks:
* 10.9.9.5
The installed route is static, not OSPF. Both sources offer the identical prefix 10.1.5.0/24, so LPM ties — and AD decides. The static route's AD 1 beats OSPF's AD 110, so IOS installs the static route and the OSPF route sits unused in the OSPF database, never reaching the RIB. This is not a bug; it is the selection order working exactly as designed. A leftover ip route 10.1.5.0 255.255.255.0 10.9.9.5 is silently shadowing the dynamic route.
Fix. Decide which path you truly want. If OSPF should own this prefix, remove the stale static:
R2(config)# no ip route 10.1.5.0 255.255.255.0 10.9.9.5
With the static gone, the OSPF route (AD 110) is now the best remaining source for 10.1.5.0/24, so it installs and traffic follows the OSPF path. (If you deliberately want the static as a backup to OSPF instead, give it an AD above 110 — a floating static — so OSPF wins while it is healthy.) Root-cause lesson: when a dynamic route "isn't being used," check for a lower-AD static covering the same prefix before suspecting the protocol.
Drill the full order against fresh tables in the Routing Table Trainer, then prove fluency on the Week 5 Part 1 Gate, which scores route selection at exam pace.
Run hard mode: for each destination, apply LPM, then AD, then metric, and check your winner against the tool.
Open routing-tableQuick check (3 items) · retrieve
Answer from memory:
- State the three route-selection tests in the order the router applies them.
- A /24 static route (AD 1) and a /16 OSPF route (AD 110) both cover a destination in the /24. Which wins, and which test decided it?
- Two OSPF routes and one static route all describe the same /24 prefix. In what order are the three narrowed to a single installed route?
Review sheet
- Fixed order: longest-prefix match → administrative distance → metric; stop at the first test that decides.
- LPM first: the most specific matching prefix wins regardless of AD or metric; the default
0.0.0.0/0is the least specific fallback. - AD for same prefix, different source: connected 0, static 1, EIGRP 90, OSPF 110, RIP 120, external EIGRP 170.
- Metric within one protocol only: never compare an OSPF cost to an EIGRP metric — that is what AD is for.
show ip route <destination>reveals the single entry that survived all three tests.
You can now predict the winning route; Week 5 turns that into fluent reading of every field and code in the live table, then feeds the Part 1 routing gate.
Next week: Reading show ip route