Course contents

Module 6: Advanced OSPFLesson 6.5 (5 of 8 in this module)26 of 29 in the OSPF course

OSPF path selection: route types before cost

How a router chooses between intra-area, inter-area, E1 and E2 routes to the same prefix, and why a cheaper path can lose.

Advanced · 10 min read

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.

OSPF prefers the route type before it looks at cost
OSPF prefers the route type before it looks at costFour rows in order of preference: intra-area, inter-area, external type 1 and external type 2. NSSA N1 and N2 follow the same order as E1 and E2.1 Intra-area (O)Learned inside the area from router and network LSAs2 Inter-area (O IA)Learned from a type 3 summary through an ABR3 External type 1 (O E1)External metric plus the cost to reach the ASBR4 External type 2 (O E2)External metric only; internal cost breaks ties

On small screens, swipe sideways or focus the diagram and use the arrow keys.

For the same prefix, a higher-ranked type wins even if its total cost is larger. Cost is compared only between routes of the same type. Longest prefix match is decided before any of this.

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.

CandidateTypeCost shownResult
Via R2 (ABR)O IA60Installed
Via R5 (ASBR)O E220 (+ forward cost, not compared first)Not installed
Illustrative Cisco IOS output written for this lesson, not a router capture
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
Only the winner is installed. The line type inter area explains why the lower external metric was ignored.

E1 and E2 with two ASBRs

E1 and E2 choose between two exits differently
E1 and E2 choose between two exits differentlyTwo ASBRs advertise the same external prefix with external metric 20. R1 is 10 away from ASBR A and 30 away from ASBR B. With E2 the external metrics tie at 20, so the forward cost breaks the tie and ASBR A wins with 10. With E1 the router adds its internal cost to the external metric, 30 for ASBR A and 50 for ASBR B, and ASBR A wins again.R1internal routerASBR Aexternal metric 20ASBR Bexternal metric 20External198.51.100.0/24cost 10cost 30E2: compares external metric, then forward costA: 20 then 10 B: 20 then 30E1: adds internal cost to the external metricA: 20 + 10 = 30 B: 20 + 30 = 50

On small screens, swipe sideways or focus the diagram and use the arrow keys.

The two types agree when the external metrics are equal. They disagree when the metrics differ: E2 would choose the lower external metric even through a far-away ASBR, while E1 weighs the whole path.

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.

ExitExternal metricCost to ASBRE2 comparesE1 compares
ASBR A201020, then 1030
ASBR B203020, then 3050

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-routers

The 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

Predict · scenario 1

A router has an inter-area route with cost 80 and an E2 route with metric 10 for the same prefix. Which is installed?

Predict · scenario 2

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?

Predict · scenario 3

A /25 route from RIP and a /24 route from OSPF cover the same address. Which does the router use for that address?

FAQ

Does OSPF always pick the lowest total cost?
No. For the same prefix and mask it compares the route type first: intra-area, then inter-area, then external type 1, then external type 2. Cost is compared only among routes of the same type.
Which route wins before any of this?
The longest matching prefix wins first, regardless of protocol. If several routing sources offer the same prefix, administrative distance picks the source (110 for OSPF by default). The OSPF ordering applies inside OSPF.
What breaks an E2 tie?
With equal external metrics, the lower forward metric, the internal cost to reach the ASBR, is preferred. If those tie as well, the router can install several equal-cost paths.