You’re looking at your router’s configuration, trying to figure out why traffic is going a certain way. You’ve configured static routes, OSPF is running, maybe even EIGRP is chiming in. Suddenly, you’re asking yourself:
“Wait… the route is there, but it’s not being used. Is it because of administrative distance? Or is it about the prefix length?”
If that’s the question in your head, you’re on the right path.
Routing decisions don’t just depend on who the route came from — they depend on how specific the route is too.
So today, let’s clear up this classic confusion:
What takes priority — Longest Prefix Match or Administrative Distance?
Quick Definitions (Just to Be Clear)
Longest Prefix Match (LPM)
When a router has multiple routes to the same destination, it chooses the one with the most specific subnet mask — i.e., the longest prefix.
For example:
- 192.168.1.0/24 is more specific than 192.168.0.0/16
- /27 is more specific than /24
LPM is about which route fits the destination best.
Administrative Distance (AD)
AD is used to rank trustworthiness between different routing sources (connected, static, OSPF, BGP, etc.).
Lower AD = more trusted.
Source | AD |
Connected | 0 |
Static | 1 |
EIGRP | 90 |
OSPF | 110 |
RIP | 120 |
Unknown | 255 (never used) |
AD only matters if multiple routes to the exact same prefix are present.
So What Wins — LPM or AD?
So What Wins — LPM or AD?
Here’s the golden rule of routing decisions:
Routers choose the route with the longest prefix match FIRST.
Then, if multiple routes match equally, it chooses the one with the lowest administrative distance.
Let’s say that again for clarity:
- LPM comes before AD.
AD only decides the winner when prefix lengths are equal.
Real Example 1 – Longest Prefix Match Wins
You’ve configured these routes:
ip route 10.0.0.0 255.0.0.0 192.168.1.1 1 ← Static route (AD = 1)
ip route 10.1.1.0 255.255.255.0 10.10.10.1 100 ← Static route with higher AD (manually set)
Now traffic is headed for 10.1.1.5.
Let’s ask:
-
- Does both routes match the destination?
- YES. But 10.1.1.0/24 is more specific than 10.0.0.0/8.
Result: Even though the second route has a higher AD (100), it wins because it is more specific.
Real Example 2 – AD Only Matters When Prefixes Are Equal
You’ve got:
OSPF learns: 10.2.2.0/24 via 192.168.1.1 (AD = 110)
Static route: 10.2.2.0/24 via 10.10.10.1 (AD = 1)
Both are /24 — same prefix length.
Now what?
Router will pick the one with lower AD — in this case, static (AD = 1).
Even if OSPF learned that route dynamically and it seems active, it won’t be used unless the static one fails.
Real Example 3 – When People Get Confused
Let’s say you’re routing to 172.16.1.55.
Your routing table shows:
C 172.16.0.0/16 is directly connected, FastEthernet0/1
S 172.16.1.0/24 [254/0] via 192.168.1.1
Which one wins?
172.16.1.0/24 matches more specifically
Even though its AD is 254 (very high) — it still wins because prefix match takes priority
That can be scary in the real world, because now you’re forwarding traffic via an unreliable static route — just because it’s more specific.
Lesson: Don’t create overly specific static routes with high ADs unless you’re tracking them carefully.
Rule Recap – LPM vs AD
Let’s visualize the router’s decision-making:
- Find all routes that match the destination IP
- Pick the one with the LONGEST PREFIX (most specific mask)
- If multiple with same prefix → choose the one with the LOWEST AD
If multiple with same prefix and same AD → check metric (like hop count, bandwidth)
Commands to Troubleshoot
View the routing table:
show ip route
Verify administrative distance:
show ip route <destination>
Look for brackets like [110/2]:
- First number = AD
- Second = metric
Use traceroute to verify path:
traceroute <IP>
Common Mistakes
Mistake | Reality Check |
“Static routes always win” | Only if same prefix length or more specific |
“AD decides everything” | No — LPM comes first |
“My OSPF route disappeared!” | Maybe a more specific static route took over |
“I removed a static, but nothing changed” | Another static with same prefix may exist |
“Higher AD means backup route won’t work” | It still can — if it has longer prefix |
Quick Summary: Who Wins?
Situation | Winner |
Static route (/24) vs OSPF route (/16) | Static — LPM wins |
Static route (/24) vs OSPF route (/24) | Static — AD wins |
OSPF route (/24) vs EIGRP route (/24) | EIGRP — lower AD wins |
Default route (0.0.0.0/0) vs /16 | /16 — more specific |
Final Thoughts — Think Like the Router
Whenever you’re unsure about why a router picks one route over another, think like this:
“What’s the best-fitting mask for this IP?”
If there’s a tie → “Which source do I trust more (lower AD)?”
Understanding LPM vs AD is not just for exams — it’s for saving your production network from misrouted traffic.