DEV Community

NetEngineerLab
NetEngineerLab

Posted on

How OSPF Interface Cost Is Calculated

OSPF interface cost is a unitless integer, not a hop count. The usual formula is reference bandwidth divided by the interface rate. The result is rounded to an integer and then forced into the range 1 through 65535. That is the arithmetic used by the OSPF Cost Calculator.

The formula and the units

cost = clamp(1, 65535, round(B_ref / B_if))
Enter fullscreen mode Exit fullscreen mode

B_ref and B_if must use the same unit. The calculator takes both in Mbit/s. A 10 Gbit/s link is entered as 10000, not 10. Type 10 and the cost looks like a 10 Mbit/s port.

If you leave the reference blank, the tool uses 100000 Mbit/s, which is 100 Gbit/s. That default is why a 1 Gbit/s interface often shows cost 100 on modern gear, while the old 100 Mbit/s reference would have given it cost 1 and made every faster link look the same.

round can be ceil, floor, or round. The default is ceil, because fractional costs are not used. A ratio of 1.01 becomes 2 under ceiling and 1 under floor.

Worked example: 100 Gbit/s reference, ceiling, no overrides

Interface Bandwidth (Mbit/s) Ratio Cost
Gigabit 1000 100 100
Ten-gigabit 10000 10 10
Fast Ethernet 100 1000 1000
400 Gbit/s 400000 0.25 1

A path with one 10 Gbit/s hop and one 1 Gbit/s hop is 10 + 100 = 110. The calculator adds only the interfaces you leave enabled. Disabled rows are left out of the total.

Rounding changes the mid-rate cases. For 100000 / 3000, the exact ratio is 33.3.... Floor gives 33, ceiling gives 34, and nearest-integer rounding gives 33.

Two boundaries matter as much as the mid-rate cases. Any interface faster than the reference still costs 1, never 0. A manual override of 50 replaces the calculated cost. An override of 0 or 70000 is rejected, because those values sit outside 1 through 65535.

Common mistakes

  • Entering 10 Gbit/s as 10. With a 100000 Mbit/s reference that produces cost 10000, the same number a 10 Mbit/s link would get.
  • Mixing units in the two fields. If the reference is already in Mbit/s, the interface rate has to be in Mbit/s as well.
  • Assuming floor and ceiling agree once the ratio looks "close to an integer." On 3000 Mbit/s they differ by one.
  • Treating equal path totals as a guarantee that the forwarding plane will load-share. The tool only counts how many computed totals share the minimum. It does not inspect the hardware.
  • Reading cost 65535 as "the link is down." That number is the upper clamp, not an operational state.

What the number does not cover

The calculator does not parse a vendor bandwidth CLI string, and it does not build LSAs or choose an area or network type. It turns the numbers you type into integer costs, sums the paths you listed, and reports the lowest total.

You can rerun the table above in the OSPF Cost Calculator. If you also need to compare spanning-tree path costs for the same speeds, use the STP Path Cost Calculator.

Top comments (0)