A real-life situation
You ask two people for directions. One is a local taxi driver; the other is a tourist. Even if the tourist's route sounds shorter, you trust the taxi driver. Then, if the taxi driver gives you two routes, you take the shorter one. A router does exactly this, in that order.
What they are
Sometimes a router learns the same prefix (same network, same length) in more than one way. It needs a tie-breaker. There are two:
- Administrative distance (AD): how much the router trusts the source of a route. It is a number from 0 to 255. Lower is better. It compares routes from different sources, for example a static route against an OSPF route.
- Metric: the "cost" of a path, calculated by one routing protocol. Lower is better. It compares paths learned from the same protocol. Each protocol measures it differently.
| Route source | Default AD | Metric it uses |
|---|---|---|
| Connected | 0 | - |
| Static | 1 | 0 |
| eBGP (external BGP) | 20 | Path attributes, not one number |
| EIGRP (internal) | 90 | Bandwidth and delay |
| OSPF | 110 | Cost, based on bandwidth |
| IS-IS | 115 | Cost |
| RIP | 120 | Hop count (number of routers) |
| EIGRP (external) | 170 | Bandwidth and delay |
| iBGP (internal BGP) | 200 | Path attributes |
| Unknown / unreachable | 255 | Never used |
The order of decisions
- Longest prefix match picks which network to use (the “Longest prefix match” lesson).
- If several sources offer that exact prefix, the lowest AD goes into the routing table.
- If one protocol offers several paths, the lowest metric wins.
- If metrics are equal, the router keeps both paths and shares traffic across them. This is called equal-cost multi-path (ECMP).
- 1. Via R2, from OSPF: R1 learns 192.168.3.0/24 through R2 with AD 110.
- 2. Via the backup link, from RIP: the same /24, one hop away, but RIP's AD is 120. Fewer hops doesn't help: different sources are compared by AD only.
- 3. Result: the OSPF route is installed. The RIP route waits in the background and is used only if the OSPF route disappears.
Why it works this way
Metrics can't be compared across protocols. An OSPF cost of 3 and a RIP hop count of 1 measure different things, like comparing kilometres with minutes. So the router first asks "which source do I trust?", using AD, and only then "which path is cheapest?", using the metric from that one source.
The default values follow a simple idea: the more the router knows first-hand, the more it trusts the route. A connected network (AD 0) is a fact. A route someone typed in (AD 1) is a strong statement. Routes heard from protocols come next.
You can change the AD of a static route by adding a number at the end of the command. The “Floating static routes” lesson uses this to build a backup route that stays hidden until it's needed.
How to verify it
Both numbers appear in brackets as [AD/metric]. This output is based on Cisco documentation, not run on a lab device.
R1#show ip route 192.168.3.0 Routing entry for 192.168.3.0/24 Known via "ospf 1", distance 110, metric 3, type intra area Last update from 10.0.12.2 on GigabitEthernet0/1, 00:12:31 ago Routing Descriptor Blocks: * 10.0.12.2, from 3.3.3.3, 00:12:31 ago, via GigabitEthernet0/1 Route metric is 3, traffic share count is 1
O 192.168.3.0/24 [110/3] via 10.0.12.2. The RIP route doesn't appear at all, because only the winner is installed.Check yourself
R1 has a static route and an OSPF route for exactly 10.5.0.0/16. Which is installed?
OSPF offers two paths to the same network: cost 20 and cost 20. What does the router do?
OSPF offers 10.1.0.0/16 and RIP offers 10.1.1.0/24. Where does a packet to 10.1.1.9 go?