OSPF · · 6 min read

How OSPF Calculates Metric and Cost

How OSPF Calculates Metric and Cost

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:

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:

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:

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]


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

Scenario:
R1 has two links to R2:

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).


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:

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:


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:

The cost of R1's incoming interface is not counted.


OSPF Cost vs Administrative Distance

Confused? These are different:

Example:

Router# show ip route
O    192.168.10.0/24 [110/20] via 10.0.0.2, GigabitEthernet0/0

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:

  1. Topology diagram showing cost calculation along two paths
  2. show ip ospf interface output highlighting Cost field
  3. show ip route ospf output with [AD/Metric] annotated
  4. Side-by-side comparison: default reference BW vs adjusted reference BW

Internal Links:

Read next

© 2025 Ping Labz. All rights reserved.