Lesson Contents
OSPF uses cost as the metric to choose the shortest path for each destination. However, OSPF first checks the route path type before the cost. The preference of route type can be different depending on your platform and OS version but in general, it works like this:
- Intra-Area (O)
- Inter-Area (O IA)
- NSSA Type 1 (N1)
- External Type 1 (E1)
- NSSA Type 2 (N2)
- External Type 2 (E2)
After the path selection, it will look at the lowest-cost path. Let me give you a quick example. If OSPF learns prefix 1.1.1.1/32 as an intra-area route (O) and as an inter-area route (O IA) then OSPF will always prefer the intra-area route, even if the inter-area route has a lower cost.
This strict “type before cost” rule, however, does not apply to every pair in the list above. It is important to understand the difference:
- Intra-area (O) vs inter-area (O IA): the route type is always decisive. An O route beats an O IA route regardless of cost.
- Type 1 externals (E1/N1) vs Type 2 externals (E2/N2): a Type 1 external always beats a Type 2 external, regardless of cost. This is because a Type 1 metric includes the internal cost to reach the ASBR, while a Type 2 metric does not.
- E1 vs N1 (and E2 vs N2): these are the same external metric class, so OSPF compares the cost first. The preference for N1 over E1 (and N2 over E2) only acts as a tie-breaker when the costs are equal. This means a lower-cost E1 can be preferred over a higher-cost N1.
Key Takeaways
- OSPF path selection checks the route path type before looking at the cost.
- An intra-area route is always preferred over inter-area routes, regardless of cost.
- A Type 1 external (E1/N1) is always preferred over a Type 2 external (E2/N2), regardless of cost.
- Between E1 and N1 (or E2 and N2), OSPF compares the cost first; the N-over-E preference is only a tie-breaker when costs are equal.
- When route types are identical, OSPF compares the lowest-cost metric.
- This behavior can cause OSPF to select higher-cost paths when route types differ.
Prerequisites
To follow this lesson, you should understand:
- Basic OSPF configuration and operation
- OSPF areas and area types (standard areas, stub areas, NSSA)
- OSPF LSA types and route redistribution
Configuration
I will demonstrate this behavior to you using the following topology:

We will create a loopback0 interface on R2 – R7 using the same prefix 1.1.1.1/32 and advertise it in OSPF as following:
- R2: Intra-Area (O)
- R3: Inter-Area (O IA)
- R4: External Type 1 (E1)
- R5: External Type 2 (E2)
- R6: NSSA Type 1 (N1)
- R7: NSSA Type 2 (N2)
We will check R1 to see what path it will prefer. Let’s configure OSPF first:
R1(config)#router ospf 1
R1(config-router)#router-id 11.11.11.11
R1(config-router)#network 192.168.12.0 0.0.0.255 area 0
R1(config-router)#network 192.168.13.0 0.0.0.255 area 0
R1(config-router)#network 192.168.14.0 0.0.0.255 area 0
R1(config-router)#network 192.168.15.0 0.0.0.255 area 0
R1(config-router)#network 192.168.16.0 0.0.0.255 area 167
R1(config-router)#network 192.168.17.0 0.0.0.255 area 167
R1(config-router)#area 167 nssa
First, we’ll advertise the correct areas on R1. Don’t forget to make area 167 the NSSA area. Let’s continue with the other routers:
R2(config)#router ospf 1
R2(config-router)#router-id 22.22.22.22
R2(config-router)#network 192.168.12.0 0.0.0.255 area 0
R2(config-router)#network 1.1.1.1 0.0.0.0 area 0
On R2, we will advertise 1.1.1.1/32 as an intra-area route.
R3(config)#router ospf 1
R3(config-router)#router-id 33.33.33.33
R3(config-router)#network 192.168.13.0 0.0.0.255 area 0
R3(config-router)#network 1.1.1.1 0.0.0.0 area 3
R3 will advertise 1.1.1.1/32 in area 3 to make it an inter-area route.
R4(config)#router ospf 1
R4(config-router)#router-id 44.44.44.44
R4(config-router)#network 192.168.14.0 0.0.0.255 area 0
R4(config-router)#redistribute connected subnets metric-type 1
R4 will redistribute prefix 1.1.1.1/32 as an external type 1 route.
R5(config)#router ospf 1
R5(config-router)#router-id 55.55.55.55
R5(config-router)#network 192.168.15.0 0.0.0.255 area 0
R5(config-router)#redistribute connected subnets
R5 will redistribute prefix 1.1.1.1/32 as an external type 2 route. Note that metric-type 2 is the default on Cisco IOS, so it does not appear in the running configuration.
R6(config)#router ospf 1
R6(config-router)#router-id 66.66.66.66
R6(config-router)#network 192.168.16.0 0.0.0.255 area 167
R6(config-router)#redistribute connected subnets metric-type 1
R6(config-router)#area 167 nssa
R6 is an NSSA ABR and will advertise 1.1.1.1/32 as an N1 route.
R7(config)#router ospf 1
R7(config-router)#router-id 77.77.77.77
R7(config-router)#network 192.168.17.0 0.0.0.255 area 167
R7(config-router)#redistribute connected subnets
R7(config-router)#area 167 nssa
Lastly, R7 will redistribute 1.1.1.1/32, so it shows up as an N2 route. Again, metric-type 2 is the default and is omitted from the running configuration.
router-id command.Let’s verify our configuration:
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
55.55.55.55 1 FULL/DR 00:00:39 192.168.15.5 GigabitEthernet0/3
44.44.44.44 1 FULL/DR 00:00:39 192.168.14.4 GigabitEthernet0/2
33.33.33.33 1 FULL/DR 00:00:39 192.168.13.3 GigabitEthernet0/1
22.22.22.22 1 FULL/DR 00:00:39 192.168.12.2 GigabitEthernet0/0
77.77.77.77 1 FULL/BDR 00:00:38 192.168.17.7 GigabitEthernet0/5
66.66.66.66 1 FULL/BDR 00:00:35 192.168.16.6 GigabitEthernet0/4
All OSPF neighbor adjacencies are working. Let’s take a look at the routing table to see what path OSPF has decided to use:
Great post Rene. OSPF is a protocol with lots of details. We can see some interesting things when we do OSPF external type 2 with same cost but different cost to ASBR.
i’ve learn something new, thanks rene
You are welcome Tim.
good site.. for good lessons
keep sharing, m/
I learned inner depth regarding protocol working …keep sharing …