Back to Posts

OSPF Metrics Explained: Cost Calculation, Path Selection, and Cisco IOS Commands

OSPF Metrics Explained: Cost Calculation, Path Selection, and Cisco IOS Commands

Home > Cisco > OSPF > OSPF Metrics and Cost Calculation

OSPF uses a metric called cost to determine the best path to a destination. Unlike protocols that use hop count or a composite calculation involving several interface characteristics, OSPF primarily derives its default interface cost from bandwidth. The route with the lowest accumulated OSPF cost is normally preferred when comparing otherwise equivalent OSPF paths.

Understanding OSPF metrics is especially important on modern Cisco networks because the traditional OSPF reference bandwidth is only 100 Mbps. Without adjusting the reference bandwidth, Fast Ethernet, Gigabit Ethernet, 10 Gigabit Ethernet, and faster interfaces can all appear to OSPF as having the same cost.

This guide explains how Cisco OSPF cost is calculated, how OSPF selects routes, how reference bandwidth affects the metric, how to configure manual costs, and which Cisco IOS commands can be used to verify and troubleshoot OSPF path selection.

What Is the OSPF Metric?

The OSPF metric is called cost. Every OSPF-enabled interface has a cost, and OSPF adds the costs of interfaces along a path to calculate the total metric to a destination.

The fundamental rule is simple:

Lower OSPF cost = more preferred path.

For example, assume a router has two valid intra-area paths to the same network:

Path Total OSPF Cost Result
R1 → R2 → Destination 20 Preferred
R1 → R3 → Destination 40 Not preferred

Because the first path has the lower accumulated cost, OSPF installs it as the preferred route, assuming both routes are the same OSPF path type.

OSPF Cost Formula

Cisco IOS calculates the default OSPF interface cost using the following basic formula:

OSPF Cost = Reference Bandwidth / Interface Bandwidth

The traditional default reference bandwidth is:

100 Mbps

This produces familiar default costs such as:

Interface Bandwidth Calculation Typical Default OSPF Cost
10 Mbps 100 / 10 10
100 Mbps 100 / 100 1
1 Gbps 100 / 1000 1
10 Gbps 100 / 10000 1

This exposes an important limitation. With the historical 100 Mbps reference bandwidth, OSPF cannot distinguish between many modern high-speed links using their automatically calculated costs. A 100 Mbps interface and a 10 Gbps interface can both receive cost 1.

Why OSPF Reference Bandwidth Matters

Modern networks should normally use a reference bandwidth that is high enough to distinguish between the link speeds deployed in the network.

On Cisco IOS, the reference bandwidth can be changed under the OSPF routing process:

router ospf 1
 auto-cost reference-bandwidth 100000

The value is specified in Mbps. A value of 100000 therefore represents 100 Gbps.

With a 100 Gbps reference bandwidth, several interface costs become:

Interface Calculation OSPF Cost
100 Mbps 100000 / 100 1000
1 Gbps 100000 / 1000 100
10 Gbps 100000 / 10000 10
100 Gbps 100000 / 100000 1

OSPF can now clearly distinguish between these link speeds.

Use the Same Reference Bandwidth Consistently

The reference bandwidth should be configured consistently on OSPF routers throughout the routing domain. Using different reference bandwidths can cause routers to calculate interface costs differently, producing confusing or asymmetric path-selection results.

For example:

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

R2(config)# router ospf 1
R2(config-router)# auto-cost reference-bandwidth 100000

R3(config)# router ospf 1
R3(config-router)# auto-cost reference-bandwidth 100000

How OSPF Calculates Total Path Cost

OSPF does not simply compare the cost of the local outgoing interface. The shortest-path calculation considers the accumulated cost through the OSPF topology.

Consider this simplified topology:

        Cost 10
R1 ---------------- R2
 |                   |
 | Cost 20           | Cost 10
 |                   |
 R3 ---------------- R4
        Cost 20

If R1 is calculating a path toward a network reached through R4, it can compare the accumulated costs of the available paths.

Through R2:

R1 → R2 = 10
R2 → R4 = 10
Total    = 20

Through R3:

R1 → R3 = 20
R3 → R4 = 20
Total    = 40

OSPF therefore prefers the path through R2 because its total cost is lower.

OSPF Uses the SPF Algorithm

OSPF is a link-state routing protocol. Routers exchange link-state information and build a link-state database containing the topology of the relevant OSPF area.

Each router then runs the Shortest Path First algorithm, commonly associated with Dijkstra's algorithm, using itself as the root of the shortest-path tree.

The interface costs contained in the topology information influence the resulting SPF tree. The lowest-cost valid route is then selected according to OSPF route-selection rules.

OSPF Route Type Matters Before Cost

A common troubleshooting mistake is to assume that the numerically lowest metric always wins regardless of route type. OSPF also considers the type of OSPF path.

Broadly, OSPF prefers internal routes over external routes. Intra-area paths are preferred over inter-area paths, and external routes have additional selection rules.

This means a route with a seemingly lower numeric metric does not necessarily replace a route belonging to a more preferred OSPF path type.

When troubleshooting unexpected path selection, always inspect both the metric and the OSPF route type.

OSPF External Type 1 and Type 2 Metrics

Redistributed routes can appear as OSPF external routes. Two common external metric types are E1 and E2.

OSPF External Type 1

An E1 route includes the external metric plus the internal OSPF cost required to reach the advertising ASBR. As a router moves farther away from the ASBR, the effective metric can therefore increase.

OSPF External Type 2

E2 is the common default external metric type on many Cisco redistribution configurations. The external metric is the primary metric used for comparison, while the internal cost toward the advertising ASBR is used as part of the tie-breaking process when necessary.

You can identify external route types in the routing table:

R1# show ip route ospf

O E1 203.0.113.0/24 [110/31] via 10.10.12.2, 00:02:18, GigabitEthernet0/0
O E2 198.51.100.0/24 [110/20] via 10.10.13.3, 00:01:42, GigabitEthernet0/1

OSPF Cost Is Different from Administrative Distance

The value displayed inside brackets in the Cisco routing table can cause confusion. Consider:

O 192.168.50.0/24 [110/20] via 10.10.12.2

The values mean:

  • 110 – Cisco administrative distance for OSPF.
  • 20 – OSPF metric or cost for that route.

Administrative distance compares routes learned from different routing sources. OSPF cost is used by OSPF when evaluating OSPF paths.

Changing the OSPF cost is therefore not the same as changing administrative distance.

Viewing OSPF Interface Cost on Cisco IOS

The show ip ospf interface command provides detailed information about the OSPF configuration and state of an interface.

R1# show ip ospf interface GigabitEthernet0/0

Example output may include:

GigabitEthernet0/0 is up, line protocol is up
  Internet Address 10.10.12.1/30, Area 0
  Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 10
  State BDR, Priority 1
  Timer intervals configured, Hello 10, Dead 40

The important field for metric troubleshooting is:

Cost: 10

A quicker overview can be obtained with:

R1# show ip ospf interface brief

Depending on IOS release and platform, the output provides interface, process, area, address, cost, state, and neighbor information in a compact form.

Manually Configuring OSPF Cost

Instead of relying on the bandwidth-derived calculation, an administrator can assign an explicit OSPF interface cost.

R1(config)# interface GigabitEthernet0/0
R1(config-if)# ip ospf cost 50

This explicitly tells OSPF to use cost 50 for that interface.

Manual cost configuration is useful when:

  • Traffic engineering requires a particular path to be preferred.
  • Two links have identical bandwidth but different operational characteristics.
  • A backup path should have a deliberately higher metric.
  • Interface bandwidth values should not be modified merely to manipulate OSPF.
  • An administrator wants deterministic and easily documented OSPF metrics.

Verify the result with:

R1# show ip ospf interface GigabitEthernet0/0

Bandwidth Command Versus ip ospf cost

Cisco interfaces have a configured bandwidth value that routing protocols and other software features may use as a logical parameter.

For example:

R1(config)# interface GigabitEthernet0/0
R1(config-if)# bandwidth 100000

The bandwidth command does not normally change the physical transmission speed of the interface. It modifies the logical bandwidth value used by features that reference it.

Because default OSPF cost is derived from interface bandwidth, changing this value can alter the automatically calculated OSPF cost.

If the only objective is to influence OSPF, explicitly configuring:

ip ospf cost <value>

is often clearer because it directly expresses the routing policy instead of changing a parameter that other features may also use.

Checking Interface Bandwidth

Use the standard interface command to inspect Cisco IOS interface information:

R1# show interfaces GigabitEthernet0/0

Look for a line similar to:

MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec

Here, the reported bandwidth is 1,000,000 Kbit/s, or 1 Gbps.

Unlike EIGRP's classic composite metric, normal OSPF interface cost does not combine bandwidth and delay. The delay field shown by show interfaces is therefore not part of the standard OSPF cost formula.

Equal-Cost Multi-Path with OSPF

If OSPF discovers multiple eligible paths of equal cost to a destination, Cisco routers can install multiple next hops and perform equal-cost multi-path routing.

For example:

R1# show ip route 192.168.100.0

Routing entry for 192.168.100.0/24
  Known via "ospf 1", distance 110, metric 20
  Routing Descriptor Blocks:
  * 10.10.12.2, from 4.4.4.4, metric 20
      Route metric is 20
    10.10.13.2, from 4.4.4.4, metric 20
      Route metric is 20

The presence of two next hops with the same metric can indicate OSPF ECMP operation.

OSPF itself does not provide unequal-cost load balancing in the same way that EIGRP can with the variance feature. OSPF paths generally need to have equal eligible costs to participate in OSPF ECMP.

Useful OSPF Metric Verification Commands

1. Display OSPF Routes

show ip route ospf

Use this command to identify OSPF-installed routes and their metrics.

2. Inspect a Specific Route

show ip route 192.168.100.0

This provides next-hop, administrative distance, metric, and routing-source information for a destination.

3. Inspect OSPF Interfaces

show ip ospf interface

Use this command to verify interface cost, area membership, timers, network type, and adjacency-related information.

4. Display a Compact Interface Summary

show ip ospf interface brief

This is useful when quickly comparing costs across several OSPF interfaces.

5. Check OSPF Neighbors

show ip ospf neighbor

A metric configuration is irrelevant if the expected adjacency has not formed. Confirm that required neighbors have reached the appropriate adjacency state.

6. Examine the OSPF Database

show ip ospf database

The link-state database helps determine what topology information OSPF has learned and is essential for deeper SPF troubleshooting.

7. Inspect the OSPF Process

show ip ospf

This command displays process-level information including router ID, areas, SPF statistics, and reference-bandwidth-related details on supported IOS versions.

8. Verify the Running Configuration

show running-config | section router ospf

This is particularly useful for checking whether auto-cost reference-bandwidth has been configured.

Example: Influencing OSPF Path Selection

Assume R1 has two links toward the same destination. The link through R2 should be primary, while R3 should act as backup.

The administrator can explicitly set costs:

R1(config)# interface GigabitEthernet0/0
R1(config-if)# ip ospf cost 10

R1(config)# interface GigabitEthernet0/1
R1(config-if)# ip ospf cost 100

Assuming the downstream topology does not reverse the comparison with additional accumulated costs, OSPF will favor the path beginning with the lower-cost interface.

Verify the interface metrics:

R1# show ip ospf interface brief

Then verify the selected route:

R1# show ip route 192.168.50.0

Do not stop at the local interface cost when troubleshooting. OSPF chooses paths based on the complete relevant SPF calculation, so downstream costs must also be considered.

Common OSPF Metric Troubleshooting Problems

Problem 1: Gigabit and 10 Gigabit Links Have the Same Cost

This is commonly caused by the traditional 100 Mbps reference bandwidth.

Check the OSPF configuration:

show running-config | section router ospf

If appropriate for the network design, configure a higher consistent reference bandwidth:

router ospf 1
 auto-cost reference-bandwidth 100000

Problem 2: OSPF Chooses an Unexpected Path

Inspect the complete path rather than only the first interface:

show ip route <destination>
show ip ospf interface
show ip ospf database

Check the accumulated cost and OSPF path type.

Problem 3: Routers Calculate Costs Differently

Verify that all relevant routers use a consistent reference-bandwidth policy.

show ip ospf
show running-config | section router ospf

Problem 4: Manual Cost Is Overriding the Expected Calculation

Inspect the interface configuration:

show running-config interface GigabitEthernet0/0

Look for:

ip ospf cost 50

An explicitly configured OSPF cost overrides the normal bandwidth-derived value for that interface.

Problem 5: The Expected Route Is Missing Completely

Before focusing on metrics, confirm that OSPF has a usable topology:

show ip ospf neighbor
show ip ospf interface brief
show ip ospf database
show ip route ospf

Possible causes include a missing adjacency, incorrect area configuration, authentication problems, mismatched timers, network-type issues, route filtering, summarization, or missing advertisements.

OSPF Metric Troubleshooting Workflow

A practical troubleshooting sequence is:

  1. Confirm the destination route with show ip route.
  2. Identify the OSPF route type and metric.
  3. Check available OSPF neighbors.
  4. Verify interface costs with show ip ospf interface.
  5. Check for manually configured ip ospf cost values.
  6. Verify the configured reference bandwidth.
  7. Check interface bandwidth values.
  8. Inspect the OSPF link-state database when the topology does not match expectations.
  9. Calculate the accumulated costs of the competing paths.
  10. Confirm whether equal-cost paths should be installed for ECMP.

OSPF Metrics Quick Reference

Item OSPF Behavior
Metric name Cost
Preferred metric Lowest eligible cost
Default cost basis Reference bandwidth divided by interface bandwidth
Traditional Cisco reference bandwidth 100 Mbps
Manual interface metric ip ospf cost
Reference bandwidth configuration auto-cost reference-bandwidth
Cisco OSPF administrative distance 110 by default
Equal-cost paths ECMP supported
Unequal-cost OSPF load balancing Not equivalent to EIGRP variance

Final Thoughts

OSPF metric calculation is straightforward once the relationship between interface bandwidth, reference bandwidth, and accumulated path cost is understood. OSPF assigns costs to interfaces, builds a link-state topology, runs the SPF algorithm, and selects the best eligible route based on OSPF path-selection rules.

The most important operational issue in modern Cisco networks is the historical 100 Mbps reference bandwidth. If it is left unchanged, links running at 100 Mbps or faster can frequently receive the same default cost. Configuring an appropriate and consistent reference bandwidth allows OSPF to distinguish between modern Ethernet speeds.

For troubleshooting, use show ip route, show ip ospf interface, show ip ospf neighbor, and show ip ospf database together. These commands show not only which path OSPF selected, but also the interface costs, neighbor state, and topology information that caused OSPF to make that decision.

Back to Posts