Why does your OSPF network prefer one path over another? It's not magic—it's cost calculation. On the CCNA 200-301 exam, you must understand how OSPF computes its metric (cost) to determine the best route, because exam questions love to test your ability to predict path selection based on interface bandwidth. Real network engineers also need this skill to troubleshoot suboptimal routing or to engineer traffic flows. This chapter covers exam objective 3.4: 'Configure and verify OSPF (single area) – cost calculation.'
Jump to a section
Imagine you're a delivery company choosing between two routes to deliver packages from City A to City B. Route X is a 10-lane superhighway with a speed limit of 120 km/h. Route Y is a narrow two-lane country road with a speed limit of 40 km/h. Your company calculates the 'cost' of each route based on the time it takes to travel one kilometer: on the superhighway, one kilometer takes 30 seconds (fast, low cost), while on the country road, it takes 90 seconds (slow, high cost). The total trip cost is the sum of per-kilometer costs along the path. Now, suppose there's a third route that is a mix of both road types. You add up the costs of each segment to get the total cost. The delivery always takes the path with the lowest total cost. In OSPF, the 'speed limit' is the interface bandwidth. OSPF calculates cost as reference bandwidth divided by interface bandwidth. The default reference bandwidth is 100 Mbps. So a FastEthernet (100 Mbps) interface gets a cost of 100/100 = 1. A T1 (1.544 Mbps) interface gets a cost of 100/1.544 ≈ 64. The lower the cost, the more preferred the route. Just as your delivery company might change the reference 'time-per-km' factor if all roads become faster, network engineers often change the OSPF reference bandwidth to 1000 Mbps (1 Gbps) to handle modern high-speed links. The analogy also covers equal-cost multipath: if two routes have the same total cost, the load is shared, just like splitting deliveries between two equally fast routes.
What Is OSPF Cost and Why Does It Exist?
OSPF (Open Shortest Path First) uses a link-state routing algorithm (Dijkstra's SPF) to compute the shortest path tree to every destination. Unlike RIP's hop count or EIGRP's composite metric, OSPF uses a dimensionless metric called cost. The cost is inversely proportional to the bandwidth of the interface: higher bandwidth = lower cost. This design allows OSPF to prefer faster paths over slower ones, which is more realistic for modern networks where bandwidth is often the bottleneck, not hop count.
How OSPF Cost Is Calculated: The Formula
The standard formula on Cisco IOS is:
Cost = Reference Bandwidth / Interface Bandwidth
Where:
Reference Bandwidth: default is 100 Mbps (100,000,000 bps)
Interface Bandwidth: the configured bandwidth of the interface in bps (not the actual speed; it's a configurable parameter)
The result is an integer; fractional values are rounded down. For example: - 10 Mbps Ethernet: cost = 100 / 10 = 10 - 100 Mbps FastEthernet: cost = 100 / 100 = 1 - 1 Gbps GigabitEthernet: cost = 100 / 1000 = 0.1 → truncated to 1 (since cost must be at least 1) - T1 (1.544 Mbps): cost = 100 / 1.544 ≈ 64.8 → truncated to 64
Wait—1 Gbps gets cost 1? That's the same as 100 Mbps! This is a problem: OSPF cannot distinguish between 100 Mbps and 1 Gbps with default reference. That's why engineers often change the reference bandwidth to a higher value, typically 10000 (10 Gbps) or 100000 (100 Gbps), using the command auto-cost reference-bandwidth under the OSPF process. For example, with reference 10000:
- 100 Mbps: cost = 10000 / 100 = 100
- 1 Gbps: cost = 10000 / 1000 = 10
- 10 Gbps: cost = 10000 / 10000 = 1
Step-by-Step Mechanism at the Packet Level
Interface Bandwidth Discovery: When OSPF is enabled on an interface (via network command or ip ospf), the router reads the interface's configured bandwidth (default is the physical speed for most interfaces, but can be changed with bandwidth command).
Cost Calculation: The router calculates the cost for that interface using the formula above. The cost is stored in the OSPF interface data structure.
LSA Generation: The router includes the cost of each link in its Type 1 Router LSA (Link State Advertisement). The LSA lists all the router's OSPF-enabled interfaces, their IP addresses, and the cost associated with each link.
LSA Flooding: The router floods its LSA to all OSPF neighbors. Every router in the area receives the LSA and stores it in its LSDB (Link State Database).
SPF Calculation: Each router runs the Dijkstra algorithm on its LSDB. The algorithm uses the cost as the metric for each link. It computes the shortest (lowest cost) path to every destination network.
Route Installation: The best path(s) are installed in the routing table (RIB) with the OSPF metric equal to the sum of costs along the path.
Key States, Timers, and Defaults
Reference Bandwidth: Default 100 Mbps. Changed with auto-cost reference-bandwidth <mbps> under router ospf.
Interface Bandwidth: Default is the interface's hardware speed (e.g., 1000000 for GigabitEthernet). Can be changed with bandwidth <kbps> under interface configuration.
Cost Range: 1 to 65535 (16-bit field in LSA). If calculated cost exceeds 65535, it's set to 65535.
Minimum Cost: 1 (even if calculation yields 0).
Cost Override: You can manually set cost per interface with ip ospf cost <value>. This overrides the automatic calculation.
Equal-Cost Multipath (ECMP): OSPF supports up to 4 equal-cost paths by default (configurable with maximum-paths).
IOS CLI Verification Commands with Example Output
#### Show the OSPF cost on an interface:
R1# show ip ospf interface gigabitEthernet 0/0/0
GigabitEthernet0/0/0 is up, line protocol is up
Internet Address 10.0.0.1/24, Area 0
Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 1.1.1.1, Interface address 10.0.0.1
Backup Designated router (ID) 2.2.2.2, Interface address 10.0.0.2
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:05
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
Index 1/1/1, flood queue length 0
Next 0x0(0)/0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 25
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 2.2.2.2 (Backup Designated Router)
Suppress hello for 0 neighbor(s)The line Cost: 1 shows the OSPF cost for this interface.
#### Show the OSPF route with cost:
R1# show ip route ospf
10.0.0.0/8 is variably subnetted, 3 subnets, 2 masks
O 10.0.1.0/24 [110/2] via 10.0.0.2, 00:12:34, GigabitEthernet0/0/0
O 10.0.2.0/24 [110/3] via 10.0.0.2, 00:12:34, GigabitEthernet0/0/0The [110/2] shows the administrative distance (110) and the OSPF metric (cost) of 2 for that route.
#### Show the LSDB to see cost in LSAs:
R1# show ip ospf database router 1.1.1.1
OSPF Router with ID (1.1.1.1) (Process ID 1)
Router Link States (Area 0)
LS age: 120
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 1.1.1.1
Advertising Router: 1.1.1.1
LS Seq Number: 80000005
Checksum: 0x1234
Length: 48
Number of Links: 2
Link connected to: a Transit Network
(Link ID) Designated Router address: 10.0.0.1
(Link Data) Router Interface address: 10.0.0.1
Number of TOS metrics: 0
TOS 0 Metrics: 1
Link connected to: a Stub Network
(Link ID) Network/subnet number: 10.0.1.0
(Link Data) Network Mask: 255.255.255.0
Number of TOS metrics: 0
TOS 0 Metrics: 1The TOS 0 Metrics: 1 shows the cost of that link.
Interaction with Related Protocols
OSPF vs EIGRP: OSPF cost is a simple metric based on bandwidth; EIGRP uses a composite metric (bandwidth, delay, reliability, load, MTU). Both can be used for path selection, but OSPF is a link-state protocol while EIGRP is distance-vector.
OSPF vs Static Routes: Static routes have administrative distance 1 (or 0 for directly connected) and no metric; OSPF routes have AD 110. If both exist, the lower AD wins, not the cost. Cost only matters among OSPF routes.
OSPF Cost and BGP: BGP uses path attributes, not cost. OSPF cost is irrelevant to BGP decision process.
auto-cost reference-bandwidth: This command changes the reference bandwidth globally under the OSPF process. It must be consistent across all routers in the OSPF domain to avoid suboptimal routing.
Understand the Cost Formula
OSPF cost = reference bandwidth / interface bandwidth. Default reference = 100 Mbps. Interface bandwidth is the configured bandwidth of the interface (not necessarily the actual speed). For example, a 10 Mbps Ethernet interface: cost = 100/10 = 10. A 100 Mbps FastEthernet: cost = 1. A 1 Gbps GigabitEthernet: cost = 100/1000 = 0.1 → truncated to 1. Note that with default reference, 100 Mbps and 1 Gbps both get cost 1, which is indistinguishable. This is a common exam trap: they ask 'which path will OSPF choose?' and both are cost 1, so ECMP is used.
Check Current Interface Bandwidth
Use `show interfaces` to see the configured bandwidth. Example: `show interfaces gigabitEthernet 0/0/0` shows 'BW 1000000 Kbit/sec' for 1 Gbps. Use `show ip ospf interface` to see the OSPF cost directly. If you need to change the bandwidth for cost calculation, use `bandwidth <kbps>` under the interface. But be careful: changing bandwidth affects other protocols (like EIGRP) and QoS. A safer method is to set cost manually with `ip ospf cost <value>`.
Change Reference Bandwidth If Needed
If your network has links faster than 100 Mbps, change the reference bandwidth under the OSPF process: `router ospf 1` then `auto-cost reference-bandwidth 1000`. This sets reference to 1000 Mbps (1 Gbps). Then 100 Mbps becomes cost 10, 1 Gbps becomes cost 1, 10 Gbps becomes cost 0.1 → truncated to 1 (still indistinguishable from 1 Gbps). For 10 Gbps, use reference 10000. Remember: all routers in the OSPF domain must use the same reference bandwidth to avoid routing loops or suboptimal paths.
Manually Override Cost on an Interface
To manually set cost on an interface, use `ip ospf cost <1-65535>` under the interface configuration. This overrides the automatic cost calculation. Example: `interface gigabitEthernet 0/0/0` then `ip ospf cost 5`. This is useful for traffic engineering, e.g., to make a high-bandwidth link less preferred for backup purposes. Verify with `show ip ospf interface`.
Verify Cost on Routes
Use `show ip route ospf` to see the OSPF metric (cost) for each route. For example, `O 10.0.1.0/24 [110/2]` means the route has AD 110 and OSPF cost 2. Use `show ip ospf database` to see the cost of each link in the LSDB. This helps in troubleshooting why a particular path is chosen.
Troubleshoot Suboptimal Routing Due to Cost
If traffic takes a slower path, check the OSPF cost on all interfaces along the path. Use `show ip ospf interface brief` to see costs quickly. Compare the total cost of alternate paths. Ensure reference bandwidth is consistent. If manual cost is set on some interfaces, verify it's intentional. Use `debug ip ospf spf` to see SPF calculations (use with caution in production).
Use ECMP with Equal Cost Paths
If two or more paths have the same total cost, OSPF will load balance across them (up to 4 by default, configurable with `maximum-paths`). Verify with `show ip route` – you'll see multiple next hops for the same destination. To change the number of equal-cost paths, use `maximum-paths <number>` under router ospf. This is often tested on the exam.
Scenario 1: Data Center with Mixed Link Speeds
You have a data center with servers connected via 10 Gbps links and older 1 Gbps links. With default OSPF reference bandwidth (100 Mbps), both link types get cost 1, so OSPF sees them as equal cost and load balances. But you want to prefer the 10 Gbps links for primary traffic and use 1 Gbps as backup. Solution: Change reference bandwidth to 10000 (10 Gbps) on all routers. Then 10 Gbps gets cost 1, 1 Gbps gets cost 10. Now OSPF will prefer the 10 Gbps path. If the 10 Gbps link fails, traffic shifts to 1 Gbps. This is a common enterprise scenario. Misconfiguration: if you forget to change reference on one router, it may calculate different costs and cause routing asymmetry or suboptimal paths.
Scenario 2: Traffic Engineering with Manual Cost
You have two WAN links between sites: a primary MPLS circuit (100 Mbps) and a backup DSL (10 Mbps). You want the primary to be preferred. With default reference, 100 Mbps gets cost 1, 10 Mbps gets cost 10. That's fine. But suppose the primary link is a satellite link with high latency but same bandwidth as DSL. Bandwidth alone doesn't reflect latency. You might manually set a higher cost on the satellite link to avoid it. Use ip ospf cost 20 on the satellite interface. This overrides the automatic calculation. In production, manual cost is often used for policy-based routing without changing bandwidth.
Scenario 3: Merging Two Companies with Different Reference Bandwidths
Company A uses reference 100 (default), Company B uses reference 1000. When they merge their OSPF networks, routers will compute different costs for the same links, causing inconsistent path selection. The fix is to standardize the reference bandwidth across the entire OSPF domain. This is a real-world challenge during network mergers. The engineer must plan a maintenance window to update all routers. Failure to do so can cause routing loops or suboptimal routing. Always document the reference bandwidth used in your network.
Performance Considerations
OSPF SPF calculation runs when a link state change occurs. The cost change triggers an LSA update and SPF recalculation. In large networks, frequent cost changes can cause CPU spikes. Use route summarization and stub areas to limit LSDB size. Also, avoid changing costs on many interfaces simultaneously.
Misconfiguration Consequences
Inconsistent reference bandwidth: Different routers compute different costs for the same link, leading to asymmetric routing or suboptimal paths.
Manual cost set too low: A backup link may become preferred over the primary.
Bandwidth command changed incorrectly: Affects other protocols (EIGRP, QoS) and may cause unintended behavior.
Cost set to 0: Not allowed (minimum 1). IOS will reject or default to 1.
Cost exceeding 65535: Truncated to 65535, which may flatten cost differences.
What CCNA 200-301 Tests on OSPF Cost Calculation
Exam objective 3.4: 'Configure and verify OSPF (single area) – cost calculation.' You must be able to:
Calculate the OSPF cost given the interface bandwidth and reference bandwidth.
Identify the path OSPF will choose based on cost.
Understand that changing reference bandwidth affects all OSPF routers in the area.
Know that manual cost overrides automatic calculation.
Interpret show ip ospf interface and show ip route output for cost.
Common Wrong Answers and Why Candidates Choose Them
Wrong: 'OSPF uses hop count like RIP.' Candidates confuse OSPF with RIP. OSPF does not use hop count; it uses cost based on bandwidth.
Wrong: 'The cost is based on the actual speed of the interface, not the configured bandwidth.' Many think OSPF reads the hardware speed. Actually, OSPF uses the bandwidth command value, which defaults to the hardware speed but can be changed. Exam questions may set a different bandwidth to test this.
Wrong: 'If two paths have different costs, OSPF uses the one with the lower sum of bandwidths.' Candidates invert the relationship. Higher bandwidth gives lower cost. They might think a 100 Mbps link (cost 1) is worse than a 10 Mbps link (cost 10).
Wrong: 'Changing reference bandwidth only affects the local router.' This is false. The reference bandwidth is a global setting under the OSPF process; it affects cost calculation for all interfaces on that router. However, if not consistent across routers, paths may be suboptimal. The exam expects you to know that all routers should match.
Specific Values, Defaults, and Command Outputs That Appear on the Exam
Default reference bandwidth: 100 Mbps.
Default cost for FastEthernet (100 Mbps): 1.
Default cost for GigabitEthernet (1000 Mbps): 1 (since 100/1000 = 0.1 -> 1).
Minimum cost: 1.
Maximum cost: 65535.
Command to change reference: auto-cost reference-bandwidth <mbps>.
Command to set manual cost: ip ospf cost <1-65535>.
Show command: show ip ospf interface [interface] to see cost per interface.
Show command: show ip route ospf to see route metrics.
Calculation Traps
Trap: Fractional costs. If calculation yields a fraction, it is truncated (not rounded). E.g., 100/1.544 = 64.8 -> cost 64. Not 65.
Trap: Cost 0. If reference bandwidth is less than interface bandwidth, cost could be <1. But IOS enforces minimum cost 1. E.g., reference 100, 10 Gbps: 100/10000 = 0.01 -> cost 1.
Trap: Bandwidth in kbps vs bps. The bandwidth command takes kbps. Reference bandwidth is in Mbps. Ensure units: convert if needed. Exam may give bandwidth in Mbps and reference in Mbps.
Trap: Multiple paths with same cost. OSPF will load balance (ECMP). If paths have different costs, only the lowest cost path(s) are used.
Decision Rule for Scenario Questions
Identify all interfaces on the path from source to destination.
Determine the cost of each interface (given or calculate).
Sum the costs along each path.
Choose the path with the lowest total cost. If tie, ECMP is used.
Remember that manual cost (ip ospf cost) overrides automatic calculation.
If reference bandwidth is changed, use that value in calculations.
Example: Router A connects to Router B via 100 Mbps (cost 1) and to Router C via 10 Mbps (cost 10). Router B connects to destination with cost 5, Router C with cost 1. Path A-B-dest: 1+5=6. Path A-C-dest: 10+1=11. OSPF chooses A-B-dest (lower cost).
OSPF cost = reference bandwidth / interface bandwidth (default reference = 100 Mbps).
Cost is an integer; fractional results are truncated (minimum 1).
Manual cost with `ip ospf cost <value>` overrides automatic calculation.
Change reference bandwidth with `auto-cost reference-bandwidth <mbps>` under router ospf; must be consistent across all routers.
Use `show ip ospf interface` to see cost per interface; `show ip route ospf` to see route metric.
Equal-cost paths (same total cost) are load-balanced (ECMP) up to 4 paths by default.
The `bandwidth` command sets the value used for cost calculation, not the actual speed.
These come up on the exam all the time. Here's how to tell them apart.
OSPF Cost (Default Reference 100 Mbps)
100 Mbps -> cost 1
1 Gbps -> cost 1 (indistinguishable from 100 Mbps)
10 Gbps -> cost 1
T1 (1.544 Mbps) -> cost 64
Manual cost can still override
OSPF Cost (Reference 1000 Mbps)
100 Mbps -> cost 10
1 Gbps -> cost 1
10 Gbps -> cost 0.1 -> cost 1 (still indistinguishable from 1 Gbps)
T1 -> cost 647
Manual cost can still override
Mistake
OSPF cost is based on hop count.
Correct
OSPF cost is based on bandwidth (reference bandwidth / interface bandwidth). Hop count is used by RIP.
Candidates often confuse link-state with distance-vector protocols.
Mistake
OSPF uses the actual physical speed of the interface for cost calculation.
Correct
OSPF uses the configured bandwidth (set by `bandwidth` command), which defaults to physical speed but can be changed.
Many assume OSPF reads hardware registers; actually it reads the software bandwidth parameter.
Mistake
Changing the reference bandwidth only affects the local router's cost calculations.
Correct
Changing reference bandwidth affects all OSPF routers in the domain because cost is advertised in LSAs; inconsistent reference leads to suboptimal routing.
Candidates think it's a local parameter, but cost is shared in LSAs.
Mistake
A higher bandwidth interface always has a lower cost than a lower bandwidth interface.
Correct
True only if reference bandwidth is the same. But manual cost can override. Also, if reference bandwidth is changed, the relationship holds but values differ.
Candidates forget about manual override and reference changes.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
With default reference bandwidth of 100 Mbps, the cost for a GigabitEthernet (1000 Mbps) is 100/1000 = 0.1, which is truncated to 1. So default cost is 1. This is the same as FastEthernet (100 Mbps). To differentiate, you must change the reference bandwidth to a higher value, e.g., 10000 (10 Gbps) or 100000 (100 Gbps).
Use the command `ip ospf cost <1-65535>` under the interface configuration mode. This overrides the automatic cost calculation based on bandwidth. For example: `interface GigabitEthernet0/0/0` then `ip ospf cost 10`. Verify with `show ip ospf interface GigabitEthernet0/0/0`.
You cannot set it to 0; the command `auto-cost reference-bandwidth` requires a value from 1 to 4294967. If you try 0, IOS will reject it. The minimum is 1 Mbps, which would make all costs very high (e.g., 100 Mbps link cost = 1/100 = 0.01 -> cost 1).
The cost for a route is the sum of the costs of all outgoing interfaces along the path from the source to the destination. Each router adds the cost of the interface it uses to forward the packet. So it's a cumulative metric, not just the first hop.
Yes, you can manually set different costs on interfaces with `ip ospf cost`. For example, you have two 1 Gbps links to different ISPs; you can set cost 10 on one and 20 on the other to prefer the first. This is a common traffic engineering technique.
The reference bandwidth provides a scaling factor so that cost is a manageable integer. Without it, costs would be very small for high-speed links (e.g., 0.001). The reference bandwidth is chosen to represent the fastest link in the network, so that the fastest link gets cost 1 and slower links get higher costs.
The cost field in the LSA is 16 bits, so maximum value is 65535. If the calculation yields a value greater than 65535, it is truncated to 65535. This is rare in modern networks but could happen with very low bandwidth links (e.g., 56 kbps with reference 10000 gives cost 178571, truncated to 65535).
You've just covered OSPF Cost Calculation — now see how well it sticks with free CCNA 200-301 practice questions. Full explanations included, no account needed.
Done with this chapter?