Back to OSPF Guide OSPF metrics

OSPF Cost Calculation and Path Selection

OSPF selects shortest paths using interface cost. Understanding cost helps explain equal-cost load balancing, reference bandwidth problems and why a higher-bandwidth link should normally win.

Cost Bandwidth SPF ECMP Reference Bandwidth

OSPF Cost at a Glance

OSPF adds the outgoing interface costs along a path. The path with the lowest total cost wins. If two paths have the same total cost, OSPF can install both and share traffic across them.

MetricCost
Best pathLowest total
Default reference100 Mbps
Equal totalsECMP
Choose your track: Read sections 1–3 for the core idea. Continue through sections 4–7 when you are ready to configure, verify, and troubleshoot a lab.

In This Lesson

  1. Understand the Cost Formula
  2. Choose a Useful Reference Bandwidth
  3. See How OSPF Selects a Path
  4. Configure Reference Bandwidth and Manual Cost
  5. Read the Verification Output
  6. Troubleshoot Unexpected Path Choices
  7. Guided Practice Lab
  8. Frequently Asked Questions

1. Understand the Cost Formula

On Cisco IOS, the automatic interface cost comes from two values: the OSPF reference bandwidth and the interface bandwidth. Both values must use the same unit before you divide them.

Cisco OSPF cost formula
Cost = Reference bandwidth ÷ Interface bandwidth

Cisco IOS uses an integer cost and does not use an automatic interface cost below 1. Lower cost is better.

Worked example with the default reference

The default reference bandwidth is 100 Mbps. A 10 Mbps link has a cost of 10 because 100 ÷ 10 = 10. A 100 Mbps link has a cost of 1 because 100 ÷ 100 = 1.

Interface speedCalculationAutomatic costMeaning
10 Mbps100 ÷ 1010Less preferred than FastEthernet
100 Mbps100 ÷ 1001Preferred over a 10 Mbps link
1 Gbps100 ÷ 10001Result is limited to the minimum cost
10 Gbps100 ÷ 100001Looks equal to 1 Gbps with this reference

2. Choose a Useful Reference Bandwidth

The old 100 Mbps default cannot show the difference between modern high-speed links. A 1 Gbps link and a 10 Gbps link both receive cost 1. Raising the reference bandwidth restores useful separation.

Link speed100 Mbps reference100,000 Mbps reference
100 Mbps11000
1 Gbps1100
10 Gbps110
100 Gbps11
Design rule: Use the same reference bandwidth on every OSPF router. The value does not need to match a link that exists today; it should be high enough to describe your fastest current or planned link.

3. See How OSPF Selects a Path

R1 has two ways to reach R4's loopback. OSPF adds the outgoing costs along each path. The loopback contributes cost 1 to both choices, so R1 still prefers the path with the lower transit cost.

Selected path Destination loopback cost: 1
OSPF selects R1 → R2 → R4 because total cost 21 is lower than 36. If both totals were 21, OSPF could use equal-cost multipath.

4. Configure Reference Bandwidth and Manual Cost

Reference bandwidth changes the automatic cost calculation for all OSPF-enabled interfaces on a router. Manual cost changes one interface and overrides the automatically calculated value.

Set a 100 Gbps reference

R1# configure terminal
R1(config)# router ospf 1
R1(config-router)# auto-cost reference-bandwidth 100000

% OSPF: Reference bandwidth is changed.

Set one manual interface cost

R1# configure terminal
R1(config)# interface GigabitEthernet0/1
R1(config-if)# ip ospf cost 25
R1(config-if)# end
  • Use reference bandwidth when interface speed should drive the metric across the whole OSPF design.
  • Use manual cost when the design requires a specific primary or backup path independent of reported bandwidth.
  • Do not use the bandwidth command only to tune OSPF. It can affect other routing protocols, QoS, monitoring, and interface statistics. Use ip ospf cost when only OSPF should change.

5. Read the Verification Output

Verify the local interface cost and the complete route metric together. The interface output explains one link. The routing table shows the accumulated cost to the destination.

Check interface and reference values

R1# show ip ospf interface brief
Interface  PID  Area  Cost  State
Gi0/0      1    0     10    P2P
Gi0/1      1    0     25    P2P

R1# show ip ospf | include Reference
 Reference bandwidth unit is 100000 mbps

Check the selected route

R1# show ip route ospf 10.4.4.4
Routing entry for 10.4.4.4/32
  Known via "ospf 1", distance 110, metric 21
  * 192.168.12.2, via GigabitEthernet0/0
Read it carefully: [110/21] in a short OSPF route entry means administrative distance 110 and total OSPF metric 21. It does not mean two separate interface costs.

6. Troubleshoot Unexpected Path Choices

Do not change the metric immediately. First prove which value is different from the design.

  • Confirm the next hop. Use show ip route ospf and record the selected next hop and total metric.
  • Check every outgoing interface in the path. One manual ip ospf cost can override the bandwidth calculation.
  • Compare reference bandwidth. A router using a different value can calculate different local interface costs.
  • Check topology and LSAs. A failed link or missing LSA can remove the expected path before cost comparison happens.
  • Look for equal totals. Multiple next hops are correct when ECMP is enabled and the complete path costs match.

7. Guided Practice Lab

Build a four-router topology with the two paths shown above. Capture the baseline before each change so you can explain why SPF changed its decision.

Task 1: Prove the Lower-Cost Path

  1. Configure all links in OSPF Area 0.
  2. Set the upper path costs to 10 and 10.
  3. Set the lower path costs to 5 and 30.
  4. Check R1's route to R4's loopback.

Expected result: R1 selects the upper path through R2 with total cost 21, including R4's loopback cost 1.

Task 2: Create Equal-Cost Paths

  1. Change the R3-to-R4 outgoing cost from 30 to 15.
  2. Calculate both totals before checking the router.
  3. Run show ip route ospf on R1.

Expected result: Both paths total 21, so R1 can install two next hops for the destination.

Task 3: Test Reference Bandwidth

  1. Remove the manual costs from the lab interfaces.
  2. Record the automatic costs with the default reference.
  3. Set auto-cost reference-bandwidth 100000 on every router.
  4. Compare interface costs and the selected route again.

Expected result: Faster links receive meaningfully lower costs, and every router reports the same reference bandwidth.

8. Frequently Asked Questions

Does lower OSPF cost mean a better path?

Yes. OSPF prefers the path with the lowest accumulated cost from the local router to the destination.

Why do 1 Gbps and 10 Gbps links both show cost 1?

The default 100 Mbps reference bandwidth is too low to distinguish them. Raise the reference bandwidth consistently across all OSPF routers.

Does OSPF add the cost of every interface?

OSPF adds outgoing interface costs along the path from the calculating router. The route metric is the total, not just the cost of the local interface.

Does manual OSPF cost override automatic cost?

Yes. ip ospf cost sets the value OSPF uses on that interface instead of the bandwidth-based calculation.

What happens when two OSPF paths have the same cost?

OSPF can install multiple equal-cost next hops and share traffic across them, subject to the platform's equal-cost multipath limit.