A routing protocol must be able to identify the best path when several routes to the same network exist. This parameter or measurement is called metric. Each dynamic routing protocol, including OSPF, comes with its own formula for calculating route metrics in order to make the best routing choices. In fact, the OSPF metric differs from the metrics of the RIP and EIGRP routing protocols.

A Route metric relies on several parameters such as hop count, bandwidth, load, interface cost, delay, reliability, or a mix of these factors. For instance, the OSPF metric is calculated based on the OSPF costs of interfaces.

Besides, EIGRP uses a sophisticated formula that relies on bandwidth, delay, load, and reliability for route metric calculation, while OSPF and RIP consider the cost (based on interface bandwidth) and hop count as metric parameters, respectively.

Before we continue, here are the network diagram and the router configurations I will use in the rest of this guide.

Router R1

Router(config)# hostname R1
R1(config)# 
R1(config)# interface F0/0
R1(config-if)# ip address 10.0.13.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# 
R1(config-if)# interface s1/0
R1(config-if)# ip address 10.0.12.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# 
R1(config-if)# router ospf 1
R1(config-router)# network 10.0.12.1 0.0.0.0 area 0
R1(config-router)# network 10.0.13.1 0.0.0.0 area 0

Router R2

Router(config)# hostname R2
R2(config)# 
R2(config)# interface F0/0
R2(config-if)# ip address 10.0.2.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# 
R2(config-if)# interface s1/0
R2(config-if)# ip address 10.0.12.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# 
R2(config-if)# router ospf 1
R2(config-router)# network 10.0.2.2 0.0.0.0 area 0
R2(config-router)# network 10.0.12.2 0.0.0.0 area 0

Router R3

Router(config)# hostname R3
R3(config)# 
R3(config)# interface F0/0
R3(config-if)# ip address 10.0.13.3 255.255.255.0
R3(config-if)# no shutdown
R3(config-if)# 
R3(config-if)# router ospf 1
R3(config-router)# network 10.0.13.3 0.0.0.0 area 0

The OSPF metric for a particular route on a router is the sum of the OSPF costs of all outgoing interfaces IP packets must pass through to go from the router to reach the route’s corresponding destination. For example, the metric of the 10.0.2.0/24 on router R3 is equal to the OSPF costs of R3’s F0/0, R1’s S1/0, and R2’s F0/0 interfaces.

Let’s determine router R2’s OSPF metric for its connected subnet 10.0.2.0/24.

Since IPv4 packets sent to subnet 10.0.2.0/24 must exit the F0/0 interface only, the OSPF metric of the route 10.0.2.0/24 is the cost of the F0/0 interface, which is equal to the OSPF reference bandwidth divided by the bandwidth of the interface.

Note that the faster the interface ( greater bandwidth), the smaller the OSPF cost. It is possible to find the value of the OSPF reference bandwidth using the show ip ospf command. Example 1 clearly indicates that the reference bandwidth is 100 Mbps, the default value. You can adjust that value using the auto-cost reference-bandwidth command in router configuration mode.

R2# show ip ospf
 Routing Process "ospf 1" with ID 10.0.12.2
 Start time: 00:04:25.804, Time elapsed: 00:03:50.188
 Supports only single TOS(TOS0) routes
 Supports opaque LSA
 Supports Link-local Signaling (LLS)
 Supports area transit capability
 Event-log enabled, Maximum number of events: 1000, Mode: cyclic
 Router is not originating router-LSAs with maximum metric
 Initial SPF schedule delay 5000 msecs
 Minimum hold time between two consecutive SPFs 10000 msecs
 Maximum wait time between two consecutive SPFs 10000 msecs
 Incremental-SPF disabled
 Minimum LSA interval 5 secs
 Minimum LSA arrival 1000 msecs
 LSA group pacing timer 240 secs
 Interface flood pacing timer 33 msecs
 Retransmission pacing timer 66 msecs
 Number of external LSA 0. Checksum Sum 0x000000
 Number of opaque AS LSA 0. Checksum Sum 0x000000
 Number of DCbitless external and opaque AS LSA 0
 Number of DoNotAge external and opaque AS LSA 0
 Number of areas in this router is 1. 1 normal 0 stub 0 nssa
 Number of areas transit capable is 0
 External flood list length 0
 IETF NSF helper support enabled
 Cisco NSF helper support enabled
 Reference bandwidth unit is 100 mbps
    Area BACKBONE(0)
        Number of interfaces in this area is 2
        Area has no authentication
        SPF algorithm last executed 00:02:59.016 ago
        SPF algorithm executed 4 times
        Area ranges are
        Number of LSA 4. Checksum Sum 0x02C6D4
        Number of opaque link LSA 0. Checksum Sum 0x000000
        Number of DCbitless LSA 0
        Number of indication LSA 0
        Number of DoNotAge LSA 0
        Flood list length 0

Example 1 – Displaying the OSPF reference bandwidth
Besides, you can check the bandwidth of the F0/0 interface using the show interface F0/0 statement, as shown in Example 2.

R2# show interfaces fastEthernet 0/0
FastEthernet0/0 is up, line protocol is up 
  Hardware is i82543 (Livengood), address is ca02.06a3.0008 (bia ca02.06a3.0008)
  Internet address is 10.0.2.2/24
  MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec, 

omitted output

Example 2 – Displaying interface bandwidth

Since the bandwidth is 100000 Kbps or 100Mbps, the OSPF cost of the interface is 100Mbps/100Mbps = 1, as mentioned in the show ip ospf interface command (Example 3).

R2# show ip ospf interface fastEthernet 0/0
FastEthernet0/0 is up, line protocol is up 
  Internet Address 10.0.2.2/24, Area 0 
  Process ID 1, Router ID 10.0.12.2, Network Type BROADCAST, Cost: 1


omitted output

Example 3 – OSPF configuration of router R2’s F0/0 interface

Now, let’s compute the OSPF metric of the path that starts on router R1, and ends on router R2 to reach subnet 10.0.2.0/24. IP packets forwarded by R1 and destined to subnet 10.0.2.0/24 exit router R1’s Serial 1/0 interface, then pass through router R2’s F0/0 interface. Therefore, the OSPF metric of the route in question is 65, which is the sum of the OSPF costs of those interfaces.

Note that the costs of R1’s Serial 1/0 and R2’s FastEthernet 0/0 interfaces are 64 and 1, respectively (Examples 3 and 4). As shown in Example 5, S1/0’s bandwidth is 1.544Mbps, and thus the cost would be 100Mbps/1.544Kbps = 64.766839378. However, the real OSPF cost of interface Serial 1/0 is the integer part of the resulting value, which is 64 (Example 4).

R1#  show ip ospf interface serial 1/0
Serial1/0 is up, line protocol is up 
  Internet Address 10.0.12.1/24, Area 0 
  Process ID 1, Router ID 10.0.13.1, Network Type POINT_TO_POINT, Cost: 64



omitted output

Example 4 – OSPF configuration of router R1’s S1/0 interface

R1#  show interfaces serial 1/0
Serial1/0 is up, line protocol is up 
  Hardware is M4T
  Internet address is 10.0.12.1/24
  MTU 1500 bytes, BW 1544 Kbit/sec, DLY 20000 usec,



omitted output

Example 5 – OSPF configuration of router R1’s S1/0 interface

Now, let’s verify our analysis using the show ip route command.

R1# show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, + - replicated route

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O        10.0.2.0/24 [110/65] via 10.0.12.2, 00:14:06, Serial1/0
C        10.0.12.0/24 is directly connected, Serial1/0
L        10.0.12.1/32 is directly connected, Serial1/0
C        10.0.13.0/24 is directly connected, FastEthernet0/0
L        10.0.13.1/32 is directly connected, FastEthernet0/0

Example 6 – Displaying R1’s routing table
In fact, Example 6 shows that the OSPF metric of R1’s route leading to subnet 10.0.2.0/24 is 65. Without a doubt, the routing table includes several elements, and the metric is one of them. It is listed right after the administrative distance, and those values are separated by a forward slash (/).

To sum up, the OSPF metric of a specific path is the sum of OSPF costs for all outgoing interfaces in that path from the beginning to the end. If OSPF has two routes to the same destination network, the route with the lowest metric wins. Otherwise, OSPF performs equal load balancing.

Finally, the total OSPF cost of the path from router R3 to subnet 10.0.2.0/24 is 66 because outgoing interfaces, in that path, are R3’s F0/0, R1’s S1/0, and R2’s F0/0 interfaces, and their costs are 1,64, and 1, respectively.

Tuning The OSPF Metric on Cisco IOS by Modifying The OSPF Cost

To adjust the OSPF metric of a route, you need to change the OSPF cost of one or more interfaces that influence the metric value. To change the OSPF cost of an interface, use the ip ospf cost, bandwidth, or auto-cost reference bandwidth commands. To learn more about how to adjust the OSPF cost of an interface, read the post: OSPF Cost.

Related Lessons to OSPF Metric

Mohamed Ouamer is a computer science teacher and a self-published author. He taught networking technologies and programming for more than fifteen years. While he loves to share knowledge and write, Mohamed's best passions include spending time with his family, visiting his parents, and learning new things.