The OSPF Cost Formula (Cisco Default)
Cost = Reference Bandwidth / Interface Bandwidth
Default reference bandwidth: 100 Mbps (100,000,000 bps)
Examples:
| Interface Type | Bandwidth | Cost Calculation | Cost |
|---|---|---|---|
| Serial (T1) | 1.544 Mbps | 100 / 1.544 | 64 |
| Ethernet | 10 Mbps | 100 / 10 | 10 |
| FastEthernet | 100 Mbps | 100 / 100 | 1 |
| GigabitEthernet | 1000 Mbps | 100 / 1000 | 1 |
| 10 GigabitEthernet | 10,000 Mbps | 100 / 10,000 | 1 |
The Problem with Default Cost
Notice anything wrong with the table above?
❌ FastEthernet (100 Mbps) has the same cost as 10 GigabitEthernet (10,000 Mbps).
This is because the default reference bandwidth is 100 Mbps. Any interface faster than 100 Mbps gets a cost of 1 (the minimum).
Real-world impact:
OSPF can't tell the difference between a 100 Mbps link and a 100 Gbps link. Both have cost 1, so OSPF might pick the slower path during equal-cost load balancing.
Fixing the Cost Problem: Change Reference Bandwidth
Solution:
Increase the reference bandwidth to a value higher than your fastest link.
Best practice:
Set reference bandwidth to 10,000 Mbps (10 Gbps) or 100,000 Mbps (100 Gbps) depending on your network.
Configuration:
Router(config)# router ospf 1
Router(config-router)# auto-cost reference-bandwidth 10000
Units: Mbps
Result with 10,000 Mbps reference bandwidth:
| Interface Type | Bandwidth | Cost Calculation | Cost |
|---|---|---|---|
| FastEthernet | 100 Mbps | 10,000 / 100 | 100 |
| GigabitEthernet | 1,000 Mbps | 10,000 / 1,000 | 10 |
| 10 GigabitEthernet | 10,000 Mbps | 10,000 / 10,000 | 1 |
| 100 GigabitEthernet | 100,000 Mbps | 10,000 / 100,000 | 1 (still hits minimum) |
Now OSPF can differentiate between FastEthernet (cost 100) and GigabitEthernet (cost 10).
Important: Configure on All Routers
⚠️ Critical:
You must configure the same reference bandwidth on every router in the OSPF domain. Otherwise, routers will calculate costs differently, leading to suboptimal routing.
Check current reference bandwidth:
Router# show ip ospf | include Reference
Reference bandwidth unit is 100 mbps
Set reference bandwidth:
Router(config-router)# auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
Please ensure reference bandwidth is consistent across all routers.
Manually Setting OSPF Cost
Sometimes you want to override the automatic cost calculation.
Use cases:
- Force traffic over a preferred path
- Influence routing during maintenance
- Work around bandwidth mismatches (e.g., interface shows 1 Gbps but actual WAN circuit is 100 Mbps)
Configuration (per interface):
Router(config)# interface gi0/0
Router(config-if)# ip ospf cost 50
Verification:
Router# show ip ospf interface gi0/0
GigabitEthernet0/0 is up, line protocol is up
Internet Address 10.0.0.1/30, Area 0
Process ID 1, Router ID 10.0.0.1, Network Type POINT_TO_POINT, Cost: 50
Priority:
Manual cost (ip ospf cost) overrides the auto-calculated cost.
How OSPF Selects the Best Path
OSPF adds up the outgoing interface costs along each path and picks the one with the lowest total.
Example Topology:
[R1] ---(cost 10)--- [R2] ---(cost 10)--- [R3]
| |
+--------(cost 100)-------------------------+
Paths from R1 to R3:
-
Path 1: R1 → R2 → R3
Total cost = 10 (R1→R2) + 10 (R2→R3) = 20 -
Path 2: R1 → R3 (direct)
Total cost = 100
Winner: Path 1 (cost 20)
Result:
R1 installs the route via R2 in its routing table.
Equal-Cost Multipath (ECMP)
If two paths have the same total cost, OSPF installs both and load-balances traffic across them.
Example:
[R1] ---(cost 10)--- [R2] ---(cost 10)--- [R4]
| |
+---(cost 10)--- [R3] ---(cost 10)--------+
Paths from R1 to R4:
- Path 1: R1 → R2 → R4 = 20
- Path 2: R1 → R3 → R4 = 20
Result:
Both paths are installed. Traffic load-balances across them.
Default ECMP limit (Cisco): 4 paths
Maximum: 32 (configurable with maximum-paths)
Configuration:
Router(config-router)# maximum-paths 8
Verifying OSPF Cost
Check Interface Cost
Router# show ip ospf interface gi0/0
GigabitEthernet0/0 is up, line protocol is up
Internet Address 10.0.0.1/30, Area 0
Process ID 1, Router ID 10.0.0.1, Network Type POINT_TO_POINT, Cost: 10
Key field: Cost: 10
Check Route Cost
Router# show ip route ospf
O 192.168.10.0/24 [110/20] via 10.0.0.2, 00:05:23, GigabitEthernet0/0
Format: [AD/Metric]
- 110 = Administrative Distance (OSPF default)
- 20 = Total OSPF cost to reach 192.168.10.0/24
Check Cost in OSPF Database
Router# show ip ospf database router 10.0.0.1
OSPF Router with ID (10.0.0.1) (Process ID 1)
Router Link States (Area 0)
LS age: 123
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 10.0.0.1
Advertising Router: 10.0.0.1
LS Seq Number: 80000005
Checksum: 0xABCD
Length: 60
Number of Links: 2
Link connected to: another Router (point-to-point)
(Link ID) Neighbor Router ID: 10.0.0.2
(Link Data) Router Interface address: 10.0.0.1
Number of TOS metrics: 0
TOS 0 Metrics: 10
Key field: TOS 0 Metrics: 10 (cost of this link)
Practical Cost Tuning Examples
Example 1: Prefer Primary Link Over Backup
Scenario:
R1 has two links to R2:
- Primary link: 1 Gbps fiber
- Backup link: 100 Mbps copper
Both show as GigabitEthernet interfaces (cost 1 with default settings). You want to prefer the fiber link.
Solution:
Increase cost on the backup link:
Primary link (Gi0/0):
Router(config-if)# ip ospf cost 1
Backup link (Gi0/1):
Router(config-if)# ip ospf cost 100
Result:
OSPF always prefers Gi0/0 (cost 1). If it fails, OSPF fails over to Gi0/1 (cost 100).
Example 2: Balance Traffic Across Two Links
Scenario:
R1 has two equal 10 Gbps links to R2.
Configuration:
Ensure both links have the same cost:
Router(config)# interface range gi0/0 - 1
Router(config-if-range)# ip ospf cost 1
Result:
OSPF load-balances traffic across both links (ECMP).
Example 3: Force Traffic via Specific Path
Scenario:
You have three routers:
- R1 ↔ R2 (cost 10)
- R2 ↔ R3 (cost 10)
- R1 ↔ R3 (cost 10, direct link)
Normally, R1 would prefer the direct link to R3 (cost 10) over the path through R2 (cost 20). But you want traffic to go via R2 for monitoring purposes.
Solution:
Increase cost on the direct link:
R1 (direct link to R3):
Router(config)# interface gi0/2
Router(config-if)# ip ospf cost 50
Result:
- Direct path: cost 50
- Via R2: cost 20 (10 + 10)
- OSPF prefers the R2 path
Cost and Bandwidth Mismatch
Problem:
Your ISP gives you a 100 Mbps circuit, but it's delivered over a GigabitEthernet handoff. The interface shows 1000 Mbps, so OSPF calculates cost based on 1 Gbps, not the actual 100 Mbps.
Result:
OSPF thinks the link is faster than it really is.
Solution 1: Manually set bandwidth
Router(config-if)# bandwidth 100000
(This changes OSPF's cost calculation but doesn't change actual speed.)
Solution 2: Manually set OSPF cost
Router(config-if)# ip ospf cost 100
Common Cost Mistakes
Mistake 1: Not Changing Reference Bandwidth
Problem:
Using default reference bandwidth (100 Mbps) in a network with GigabitEthernet and 10 GigabitEthernet.
Impact:
All links faster than 100 Mbps get cost 1. OSPF can't differentiate between them.
Fix:
Router(config-router)# auto-cost reference-bandwidth 10000
Mistake 2: Inconsistent Reference Bandwidth
Problem:
Some routers use reference bandwidth 10,000, others use 100.
Impact:
Routers calculate costs differently. Suboptimal routing.
Fix:
Standardize reference bandwidth across all routers.
Mistake 3: Forgetting Outgoing Interface Cost
Problem:
An engineer looks at a path and forgets to count the cost of the outgoing interface on the local router.
Example:
R1 → R2 → R3
Cost from R1's perspective:
- Cost to reach R2 = cost of R1's outgoing interface to R2 (e.g., 10)
- Cost to reach R3 = cost of R1's outgoing interface (10) + cost of R2's outgoing interface to R3 (10) = 20
The cost of R1's incoming interface is not counted.
OSPF Cost vs Administrative Distance
Confused? These are different:
- Administrative Distance (AD): Used to compare routes from different protocols (OSPF = 110, EIGRP = 90, etc.)
- OSPF Cost (Metric): Used to compare OSPF routes to each other
Example:
Router# show ip route
O 192.168.10.0/24 [110/20] via 10.0.0.2, GigabitEthernet0/0
- 110 = AD (trust level compared to other protocols)
- 20 = OSPF cost (used to pick best OSPF path)
Summary: OSPF Cost Checklist
Now you know:
✅ OSPF cost formula: Reference Bandwidth / Interface Bandwidth
✅ Default reference bandwidth: 100 Mbps (too low for modern networks)
✅ How to fix it: auto-cost reference-bandwidth 10000
✅ Manual cost override: ip ospf cost [value]
✅ Path selection: Lowest total cost wins
✅ ECMP: Equal-cost paths load-balance
✅ Common mistakes: Inconsistent reference bandwidth, ignoring outgoing cost
Next Step:
Now you understand how OSPF picks paths. But how do you identify each router? That's where Router ID comes in. Read OSPF Router ID Configuration Guide next.
Screenshot Suggestions:
- Topology diagram showing cost calculation along two paths
show ip ospf interfaceoutput highlighting Cost fieldshow ip route ospfoutput with [AD/Metric] annotated- Side-by-side comparison: default reference BW vs adjusted reference BW
Internal Links:
- ← OSPF Key Terms and Concepts (Article 2)
- → OSPF Router ID Configuration Guide (Article 7)
- → OSPF Route Summarization (Article 28)
- → How to Configure Single-Area OSPF (Article 8)