Calculate Spanning Tree Protocol port cost based on link speed and STP version.
Spanning Tree Protocol assigns a cost to each link based on its speed, and switches sum these costs along every path to the root bridge to determine the lowest-cost (fastest, most direct) path, which becomes the active forwarding path while redundant paths are blocked to prevent loops. The legacy 802.1D 'short' cost values used a 16-bit scale poorly suited to modern high-speed links, so the 802.1T 'long' cost values use a much wider 32-bit range that better differentiates between 1G, 10G, 40G, and 100G links.
STP path cost
path_cost = per_link_cost(speed) × number_of_hops
Under the IEEE 802.1T 'long' method (current default): 10 Mbps = 2,000,000; 100 Mbps = 200,000; 1 Gbps = 20,000; 10 Gbps = 2,000; 40/100 Gbps = 500/200. Under the older 802.1D 'short' method: 10 Mbps = 100; 100 Mbps = 19; 1 Gbps = 4; 10 Gbps and above = 2.
STP's root path cost represents the cumulative 'expense' of reaching the root bridge — lower cost implies a faster, more direct path. Switches select the path with the lowest total accumulated cost as the active forwarding path, blocking higher-cost redundant paths to prevent Layer 2 loops.
The original 'short' method used an 8-bit-derived scale (values like 2, 4, 19, 100) that couldn't meaningfully distinguish between very fast modern links — 10G, 40G, and 100G all round to nearly the same cost. The 'long' method uses much larger, more granular values so higher-speed links are still clearly favored over slower ones even at multi-gigabit scale.