OSPF Cost – OSPF Routing Protocol Metric Explained

OSPF is a dynamic routing protocol that uses Link State Routing (LSR) algorithm. It is one of the Interior Gateway Protocols (IGP) that operates within a single autonomous system. OSPF cost is its metric (the unit used by a router to make routing decisions).

OSPF executes a process using an algorithm developed by Edsger Dijkstra to find the shortest route to the advertising node. The router will then use this output as a candidate path for its routing table. For the OSPF to accurately represent topology, each link of the network must have an associated OSPF cost.

OSPF relies on costs that are inversely proportional to the bandwidth of the link. Therefore, higher bandwidth links are preferred to lower ones. The Cost formula is reference bandwidth divided by interface bandwidth. The default reference bandwidth of 100 Mbps is used for OSPF cost calculation.

For example, if we have an Ethernet interface (10 Mbps), the OSPF path cost value is 100 Mbps / 10 Mbps = 10.

 

OSPF Default Interface Cost Values

Here are the default Cost values for each interface type:

Gigabit Ethernet Interface (1 Gbps) 1
Fast Ethernet Interface (100 Mbps) 1
Ethernet Interface (10 Mbps) 10
DS1 (1.544 Mbps) 64
DSL (768 Kbps) 133

 

Cisco routers have three methods to change the OSPF interface cost:

1. By directly using the interface command ‘ip ospf cost <1-65535>’

Router#conf t
Router(config)#int gi0/0/0
Router(config-if)#ip ospf cost <1-65535>

We can verify this by using the ‘show ip ospf interface’ command.

 

2. Changing the ‘interface bandwidth’ setting (in kilobits), which changes the calculated value.

Router#conf t
Router(config)#int gi0/0/0
Router(config-if)#bandwidth <1-10000000>

 

3. Changing the OSPF reference bandwidth setting, which changes the calculated value.

Router#conf t
Router(config)#router ospf 1
Router(config-router)#auto-cost reference-bandwidth 100000

 

NOTE
Please ensure reference bandwidth is the same across all routers. The reference bandwidth command warns you that you need to make the same change across all your routers. This will allow all routers to make their calculations on the same information.

 

ospf cost
In our example, R1, R2, and R3 are running OSPF. From R1’s perspective, it installed both paths in its routing table since the links towards R2 and R3 have equal Costs of 1.

O       1.1.1.0/24 [110/2] via 10.2.2.2, 00:00:03, GigabitEthernet0/0
                   [110/2] via 10.3.3.2, 00:00:03, GigabitEthernet0/1
GigabitEthernet0/0 is up, line protocol is up
  Internet address is 10.2.2.1/30, Area 0
  Process ID 1, Router ID 10.1.1.1, Network Type BROADCAST, Cost: 1

GigabitEthernet0/1 is up, line protocol is up
  Internet address is 10.3.3.1/30, Area 0
  Process ID 1, Router ID 10.1.1.1, Network Type BROADCAST, Cost: 1

 

Let’s change R1 Gi0/1’s cost to 20.

R1#conf t
R1(config)#int gi0/1
R1(config-if)#ip ospf cost 20

 

For verification, let’s check the cost and the routing table again.

R1#sh ip ospf interface 

GigabitEthernet0/0 is up, line protocol is up
  Internet address is 10.2.2.1/30, Area 0
  Process ID 1, Router ID 10.1.1.1, Network Type BROADCAST, Cost: 1


GigabitEthernet0/1 is up, line protocol is up
  Internet address is 10.3.3.1/30, Area 0
  Process ID 1, Router ID 10.1.1.1, Network Type BROADCAST, Cost: 20

 

Lower cost wins, and R3’s route was removed from our routing table.

O       1.1.1.0/24 [110/2] via 10.2.2.2, 00:00:00, GigabitEthernet0/0

Download our Free CCNA Study Guide PDF for complete notes on all the CCNA 200-301 exam topics in one book.

We recommend the Cisco CCNA Gold Bootcamp as your main CCNA training course. It’s the highest rated Cisco course online with an average rating of 4.8 from over 30,000 public reviews and is the gold standard in CCNA training: