DEV Community

NetEngineerLab
NetEngineerLab

Posted on

STP Path Cost: When the Short Table Ties and the Long Formula Does Not

A spanning-tree path cost is the sum of the port costs toward the root, not a hop count. Faster links are supposed to look cheaper. Whether they actually do depends on which cost method you are using. The STP Path Cost Calculator applies either the long formula or the short table, then compares two paths.

Long formula versus short table

The long method, as implemented by the calculator, is:

cost_long = clamp(1, 200000000, round(2e10 / (B_Mbps × 1000)))
Enter fullscreen mode Exit fullscreen mode

The × 1000 converts the typed Mbit/s value into kbit/s, which is the unit in the denominator. Rounding is ordinary nearest-integer rounding. The result is then forced into the range 1 through 200000000.

The short method does not use that formula at all. It looks the speed up in a fixed table and rejects any other rate:

Speed (Mbit/s) Short cost
4 250
10 100
16 62
100 19
1000 4
10000 2

A 100 Gbit/s port is a valid long-method input and a short-method error. The short table also cannot rank anything above 10 Gbit/s, which is why two different physical paths can look equal under short costs and unequal under long costs.

Speeds are typed in Mbit/s. The engine does not parse a token such as 10G. Separate hops with spaces, commas, or semicolons, and keep each path between 1 and 32 hops.

Worked example: two 10 Gbit/s hops versus one 1 Gbit/s hop

Path A is 10000 10000. Path B is 1000.

Long method:

  1. Each 10 Gbit/s hop: 2e10 / (10000 × 1000) = 2000.
  2. The 1 Gbit/s hop: 2e10 / (1000 × 1000) = 20000.
  3. Total A = 4000. Total B = 20000. Winner A, difference 16000.

Short method on the same speeds: path A is 2 + 2 = 4, path B is 4. The tool reports a tie and a warning. A real bridge would still have to break that tie with the bridge ID. This calculator stops at the cost comparison and does not invent a root bridge.

A few more long-method checks, still using the same formula: 10 Mbit/s costs 2000000, 100 Mbit/s costs 200000, 100 Gbit/s costs 200, and 400 Gbit/s costs 50.

Common mistakes

  • Comparing a short-table total with a long-formula total. The two scales are not interchangeable.
  • Expecting the short table to accept 40 Gbit/s or 100 Gbit/s. Those rows are missing, and the tool returns an error instead of interpolating.
  • Typing 10G or 1G. The fields want 10000 and 1000.
  • Treating a reported tie as "the two paths are operationally identical." It only means the cost sums are equal. Port priority and bridge ID are outside the tool.
  • Counting hops instead of summing port costs. Two cheap 10 Gbit/s hops can beat one expensive 1 Gbit/s hop, which is the point of the long-method example above.

What the comparison leaves open

The calculator does not configure a switch, and it does not apply port priority or a root bridge ID. It assigns a cost to each typed speed, adds the hops on path A and path B, and says which sum is smaller.

Rerun the two-versus-one example in the STP Path Cost Calculator. Interface metrics for OSPF on the same link rates are a separate calculation, in the OSPF Cost Calculator.

Top comments (0)