In 20 years, you will be more dissapointed by what you didn't do than by what you did.

Administrative Distance vs Metric vs Longest Prefix Match Explained

Does a router choose the lowest administrative distance, the lowest metric, or the longest prefix? The answer depends on whether you mean building the routing table or forwarding a packet.[1]

Short answer: A routing protocol selects its candidates using its own path-selection rules; administrative distance (AD) selects between competing route sources for the same prefix and prefix length; longest prefix match selects the most specific installed route when forwarding a packet.[1] Do not treat these as three numbers compared together for every packet.[1]

Administrative distance vs metric vs longest prefix match

This guide uses Cisco routing terminology and defaults, with ordinary destination-based IPv4 forwarding as its scope.

Mechanism Question it answers Where it applies Key limitation
Protocol metric and path-selection rules Which candidate does this protocol prefer? Routing protocol computation Metrics from different protocols are not a common scoring system.[1]
Administrative distance Which route source should supply this exact prefix? Routing Information Base (RIB) selection A lower AD does not remove a different-length prefix.[1][2]
Longest prefix match Which installed prefix best matches this packet's destination? Forwarding Information Base (FIB) lookup Only usable installed forwarding entries participate.[1]

Think of route selection and packet lookup as separate problems: route selection supplies the usable entries, while packet lookup chooses among their matching prefixes.[1]

The process: candidates, RIB, FIB, packet

The following is a conceptual flow, not a claim that every platform implements identical internal steps:

Protocol information / configured routes
        |
        v
Each protocol chooses its best eligible candidates
        |
        v
For an identical prefix: compare route-source AD
Validate usability, including next-hop resolution
        |
        v
Selected RIB routes support forwarding entries in the FIB
        |
Packet arrives -> destination lookup -> longest matching prefix
        |
        v
Selected next hop / outgoing forwarding action

Cisco documents protocol best-path selection before RIB comparison, and explicitly separates longest prefix match from route installation.[1] A route with an unresolved next hop cannot simply win installation because its AD is attractive.[1]

Interview trap: “Longest prefix, then AD, then metric” can help classify a paper question, but it is misleading as a description of what happens to each arriving packet: AD and metric have already influenced installation, not the forwarding lookup.[1]

Worked example: an OSPF route beats a static route for one packet

This is an original, hypothetical scenario, not captured router output. Assume all listed routes are usable, their next hops resolve, and the forwarding entries are installed in the same routing context.

Installed route Source AD Metric Next hop
0.0.0.0/0 Static 1 0 192.0.2.1
10.42.0.0/16 Static 1 0 192.0.2.2
10.42.7.0/24 OSPF 110 50 192.0.2.3

For destination 10.42.7.25, the matching /24 wins, so the hypothetical packet uses 192.0.2.3; the static /16 having AD 1 does not override that more-specific entry.[1][2]

For destination 10.42.8.25, there is no matching /24 in this example, so the /16 is the longest match and selects 192.0.2.2.[2]

For destination 198.51.100.25, only the default route matches, selecting 192.0.2.1.[2]

All three routes can coexist because they represent different destination prefixes; they are not competing to install the same exact route.[2]

Now make the prefixes identical

Suppose internal EIGRP and OSPF both propose 10.42.7.0/24, with their default Cisco distances and usable next hops. Internal EIGRP wins RIB selection at AD 90 versus OSPF at AD 110.[1] An OSPF metric of 2 does not beat an EIGRP metric of 30720 by being numerically smaller: they belong to different metric systems.[1]

If the internal EIGRP route is withdrawn, the OSPF candidate may become installed, provided it remains valid and usable.[1] That is a change to the selected route, not a per-packet comparison of EIGRP and OSPF metrics.[1]

Cisco administrative distance values worth knowing

These are Cisco defaults from the cited documentation, not universal values for every vendor or configuration.[1]

Route source Default AD
Connected 0
Static 1
eBGP 20
Internal EIGRP 90
OSPF 110
IS-IS 115
RIP 120
External EIGRP 170
iBGP 200

A Cisco route assigned AD 255 is not installed; it is not a last-resort backup.[1] AD is local to the router and is not advertised in routing updates.[1]

Avoid saying simply “EIGRP beats OSPF”: internal EIGRP defaults to 90, but external EIGRP defaults to 170, so the route type matters.[1]

Floating static route: why the prefix must match your intention

A floating static route uses an AD higher than the preferred route source for the same destination prefix, so it becomes eligible for installation after the preferred route disappears, assuming its next hop remains reachable.[1]

Illustrative Cisco IOS/IOS XE configuration for an isolated lab:

! Assumption: OSPF normally supplies 10.42.7.0/24 at AD 110.
! Assumption: 192.0.2.2 resolves through an independent backup path.
ip route 10.42.7.0 255.255.255.0 192.0.2.2 200

The final value is the static route's AD, not its metric.[2] In this example, the static /24 is a backup to the OSPF /24 because 200 is higher than 110.[1]

By contrast, a static /25 inside that /24 with AD 200 is a different prefix: if usable and installed, it attracts matching traffic immediately through longest prefix match.[1][2]

Raising its AD does not make it “float behind” the broader /24.[1][2]

Suggested test: Before applying any backup design in production, withdraw the primary route in a lab, check that the backup next hop still resolves, test return traffic, then restore the primary. These are proposed validation steps, not results of a router lab run for this article.

Troubleshooting checklist: verify the destination, not just the protocol

Use this checklist as an investigation order:

  1. Record the exact destination IP and routing context, including the VRF if applicable.
  2. Identify the longest matching route that is actually installed; do not compare a /16 and /24 solely by their AD.[1][2]
  3. For an unexpected source of the same prefix, inspect the configured distances and route type.[1]
  4. For an unexpected path within one protocol, inspect that protocol's path-selection rules and eligible candidates rather than comparing unrelated metric numbers.[1]
  5. Check next-hop resolution before assuming a valid-looking candidate should be installed.[1]
  6. Compare the routing and forwarding views, then test the reverse direction separately.

Read-only Cisco IOS/IOS XE-style verification commands, with syntax to confirm against your platform:

show ip route 10.42.7.25
show ip route 10.42.7.0 255.255.255.0
show ip protocols
show ip cef 10.42.7.25 detail

In Cisco show ip route output, a value such as [110/50] means administrative distance 110 and protocol metric 50.[1] It does not mean “110 hops,” and it is not a two-part packet-forwarding score.[1]

Do not change AD as a first troubleshooting step: inconsistent AD changes can create suboptimal paths, loops or black holes.[1] First explain which candidate is missing, which exact prefix is selected, and whether the forwarding entry matches the intended design.

Common interview pitfalls

  • “Static always wins.” Only compare AD for the same destination prefix; a more-specific installed dynamic route can carry the packet.[1][2]
  • “Metric 2 is better than metric 30720.” That comparison is meaningless across incompatible routing protocols.[1]
  • “The route with the highest AD is never used.” It may be the only usable route to that exact prefix, or a more-specific installed prefix.[1][2]
  • “Every protocol is just lowest metric.” Protocols apply their own path-selection algorithms; keep that stage separate from cross-source AD selection.[1]
  • “A configured backup route guarantees failover.” Installation still depends on eligibility and a usable next hop.[1]
  • “AD changes influence the neighbor directly.” AD is a local selection value, not an advertised routing attribute.[1]

A concise interview answer

I separate route installation from forwarding. Each routing protocol chooses its best eligible candidates using its own rules, and administrative distance selects between route sources for the same prefix and prefix length.[1]

Once routes are installed, ordinary destination-based forwarding uses the longest matching prefix, not the lowest AD across every matching entry.[1]

For example, an installed OSPF /24 beats a static /16 for a destination inside the /24, while a static and an OSPF route to the same /24 compete by administrative distance.[1][2]

Related reading

Summary

Protocol rules choose candidates, AD arbitrates route sources for an identical prefix, and longest prefix match directs packets using installed entries. Keeping those decisions separate is the key to explaining both routing-table results and actual forwarding.[1]

Preparing for a network engineering interview? Practice the three destination lookups above, then change the backup /24 to a /25 and explain why that changes the outcome before touching a router.

Sources

Comments

0 Responses to "Administrative Distance vs Metric vs Longest Prefix Match Explained"

Post a Comment

Popular Posts