STP Cost Calculation: Path Cost and Root Port Examples

Learn how STP adds link costs, compares paths to the root bridge and selects one root port—without getting lost in the numbers.

STPPath CostRoot PortCCNA
Spanning Tree Cost Calculation learning map
Learning map for Spanning Tree Cost Calculation showing the article's core concepts, workflow, practice topics, and troubleshooting path.

How does STP cost calculation work?

STP selects the path with the lowest total cost to the root bridge. A switch takes the root path cost advertised in a received BPDU, adds the cost of the local port that received it, and compares that total with the totals learned on its other ports.
Received BPDU
root path cost
+Local receiving
port cost
=Total path cost
to the root

Default port cost is derived from interface speed: faster links normally have lower cost. Each non-root switch chooses exactly one root port—the port that receives the best BPDU and offers the best path toward the root bridge.

STP cost values: short and long methods

The familiar CCNA values 100, 19 and 4 belong to the classic 16-bit short path-cost method. Modern networks may use the 32-bit long method, which distinguishes high-speed links more precisely.

Link speedShort methodLong methodMeaning
10 Mbps1002,000,000Highest cost of these examples
100 Mbps19200,000Preferred over 10 Mbps
1 Gbps420,000Preferred over 100 Mbps
10 Gbps22,000Lowest cost of these examples

Memory aid Slower interface = higher cost. Faster interface = lower cost.

Check the active method: defaults vary by Cisco family and software release. Do not mix short and long values in the same calculation. Verify the switch’s configured method and the cost displayed by show spanning-tree.

Worked example: compare two paths

SW4 can reach root bridge SW1 through SW2 or SW3. Add the incoming interface costs along each path.

ROOT BRIDGE: SW1

Path A through SW2

SW1 · RootStart cost 0
SW2Advertises 19
SW4Adds local cost 4
19 + 4 = 23
SELECTED ROOT PORT

Path B through SW3

SW1 · RootStart cost 0
SW3Advertises 19
SW4Adds local cost 19
19 + 19 = 38
HIGHER-COST PATH NOT SELECTED
Original visual: SW4 selects the interface toward SW2 because total path cost 23 is lower than 38.
  1. SW1 is the root, so it originates BPDUs with root path cost 0.
  2. SW2 receives the BPDU on a 100 Mbps port, adds 19 and advertises a root path cost of 19.
  3. SW4 receives SW2’s BPDU on a 1 Gbps port, adds 4 and calculates 23.
  4. Through SW3, SW4 calculates 19 + 19 = 38.
  5. Because 23 is lower than 38, the SW4 port toward SW2 becomes its root port.

Where cost appears in a BPDU

A configuration BPDU carries the Root ID and a Root Path Cost field. Switches do not build a link-state map of the entire topology. They compare the BPDU information received on their ports and improve the advertised cost by adding their local receiving-port cost.

For the selected path above, SW2 advertises 19. SW4 does not expect SW2 to advertise SW4’s local link cost; SW4 adds its own incoming 1 Gbps port cost of 4 and obtains 23.

Think locally: a switch only needs the quality of the BPDUs it receives. The best received information plus local port cost determines its best route toward the root.

What happens when STP costs are equal?

Path cost is not the only comparison. If two candidate BPDUs tie, STP keeps comparing fields until it finds a lower value.

FirstLowest Root Bridge ID
ThenLowest total Root Path Cost
If tiedLowest Sender Bridge ID
If tiedLowest Sender Port ID
Rare final tieLowest Local Port ID

Two parallel links to the same upstream switch

If SW2 receives equal-cost BPDUs over two links from the same upstream switch, the upstream sender port ID normally breaks the tie. Port ID combines port priority and port number. With default priorities, the BPDU sent from the lower-numbered upstream port wins.

Common shortcut: people often say “the lowest interface number wins.” That is usually the visible outcome in a simple parallel-link lab, but the formal comparison is the BPDU sender port ID before the local receiving port ID.

Verify and configure STP cost on Cisco switches

Show the selected cost

SW4# show spanning-tree vlan 10

Interface  Role Sts Cost  Prio.Nbr Type
---------  ---- --- ----- -------- ----
Gi0/1      Root FWD 4     128.1    P2p
Fa0/2      Altn BLK 19    128.2    P2p

SW4# show spanning-tree interface gi0/1 detail

Choose short or long method

SW4(config)# spanning-tree pathcost method long

! Return to the platform default
SW4(config)# no spanning-tree pathcost method long

Set an interface cost deliberately

SW4(config)# interface GigabitEthernet0/1
SW4(config-if)# spanning-tree vlan 10 cost 50

! Restore the calculated default
SW4(config-if)# no spanning-tree vlan 10 cost

Command syntax and valid ranges depend on platform, spanning-tree mode and whether the interface is an access port or trunk. Always check the device command reference and confirm the result with show spanning-tree vlan 10.

Design caution: changing cost changes the active Layer 2 topology. Document the intended path, verify both directions and maintain out-of-band or console access for remote changes.

Common STP cost calculation mistakes

  • Comparing only one link: add every incoming port cost along the complete path to the root.
  • Mixing short and long values: determine the active path-cost method first.
  • Adding the outgoing port incorrectly: a switch adds the cost of the local port on which it receives the BPDU.
  • Assuming the switch knows the entire topology: STP makes distributed decisions from received BPDUs.
  • Stopping when costs tie: continue with sender Bridge ID and sender Port ID.
  • Changing cost without verifying VLAN scope: trunk ports may use per-VLAN cost settings.

Spanning Tree Cost Calculation Frequently Asked Questions

How is STP root path cost calculated?

Add the costs of the incoming ports used along the path from the non-root switch toward the root bridge. Operationally, each switch adds its local receiving-port cost to the root path cost advertised in the BPDU.

Why does STP prefer the lowest cost?

Lower default cost represents higher interface speed, so selecting the lowest cumulative cost normally creates the fastest available loop-free path to the root.

What is the STP cost of a 1 Gbps link?

It is 4 with the classic short method and 20,000 with the long method.

What is the STP cost of a 100 Mbps link?

It is 19 with the short method and 200,000 with the long method.

Where is root path cost stored?

Configuration BPDUs include a Root Path Cost field that represents the sender’s cost to reach the root bridge.

Can I change STP cost manually?

Yes. A manual interface or per-VLAN cost can influence path selection, but it should be planned, documented and verified carefully.

Authoritative references

Cost values and path-selection behavior were checked against Cisco’s Spanning Tree Protocol guide, Catalyst STP configuration guide and Cisco short and long path-cost table.

Continue the STP lesson chain

Continue learning

Use these related resources to apply or verify the concepts on this page: