Watch on Instagram

Network Bytes · Episode 98 · CCNA 3.4

"OSPF cost"

OSPF adds up link costs along each path and picks the lowest total. Each link's cost is the reference bandwidth divided by the interface bandwidth, with a 100 Mbps default reference, so fast links need a higher reference set with auto-cost reference-bandwidth.

Posted · About a 1 minute watch, 3 minute read · Take the quiz

Lowest total wins

Every OSPF router adds up the cost of each outgoing interface along a path to a destination. When there is more than one way to get there, the path with the lowest total goes into the routing table. A short path made of slow links can lose to a longer path made of fast ones.

The toll road

Think of each link as a road with a toll booth: the slower the road, the higher the toll. A narrow country lane charges a lot, a wide highway charges a little. OSPF is the driver who adds up every toll on the trip and takes the cheapest route.

Where each cost comes from

On Cisco IOS, an interface's OSPF cost is:

`` cost = reference bandwidth ÷ interface bandwidth ``

The default reference bandwidth is 100 Mbps, and the result is rounded down, with a minimum of 1:

| Link | Default cost | |---|---| | 10 Mbps | 10 | | 100 Mbps | 1 | | 1 Gbps | 1 | | 10 Gbps | 1 |

The catch, and the fix

With the default reference, every link of 100 Mbps or faster costs 1, so OSPF can't tell a FastEthernet link from a 10-gig one. Raise the reference under the OSPF process (the value is in Mbps):

`` router ospf 1 auto-cost reference-bandwidth 10000 ``

Now 10 Gbps costs 1, 1 Gbps costs 10 and 100 Mbps costs 100. IOS reminds you to use the same reference on every router in the area; if routers disagree, they compute costs on different scales and can pick poor paths.

Try it yourself

In Cisco Packet Tracer, build three routers in a triangle, with one Gigabit link and two FastEthernet links, and run single-area OSPF. Use show ip ospf interface brief to read each interface's cost and show ip route ospf to see the chosen path and its metric. Then set auto-cost reference-bandwidth 10000 on all three routers and compare the costs and the route again.

Good to know

  • CCNA 3.4 covers configuring and verifying single-area OSPFv2 (EP46 introduced adding up link costs; EP94 covers the router ID).
  • Cost = reference bandwidth ÷ interface bandwidth, default reference 100 Mbps, rounded down and never below 1.
  • The bandwidth used is the interface's configured bandwidth value, which defaults to the link speed on Ethernet. Changing it changes the cost (left out of the short).
  • You can also set a cost directly with ip ospf cost <value> on an interface (left out of the short).
  • auto-cost reference-bandwidth <Mbps> goes under router ospf, and should match on every router.
  • A path's cost is the sum of the outgoing interface costs along the way.
  • "Toll road" is the analogy.

For CCNA learners

CCNA exam topic 3.4 covers single-area OSPFv2. Know the cost formula, the 100 Mbps default reference, why fast links all end up at cost 1, how auto-cost reference-bandwidth fixes it, and how to check costs with show ip ospf interface.

Answer to the comment question

21. With the default 100 Mbps reference, each 10 Mbps link costs 100 ÷ 10 = 10 and the 100 Mbps link costs 100 ÷ 100 = 1, so the path totals 10 + 10 + 1 = 21.

Test your knowledge

Quick quiz: "OSPF cost"

4 multiple-choice questions. Pick one answer for each, then check how you did.

1How does OSPF choose between two paths to the same network?
2With the default reference bandwidth, what is the OSPF cost of a 10 Mbps link?
3Why do 100 Mbps, 1 Gbps and 10 Gbps links all get cost 1 by default?
4What should you do after raising the reference with auto-cost reference-bandwidth on one router?

Sources

Video transcript

How does OSPF decide that one link costs more than another?

OSPF adds up link costs and picks the lowest total. But where does each cost come from?

Think of a toll road: the slower the road, the higher the toll.

Cost equals the reference bandwidth divided by the link's bandwidth. By default, the reference is one hundred megabits per second. So a ten-megabit link costs ten, and a hundred-megabit link costs one.

The catch: gigabit and ten-gig links also cost one, since cost can't go below one. So set a higher reference, with auto-cost reference-bandwidth, on every router.

Default reference. A path crosses two ten-megabit links and one hundred-megabit link. What's the total cost? Comment your answer below!

That's your byte.

More from Network Bytes

All Network Bytes lessons