Course menu

Course 9: OSPFLesson 4.3 (10 of 20 in this course)79 of 118 in the CCNA series

OSPF cost and reference bandwidth

How OSPF turns bandwidth into cost, adds it up along a path, and three ways to change it.

Intermediate · 11 min read

What you will learn

After this lesson, you can calculate the cost of an interface and of a whole path, explain why the reference bandwidth should be raised, and change cost with the right command.

  • Cost formula
  • auto-cost reference-bandwidth
  • ip ospf cost
  • ECMP

OSPF cost is the metric OSPF uses to compare paths. Each outgoing interface has a cost, by default reference bandwidth ÷ interface bandwidth, and the cost of a path is the sum of the outgoing interface costs along it. The path with the lowest total wins.

In simple terms: Every link has a price, and faster links are cheaper. OSPF adds up the prices along each possible path and picks the cheapest one.

A real-life situation

The network from the first module has two paths from LAN A to LAN B. The top one, through R2, is gigabit all the way. The bottom one, through R3, includes an older 100 Mbps link between R1 and R3. With OSPF running on default settings, users complain that copies to the servers are sometimes fast and sometimes slow. show ip route on R1 shows two routes to LAN B with the same cost: OSPF is sending half the traffic over the slow link. It can't tell the two links apart, and this lesson shows why.

What OSPF cost is

Each interface gets a cost from one simple division:

cost = reference bandwidth ÷ interface bandwidth

The result is rounded down and is never less than 1. The reference bandwidth is 100 Mbps unless you change it. That made sense when 100 Mbps was fast, but today it means:

InterfaceBandwidthCost with the default 100 Mbps referenceCost with a 1 000 Mbps reference
Serial (T1)1.544 Mbps64647
Ethernet10 Mbps10100
FastEthernet100 Mbps110
GigabitEthernet1 Gbps11
TenGigabitEthernet10 Gbps11

With the default, FastEthernet, gigabit and 10-gigabit all cost 1. That is exactly the problem in the situation above. Raising the reference to 1 000 Mbps separates 100 Mbps from 1 Gbps; a network with 10-gigabit links needs 10 000 Mbps or more.

How path cost adds up

A router adds the cost of each outgoing interface on the way to the destination, including the interface on the last router that connects to the destination LAN. Costs of incoming interfaces are not counted.

Gi0/0Gi0/1Gi0/0cost 1Gi0/2Gi0/0cost 10Gi0/1Gi0/1cost 1Gi0/1Gi0/2cost 1Gi0/0LAN A192.168.1.0/24R1RID 1.1.1.1R2RID 2.2.2.2R3RID 3.3.3.3R4RID 4.4.4.4LAN B192.168.4.0/24
  1. 1. Top path: cost 3. R1 Gi0/1 (1) + R2 Gi0/1 (1) + R4 Gi0/0 to LAN B (1).
  2. 2. Bottom path: cost 12. R1 Gi0/2, the 100 Mbps link (10) + R3 Gi0/1 (1) + R4 Gi0/0 (1).
  3. 3. OSPF installs the top path. R1's routing table shows O 192.168.4.0/24 [110/3] via 10.0.12.2. The bottom path stays in the LSDB as a backup if the top one fails.

With the default reference, the 100 Mbps link would cost 1 too: both paths would total 3, and R1 would use both. That is equal-cost multi-path (ECMP). OSPF installs up to 4 equal paths by default (change it with maximum-paths under router ospf). ECMP is useful when the paths really are equal, and harmful when they only look equal.

How to configure it on Cisco IOS

There are three ways to influence cost. In order of priority, highest first:

1. Set the cost directly

interface GigabitEthernet0/2 ip ospf cost 10

On R1. Overrides every calculation for this interface (1 to 65 535). It affects only traffic leaving R1 through Gi0/2; R3 keeps its own cost for the opposite direction.

2. Change the bandwidth the formula uses

interface GigabitEthernet0/2 bandwidth 100000

In kbps (100 000 kbps = 100 Mbps). The formula now divides by 100 Mbps. Use it when the interface runs faster than the real service, for example a gigabit port connected to a 100 Mbps WAN circuit. Other features read this value too.

3. Raise the reference bandwidth (recommended)

router ospf 1 auto-cost reference-bandwidth 1000

In Mbps, on every router. IOS answers with a reminder: % OSPF: Reference bandwidth is changed. Please ensure reference bandwidth is consistent across all routers.

The reference must be the same on every router. Otherwise one router thinks a gigabit link costs 1 and another thinks it costs 10, and their path choices stop making sense together. Choose a value at least as high as your fastest link, so the fastest link costs 1 and everything slower costs more.

How to verify it

Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ip ospf interface brief
Interface    PID   Area            IP Address/Mask    Cost  State Nbrs F/C
Gi0/2        1     0               10.0.13.1/30       10    P2P   1/1
Gi0/1        1     0               10.0.12.1/30       1     P2P   1/1
Gi0/0        1     0               192.168.1.1/24     1     DR    0/0
The Cost column is the quickest check: 10 on the 100 Mbps link, 1 on the gigabit ones.
Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ip route 192.168.4.0
Routing entry for 192.168.4.0/24
  Known via "ospf 1", distance 110, metric 3, type intra area
  Last update from 10.0.12.2 on GigabitEthernet0/1, 00:01:15 ago
  Routing Descriptor Blocks:
  * 10.0.12.2, from 4.4.4.4, 00:01:15 ago, via GigabitEthernet0/1
      Route metric is 3, traffic share count is 1
metric 3 through R2. One routing descriptor block means one path. Before the reference bandwidth was raised, a second block via 10.0.13.2 would have appeared here with the same metric.
Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show interfaces GigabitEthernet0/2 | include BW
  MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
BW is the bandwidth OSPF divides by. It shows either the real speed or the value from the bandwidth command.
show ip ospf | include Reference

Prints: Reference bandwidth unit is 1000 mbps. Check it on every router.

What goes wrong and how to troubleshoot it

  • Traffic is shared over a fast and a slow link. The default reference makes them equal. Raise auto-cost reference-bandwidth everywhere.
  • Path choices change depending on which router you ask. The reference bandwidth differs between routers. Compare show ip ospf | include Reference.
  • Traffic goes one way and returns another. ip ospf cost was set on one end of a link only. That isn't wrong, but it should be deliberate.
  • A cost won't change. An ip ospf cost on the interface overrides both the reference bandwidth and the bandwidth command.

Common mistakes

  • Counting incoming interface costs. Only outgoing interfaces count.
  • Forgetting the last router's LAN interface when adding up a path.
  • Mixing units: auto-cost reference-bandwidth is in Mbps, bandwidth is in kbps.
  • Changing the reference bandwidth on one router only.
  • Thinking bandwidth changes the real speed of the interface.

💡 Exam tip: be fast at 100 ÷ bandwidth in Mbps (and at other reference values), at adding path costs from a diagram, and at reading [110/3] as distance 110, cost 3. Know the three commands and that ip ospf cost wins over the other two.

Key takeaways

✅ Key takeaways
  • Interface cost = reference bandwidth ÷ interface bandwidth, rounded down, minimum 1, maximum 65 535.
  • Path cost = sum of outgoing interface costs, including the destination LAN interface.
  • The default 100 Mbps reference makes every link of 100 Mbps or more cost 1; raise it on every router.
  • ip ospf cost overrides bandwidth, which overrides the real speed.
  • Equal total costs give ECMP: up to 4 paths by default.

Check yourself

Predict · scenario 1

The reference bandwidth is the default. What is the cost of a 10 Mbps Ethernet interface?

Predict · scenario 2

With a 1 000 Mbps reference, R1 has paths to LAN B of cost 1 + 1 + 1 and 10 + 1 + 1. Which does it use?

Predict · scenario 3

You type auto-cost reference-bandwidth 10000 on R1 only. What is the likely result?

Predict · scenario 4

An interface has bandwidth 100000 and ip ospf cost 5. The reference is 1 000 Mbps. What is its cost?

FAQ

Is OSPF cost the same in both directions of a link?
Not necessarily. Each router uses the cost of its own outgoing interface. Usually both ends have the same bandwidth and so the same cost, but if you set ip ospf cost on one end only, traffic in each direction can take a different path.
Does the bandwidth command change the speed of the link?
No. It only changes the number that routing protocols and some other features (such as EIGRP and QoS calculations) use. The interface still sends at its real speed.
What are the smallest and largest costs?
An interface cost is between 1 and 65 535. The formula is rounded down and never goes below 1, which is why every link at or above the reference bandwidth gets cost 1.