Lesson 5 — Longest-Prefix Match, AD, and Metrics
Week 4 outline
- Week 4 overview
- Lesson 1Routing Fundamentals and the Forwarding Decision
- Lesson 2Connected and Local Routes
- QuizRouting Table Foundations
- Lesson 3IPv4 Static Routes: Next-Hop and Exit-Interface
- Lesson 4Default Routes and Floating Static Routes
- QuizStatic Routing & Failover
- LabStatic Routing Lab
- Lesson 5Longest-Prefix Match, AD, and Metrics (current step)
- CheckpointWeek 4 Checkpoint
Longest-Prefix Match, AD, and Metrics
Apply the router's real selection order — longest-prefix match, then administrative distance, then metric — to predict exactly which route forwards a packet.
Lesson orientation
What you'll learn (4 objectives)~32 min: video → lesson → check → apply → lab prep
Learning objectives
- State the three-step order a router uses to choose a route
- Use longest-prefix match to pick the most specific matching prefix regardless of source or AD
- Use administrative distance to choose between two sources offering the same prefix, from the standard values
- Explain that metric only breaks ties within a single protocol, and diagnose an unexpected path caused by AD or LPM
Terms you will see
Time breakdown
- Read the notes16 min
- Routing Table Trainer — hard mode10 min
- Decision walkthrough6 min
Assigned video

Dynamic Routing, AD & Floating Static (Day 24)
By Jeremy's IT Lab · Opens externally on YouTube
- Assigned watch
- ~6 min
The link opens in a new browser tab. Return here when you finish watching.
Watch for these concepts
- How AD ranks different route sources
- Longest-prefix match being applied before AD is even considered
Go beyond the video
The assigned video introduces the idea. CCNA Practice Labs completes the learning path: clarify core concepts, explore how each device behaves, visualize the communication path, check your understanding, and prepare for hands-on lab work.
Watch the concept → understand it → visualize it → practice it → apply it.
Three tests, in a fixed order
When several routes could carry a packet, the router applies three tests in order and stops at the first one that decides. Get the order right and every route-selection question becomes mechanical.
- Longest-prefix match — of all routes whose prefix contains the destination, the one with the most specific (longest) prefix wins. Decided first, and decided on the destination address alone.
- Administrative distance — 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.
There is a reason this order makes sense rather than being arbitrary. A more specific route reflects more precise knowledge about a destination: 10.1.1.0/24 says I know specifically about this /24, while 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 that idea — the least specific route, used only when nothing else matches.
Longest-prefix match, worked
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| Destination | Winner | Why |
|---|---|---|
| 10.1.1.50 | C 10.1.1.0/26 | The /26 covers .0 through .63, so .50 is inside it. It is the most specific match, so it wins outright — the OSPF /16 and static /24 also match but are less specific. |
| 10.1.1.200 | S 10.1.1.0/24 | Outside the /26's range of .0–.63, so the /26 no longer matches at all. The next most specific is the static /24. |
| 10.2.5.5 | S* 0.0.0.0/0 | None of the 10.1 prefixes match — the OSPF /16 covers 10.1.0.0 through 10.1.255.255, and 10.2 is outside it. Only the default remains. |
Note that none of those three decisions consulted AD or metric. Prefix length settled all of them, which is what makes the first test so much more important than its position in a list suggests.
Administrative distance ranks sources, not paths
Two protocols can both learn a route to the exact same prefix — say OSPF and a static route both describe 10.1.5.0/24. Longest-prefix match cannot break that tie, since the prefix lengths are identical, so the router asks which source it trusts more. Lower AD wins.
| 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 beats OSPF, which beats RIP. A connected route 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 at all, it encodes how much the administrator trusts each source of information. That is exactly the mechanism a floating static route exploited in the previous lesson — raising a static route's AD above the primary's so it loses the comparison until the primary disappears.
Metric is the within-protocol tiebreaker
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. Each protocol computes its metric differently: OSPF uses a cost derived from bandwidth, EIGRP a composite of bandwidth and delay, RIP a hop count.
When a healthy protocol is quietly ignored
What you should retain
- Fixed order: longest-prefix match, then administrative distance, then 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/0 is the least specific route and therefore the last resort.
- AD applies only to the same prefix from different sources: connected 0, static 1, EIGRP 90, OSPF 110, RIP 120, external EIGRP 170.
- Metric applies only within one protocol; comparing an OSPF cost to an EIGRP metric is meaningless.
- show ip route <destination> reveals the single entry that survived all three tests.
Before you read on
Given: S* 0.0.0.0/0 [1/0]; O 10.1.0.0/16 [110/20]; S 10.1.5.0/24 [1/0]; O 10.1.5.0/24 [110/30]; D 172.16.0.0/16 [90/2816]. Name the winner and the deciding test for each destination. (1) 10.1.5.40 (2) 10.1.9.20 (3) 172.16.4.4 and 8.8.8.8.
See it happen
Routing Table Trainer — hard mode
For each destination apply LPM, then AD, then metric, and check your winner against the tool. Hard mode deliberately includes overlapping prefixes from different sources, which is where the order stops being obvious and starts being a skill.
Study deeper
Topic guides extend this lesson — they do not replace the first-party walkthrough above.
Routing Protocols
For the full AD table and the LPM-versus-AD distinction, which returns as soon as OSPF arrives in Week 5
