When an OSPF router learns multiple routes to the same destination, it must pick the best one. This decision isn't random—it follows a precise, deterministic logic that the CCNA 200-301 exam expects you to know inside out. Understanding OSPF path selection is critical because it determines how traffic flows through your network, and misconfigurations can lead to suboptimal routing or black holes. This chapter covers exam objective 3.4: IP Connectivity – OSPF Path Selection Logic, giving you the mechanistic understanding you need to both pass the exam and build real-world networks.
Jump to a section
Imagine you manage a fleet of delivery trucks for a national courier company. Your job is to get a package from New York to Los Angeles as efficiently as possible. You have multiple drivers, each with a different route. Driver A takes Interstate 80 – it's the shortest distance (2,800 miles) but has many tolls and traffic jams. Driver B takes Interstate 40 – slightly longer (2,900 miles) but with fewer stops and higher speed limits. Driver C takes a scenic route through the Rockies – it's beautiful but slow and winding. How do you decide which driver to send?
You don't just look at distance. You consider the total 'cost' of each route: time, fuel, tolls, wear and tear. In OSPF, each link has a cost (inversely related to bandwidth), and the router adds up the costs along each path to the destination. The path with the lowest total cost wins. But there's more: if two paths have the same cost, OSPF can load-balance across them (ECMP). Also, OSPF prefers intra-area routes over inter-area routes, regardless of cost. Think of it like this: a package going to a neighboring city (intra-area) is easier than one going across the country (inter-area), even if the cross-country highway is faster.
Just like you wouldn't send a truck on a road that's closed, OSPF won't use a route that's down (link failure). And if a new, cheaper road opens (a better path), the fleet manager (OSPF) recalculates and may switch drivers. The 'cost' is OSPF's metric, and it's calculated as 100,000,000 / bandwidth (in bps) by default. So a 100 Mbps link has cost 1, a 10 Mbps link has cost 10, and a 1 Gbps link has cost 0.1 (but OSPF truncates to integer, so it's 1). This analogy captures the core of OSPF path selection: cost-based, with administrative preferences for route type.
What is OSPF Path Selection Logic?
OSPF (Open Shortest Path First) is a link-state routing protocol that uses the Shortest Path First (SPF) algorithm (Dijkstra's algorithm) to compute the best path to each destination. The path selection logic determines which routes are installed in the routing table (RIB) and used for forwarding. The exam objective 3.4 (IP Connectivity – OSPF Path Selection) focuses on how OSPF chooses between multiple paths to the same subnet, including the concept of OSPF cost, equal-cost multipath (ECMP), and the preference for intra-area vs. inter-area routes.
OSPF Metric: Cost
OSPF uses a metric called 'cost' which is inversely proportional to the bandwidth of the interface. The default formula is:
Cost = reference-bandwidth / interface-bandwidth
Where the default reference bandwidth is 100 Mbps (100,000,000 bps). For example:
FastEthernet (100 Mbps): cost = 100,000,000 / 100,000,000 = 1
GigabitEthernet (1000 Mbps): cost = 100,000,000 / 1,000,000,000 = 0.1 → truncated to 1
10 Mbps Ethernet: cost = 100,000,000 / 10,000,000 = 10
T1 (1.544 Mbps): cost = 100,000,000 / 1,544,000 ≈ 64
Because OSPF cost must be an integer, very high-speed interfaces (>=1 Gbps) all get cost 1 with the default reference bandwidth. This can cause suboptimal routing in modern networks. To fix this, you can change the reference bandwidth using:
router ospf 1
auto-cost reference-bandwidth 10000This sets the reference to 10 Gbps, so a 1 Gbps link gets cost 10, a 10 Gbps link gets cost 1, etc. Note: the reference bandwidth must be consistent across all routers in the OSPF domain.
Path Selection Steps
OSPF's path selection logic follows this order:
Intra-area routes (O) are preferred over inter-area routes (O IA). An intra-area route is one where the destination subnet is in the same OSPF area as the router. Inter-area routes are learned via ABRs. This preference is hardcoded and cannot be changed.
If multiple intra-area routes exist, OSPF compares the total cost to the destination. The path with the lowest cost is chosen. Costs are additive along the path.
If multiple inter-area routes exist, OSPF compares the cost to the ABR (not the total cost to the destination). Wait—this is a common misconception. Actually, OSPF compares the total cost from the local router to the destination, including the cost from the ABR to the destination. However, for inter-area routes, the cost to the ABR plus the cost advertised by the ABR is used. The path with the lowest total cost wins.
If two paths have equal cost, OSPF installs both (ECMP) up to a maximum of 4 paths by default (configurable with `maximum-paths`).
If there are still multiple paths (e.g., equal cost via different ABRs), OSPF may use the next tiebreaker: Router ID (lowest wins) or interface type? Actually, OSPF does not have a deterministic tiebreaker beyond cost for intra-area. For inter-area, if costs are equal, OSPF may install multiple paths (ECMP) or pick one based on implementation. In practice, Cisco IOS installs up to 4 equal-cost paths.
The SPF Algorithm
OSPF uses Dijkstra's algorithm to compute the shortest path tree (SPT) from the router's perspective. Each router builds a link-state database (LSDB) containing all routers and their links in the area. The SPF algorithm runs on the LSDB to find the shortest path to each destination. The algorithm:
Starts with the local router as the root.
Examines all neighbor routers and adds them to a candidate list with a cost equal to the link cost.
Selects the candidate with the lowest cost and moves it to the tree.
Repeats, adding new candidates from the newly added router, updating costs cumulatively.
Continues until all routers are in the tree.
The result is a loop-free topology. The SPF algorithm runs only within an area; inter-area routes are computed using distance-vector-like behavior (ABRs advertise summaries).
Verifying OSPF Path Selection
Use show ip route ospf to see OSPF routes:
R1# show ip route ospf
10.1.1.0/24 is variably subnetted, 2 subnets, 2 masks
O 10.1.1.0/24 [110/2] via 192.168.1.2, 00:00:15, GigabitEthernet0/0
O IA 10.2.2.0/24 [110/3] via 192.168.1.2, 00:00:15, GigabitEthernet0/0The [110/2] shows administrative distance (110) and metric (cost). O means intra-area, O IA means inter-area.
To see the OSPF database for a specific route:
R1# show ip ospf databaseTo see the SPF tree:
R1# show ip ospf border-routersCost Manipulation
You can manually set the OSPF cost on an interface:
interface GigabitEthernet0/0
ip ospf cost 10This overrides the auto-cost. You can also set the bandwidth on the interface, which affects auto-cost:
interface GigabitEthernet0/0
bandwidth 100000But note: changing bandwidth affects other protocols (like EIGRP) and is not recommended just for OSPF cost tuning.
Interaction with Other Protocols
OSPF path selection is independent of other routing protocols. However, when multiple routing protocols learn the same route, the administrative distance (AD) determines which route is installed. OSPF has AD 110. So if OSPF and EIGRP (AD 90) both know about 10.1.1.0/24, EIGRP wins regardless of metric. This is a common exam point: AD is checked before metric.
Understand OSPF Route Types
OSPF categorizes routes into three types: intra-area (O), inter-area (O IA), and external (O E1 or O E2). Intra-area routes are learned via Type 1 LSAs (Router LSAs) and Type 2 LSAs (Network LSAs) within the same area. Inter-area routes are learned via Type 3 LSAs (Summary LSAs) from ABRs. External routes are learned via Type 5 LSAs (AS External LSAs) from ASBRs. The exam expects you to know that intra-area routes are always preferred over inter-area routes, regardless of cost. This is a hardcoded rule in OSPF. For example, if an intra-area path has cost 100 and an inter-area path has cost 1, the intra-area path is still chosen.
Calculate OSPF Cost for Each Path
OSPF cost is calculated as reference bandwidth divided by interface bandwidth. The default reference is 100 Mbps. For each path from the local router to the destination subnet, add the costs of all outgoing interfaces along the path. The total cost is the metric for that path. For example, if a router has a 100 Mbps link (cost 1) to a neighbor, and that neighbor has a 10 Mbps link (cost 10) to the destination, the total cost is 11. Remember that OSPF cost is only meaningful within an area; inter-area routes include the cost from the ABR to the destination, which is advertised in the Type 3 LSA.
Compare Costs and Select Best Path
For intra-area routes, OSPF compares the total cost to the destination and picks the lowest cost path. If multiple paths have the same cost, OSPF installs up to 4 equal-cost paths (ECMP) by default. For inter-area routes, OSPF also compares total cost, but the cost from the ABR to the destination is included. The path with the lowest total cost is installed. If there are multiple ABRs with equal total cost, OSPF may install multiple paths (ECMP) or pick one based on implementation. Note that OSPF does not consider hop count; only cost matters.
Verify Routes with show commands
Use `show ip route ospf` to see which OSPF routes are installed. Look for the prefix, metric (in [AD/metric]), and next hop. For example: `O 10.1.1.0/24 [110/20] via 192.168.1.1`. The metric 20 is the total cost. Use `show ip ospf interface` to see the cost assigned to each interface. Use `show ip ospf database` to see the link-state database, including the cost advertised by neighbors. For troubleshooting, use `debug ip ospf spf` to see SPF calculations (but be careful in production).
Troubleshoot Suboptimal Path Selection
If traffic takes a suboptimal path, check the OSPF costs. Common issues: (1) Auto-cost reference bandwidth mismatch – if one router uses default (100 Mbps) and another uses a higher reference, costs will be inconsistent. (2) Manual cost misconfiguration – an interface may have an incorrect `ip ospf cost` set. (3) Bandwidth misconfiguration – if an interface's bandwidth is set incorrectly (e.g., a 1 Gbps link with bandwidth 1000000 instead of 1000000), the auto-cost will be wrong. (4) Route type preference – an intra-area route with high cost may be preferred over an inter-area route with lower cost. Use `show ip route` to see the installed route, then trace the path and verify costs on each interface.
Manipulate Path Selection with Cost
To influence OSPF path selection, you can change the cost on an interface using `ip ospf cost <value>`. This is preferred over changing bandwidth because it only affects OSPF. For example, to make a backup link less preferred, set its cost higher. To force traffic through a specific path, lower its cost. You can also change the reference bandwidth globally with `auto-cost reference-bandwidth` under router ospf. Remember that cost must be an integer between 1 and 65535. Also, you can use `maximum-paths <number>` to control how many equal-cost paths are installed (default 4, max 16).
In enterprise networks, OSPF path selection logic is crucial for traffic engineering and redundancy. Consider a company with two data centers: DC1 and DC2, each connected to a campus network via dual links. The campus router has two OSPF paths to a server subnet in DC1: one via a 10 Gbps direct link (cost 1) and another via a 1 Gbps link through DC2 (cost 10). OSPF will choose the direct 10 Gbps path because of lower cost. This is desired. But what if the 10 Gbps link fails? OSPF automatically switches to the backup path via DC2. This failover happens quickly (within seconds) because OSPF detects the link down via hello timers (default 10 seconds) and runs SPF to recalculate.
Another scenario: a service provider uses OSPF within its backbone. They have multiple links between routers with different bandwidths. To ensure that traffic uses the highest-bandwidth links, they rely on OSPF's auto-cost. However, with default reference bandwidth (100 Mbps), all links >=1 Gbps get cost 1, so OSPF sees them as equal-cost and load-balances. This may be undesirable if they want to prefer 10 Gbps over 1 Gbps. They would change the reference bandwidth to 10 Gbps or 100 Gbps to differentiate costs.
A common misconfiguration is forgetting to set the same reference bandwidth on all routers. If one router uses default (100 Mbps) and another uses 10000 Mbps (10 Gbps), the costs will be inconsistent, leading to routing loops or suboptimal paths. For example, Router A sees a 1 Gbps link as cost 1, while Router B sees it as cost 10. When Router A advertises a route with cost 1, Router B adds its own cost to reach Router A, resulting in a total cost that doesn't reflect the true path cost. This can cause asymmetric routing.
In production, network engineers often manually set OSPF cost to achieve specific traffic flows, such as making a satellite link less preferred than a fiber link, even if the satellite has higher bandwidth (due to latency). OSPF cost is purely based on bandwidth, not latency, so manual tuning is necessary. Also, OSPF path selection can be influenced by using different OSPF areas to force traffic through specific ABRs. For example, placing a subnet in a different area can make it inter-area, which is less preferred than intra-area, effectively steering traffic away from that path.
The 200-301 exam tests OSPF path selection under objective 3.4: IP Connectivity – OSPF Path Selection. Expect multiple-choice questions that present a topology and ask which path OSPF will choose, or why a particular route is preferred. Key points to remember:
Intra-area (O) always beats inter-area (O IA), regardless of cost. This is the most common trap. A question might show an intra-area path with cost 100 and an inter-area path with cost 10, and ask which is installed. Many candidates choose the inter-area because of lower cost, but the correct answer is the intra-area. Remember: route type preference is checked before cost.
OSPF cost calculation: Know the formula (100,000,000 / bandwidth). Be able to calculate cost for common link speeds: 10 Mbps = 10, 100 Mbps = 1, 1 Gbps = 1 (with default reference). If the reference bandwidth is changed, recalculate accordingly. Exam questions may give you a reference bandwidth and ask for the cost.
ECMP: OSPF installs up to 4 equal-cost paths by default. If a question shows two paths with equal cost, expect that both are used (load balancing). The maximum-paths command can change this.
Administrative Distance: OSPF AD is 110. If the same route is learned from another protocol (e.g., EIGRP AD 90), that route wins regardless of OSPF metric. A question might combine OSPF and static routes (AD 1) – static wins.
5. Common wrong answers: - Choosing the path with fewer hops (OSPF doesn't use hop count). - Thinking that OSPF prefers higher bandwidth links (it prefers lower cost, which is higher bandwidth, but only if cost is lower). - Assuming that OSPF always load-balances across multiple paths (only if equal cost). - Forgetting that intra-area routes are preferred over inter-area.
Elimination strategy: For scenario questions, first identify the route types (O vs O IA). Then compare costs. If costs are equal, ECMP applies. If multiple paths from different protocols, AD decides. Always check the destination subnet and which router is advertising it.
Command outputs: Be able to read show ip route ospf output. Know that [110/20] means AD 110, metric 20. The letter O or O IA indicates the route type. Also, show ip ospf interface brief shows cost per interface.
OSPF prefers intra-area routes (O) over inter-area routes (O IA) regardless of metric.
OSPF cost = reference-bandwidth (default 100 Mbps) / interface bandwidth; cost is an integer.
For equal-cost paths, OSPF installs up to 4 paths by default (configurable with maximum-paths).
Administrative distance of OSPF is 110; other protocols with lower AD override OSPF.
Use 'show ip route ospf' to see installed OSPF routes with metric and next hop.
Manual cost configuration with 'ip ospf cost' overrides auto-cost.
The SPF algorithm (Dijkstra) computes shortest path based on cumulative cost.
OSPF does not consider hop count, only cost.
Auto-cost reference bandwidth should be consistent across all routers in the OSPF domain.
OSPF external routes (O E1/E2) have their own preference rules, but are beyond CCNA scope.
These come up on the exam all the time. Here's how to tell them apart.
OSPF Path Selection
Uses cost metric based on bandwidth (reference/interface).
Prefers intra-area routes over inter-area regardless of metric.
Equal-cost load balancing only; unequal-cost not supported.
Metric is a single value (cost).
SPF algorithm computes shortest path tree.
EIGRP Path Selection
Uses composite metric based on bandwidth, delay, load, reliability (K values).
No concept of area; all internal routes are equal (unless redistribution).
Supports unequal-cost load balancing (variance command).
Metric is a composite value; can be complex.
DUAL algorithm provides fast convergence and loop-free paths.
Mistake
OSPF selects the path with the fewest hops.
Correct
OSPF uses cost, not hop count. Hop count is used by RIP. OSPF cost is based on bandwidth. A path with more hops but higher bandwidth (lower cost) can be preferred over a path with fewer hops but lower bandwidth.
Candidates often confuse OSPF with RIP because both are IGP protocols, but they use different metrics.
Mistake
OSPF always prefers the path with the highest bandwidth.
Correct
OSPF prefers the path with the lowest cost, which is inversely proportional to bandwidth. Higher bandwidth gives lower cost, but if two paths have different bandwidths but the same cost (e.g., both cost 1 due to reference bandwidth issues), they are considered equal.
The term 'cost' is confusing; candidates think higher bandwidth = better, so they assume OSPF picks the highest bandwidth link directly.
Mistake
An inter-area route with a lower cost is preferred over an intra-area route with a higher cost.
Correct
Intra-area routes are always preferred over inter-area routes, regardless of cost. This is a hardcoded rule in OSPF. The route type (O vs O IA) is the first tiebreaker.
Candidates assume metric is the only factor, but OSPF has administrative preference for routes learned within the same area.
Mistake
OSPF load-balances across all available paths to a destination.
Correct
OSPF only load-balances across equal-cost paths. By default, it installs up to 4 equal-cost paths. If paths have different costs, only the best (lowest cost) path is used.
Candidates may think OSPF uses all paths for redundancy, but it only uses paths with the same metric.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
OSPF uses the SPF (Shortest Path First) algorithm to compute the shortest path tree from the router to all destinations. The metric is cost, which is calculated as reference bandwidth divided by interface bandwidth (default reference 100 Mbps). The path with the lowest total cost is chosen. However, OSPF first prefers intra-area routes over inter-area routes, regardless of cost. If multiple equal-cost paths exist, OSPF installs up to 4 (default) for load balancing. Exam tip: Always check route type (O vs O IA) before comparing costs.
Intra-area routes (O) are learned within the same OSPF area via Type 1 and Type 2 LSAs. Inter-area routes (O IA) are learned from other areas via Type 3 LSAs generated by ABRs. OSPF always prefers intra-area routes, even if the inter-area route has a lower cost. This is a hardcoded rule. On the exam, if you see both an O and O IA route to the same subnet, the O route wins. Inter-area routes are used when the destination is in a different area.
Yes, use the `ip ospf cost <value>` interface command. The value must be an integer between 1 and 65535. This overrides the auto-cost calculation. This is useful for traffic engineering, such as making a backup link less preferred. Alternatively, you can change the interface bandwidth with the `bandwidth` command, but that affects other protocols. The `ip ospf cost` command is preferred because it only affects OSPF.
Because the default reference bandwidth is 100 Mbps. For any interface with bandwidth >= 100 Mbps, the cost calculation (100,000,000 / bandwidth) yields a number less than 1, which is truncated to 1. To differentiate higher-speed links, change the reference bandwidth globally with `auto-cost reference-bandwidth <Mbps>` under router ospf. For example, setting it to 10000 (10 Gbps) gives a 1 Gbps link cost 10 and a 10 Gbps link cost 1.
ECMP allows OSPF to install multiple routes to the same destination when they have equal cost. By default, OSPF installs up to 4 equal-cost paths. The router then load-balances traffic across these paths. You can change the maximum number with the `maximum-paths <number>` command under router ospf. ECMP is a key feature for redundancy and increased throughput.
External routes are injected into OSPF by an ASBR (Autonomous System Boundary Router) using Type 5 LSAs. There are two types: E1 (external type 1) and E2 (external type 2). E1 routes add the internal cost to the external metric, while E2 routes use only the external metric (default). OSPF prefers E1 over E2 if both are present. External routes have a higher administrative distance than internal routes? No, they share the same AD (110). However, OSPF prefers intra-area and inter-area routes over external routes. This is beyond CCNA scope but good to know.
OSPF has an administrative distance (AD) of 110. AD is a trustworthiness value; lower is more trusted. If a router learns the same route from multiple routing protocols, the one with the lowest AD is installed. For example, a static route (AD 1) or EIGRP (AD 90) would be preferred over OSPF. Even if OSPF has a better metric, the lower AD wins. This is a common exam trap: a question may show OSPF with cost 1 and EIGRP with metric 100, but the EIGRP route is installed because its AD (90) is lower than OSPF's 110.
You've just covered OSPF Path Selection Logic — now see how well it sticks with free CCNA 200-301 practice questions. Full explanations included, no account needed.
Done with this chapter?