The cheapest path does not always win
A router can hold more than one OSPF route to the same prefix, for example when a network is reachable inside the area and also advertised as an external route. A router installing the cheapest of them would be easy to explain, but OSPF compares something else first: how the route was learned.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Four route types are compared in order. An intra-area route (code O) comes from router and network LSAs in the router's own area. An inter-area route (O IA) comes from a type 3 summary advertised by an ABR. An external type 1 route (O E1) adds the cost of the internal path to the ASBR onto the external metric. An external type 2 route (O E2, the default for redistributed routes) keeps the external metric only. In a not-so-stubby area, type 7 routes follow the same pattern as N1 and N2.
Worked example: a cheap external route loses
R3 learns 198.18.0.0/24 twice. One path crosses the backbone as an inter-area route with total cost 60. The other is an external type 2 route with metric 20. Compared as numbers, 20 looks better. Compared by type, inter-area wins.
| Candidate | Type | Cost shown | Result |
|---|---|---|---|
| Via R2 (ABR) | O IA | 60 | Installed |
| Via R5 (ASBR) | O E2 | 20 (+ forward cost, not compared first) | Not installed |
R3#show ip route 198.18.0.0 Routing entry for 198.18.0.0/24 Known via "ospf 1", distance 110, metric 60, type inter area Last update from 10.0.23.1 on GigabitEthernet0/0, 00:04:11 ago Routing Descriptor Blocks: * 10.0.23.1, from 2.2.2.2, 00:04:11 ago, via GigabitEthernet0/0 Route metric is 60, traffic share count is 1
type inter area explains why the lower external metric was ignored.E1 and E2 with two ASBRs
On small screens, swipe sideways or focus the diagram and use the arrow keys.
With E2, the metric inside OSPF does not grow as the route crosses the network, so the same prefix from two ASBRs with metric 20 ties on the external metric. The router then compares the forward metric: the internal cost to each ASBR. The lower one wins. With E1, the internal cost is already added, so the lowest total decides. Use E1 when the exit closest to the traffic should win and the external metrics are comparable; use E2 when a single exit is preferred whatever the distance.
| Exit | External metric | Cost to ASBR | E2 compares | E1 compares |
|---|---|---|---|---|
| ASBR A | 20 | 10 | 20, then 10 | 30 |
| ASBR B | 20 | 30 | 20, then 30 | 50 |
Both rules choose ASBR A here. They differ when the external metrics differ: E2 would pick the lower external metric even if that exit is far away.
Checking which type you have
show ip route ospf
show ip ospf database external 198.18.0.0
show ip ospf border-routersThe route code shows the type. The external LSA shows its metric type and advertising router. The border-router list shows the cost to the ASBR.
When two equal routes remain, the router installs up to the configured maximum number of equal-cost paths (four by default on many IOS releases) and shares traffic across them.
Check your understanding
A router has an inter-area route with cost 80 and an E2 route with metric 10 for the same prefix. Which is installed?
Two ASBRs advertise the same E2 prefix with metric 20. The cost to ASBR A is 10 and to ASBR B is 40. What happens?
A /25 route from RIP and a /24 route from OSPF cover the same address. Which does the router use for that address?