When a loop occurs in the switched network, the STP uses path cost to resolve the port’s state. Path cost is obtained from the port’s speed. The spanning tree puts the lowest-numbered port into the forwarding state if all connected ports have the same path cost values. For CCNA students, understanding path cost is key to mastering STP root bridge election and loop prevention. In CCNP, it ties into rapid convergence with RSTP.
Pro tip: Always verify costs post-config to avoid suboptimal paths in production—I’ve seen it cause 50 ms+ convergence delays in VLANs.
The path information is determined using the sum of the individual port costs from the destination to the root bridge. Each “destination” is a switch port. The port’s speed defines the default port costs. The table below illustrates the default port cost of the Cisco switches.
| Link Speed | Legacy Cost (802.1D-1998) | Revised Cost (802.1D-2004+) | Notes |
|---|---|---|---|
| 100 Gbps | N/A | 1 | Common in modern spines |
| 40 Gbps | N/A | 1 | Data center aggregation |
| 10 Gbps | 1 | 2 | Updated for 10GE |
| 1 Gbps | 1 | 4 | Standard GE links |
| 100 Mbps | 10 | 19 | Fast Ethernet legacy |
| 10 Mbps | 100 | 100 | Rarely used today |
Note: Costs auto-scale based on negotiated speed. For CCNP, remember MSTP inherits these but allows region-specific tweaks.
As shown in the table, 100G/b and 40 G/b port have the port cost of 1, 10 Gb/s Ethernet ports have a port cost of 2, 1 Gb/s Ethernet ports have a port cost of 4, 100 Mb/s Fast Ethernet ports have a port cost of 19, and 10 Mb/s Ethernet ports have a port cost of 100. So, if the speed is slow, the price is more significant for the spanning-tree algorithm.
The IEEE revised cost values to accommodate the 100 and 40 Gigabit Ethernet standards. As newer and faster Ethernet technologies enter the marketplace, the path cost values may again be revised to accommodate new standards. The default cost of the port is associated with the port, but we can manually configure the cost value for any port to control the spanning tree paths on the root bridge. We can configure the port cast in interface configuration mode. The cost value must be between 1 and 200 000 000. Enter the “no spanning-tree cost” in interface configuration mode to restore the default port cost value.
Path Cost Formula: Total Path Cost = Σ (Individual Port Costs) along the path to Root Bridge. Lower sum = preferred path. In RSTP (CCNP focus), this feeds into proposal/agreement for faster blocking.
Path Cost Calculation
Paths with the lowest cost become the preferred path. The remaining paths to the root bridge are blocked. Now look at the below image and analyze all the paths from all switches to the root bridge:
Topology Diagram: A root bridge connected to Switch-2 (Fa0/1) and Switch-3 (Fa0/1). Switch-2 links to Switch-3 (Fa0/2-Fa0/3) and Switch-4 (Gig1/0/1). Switch-3 links to Switch-5 (Eth2/1). Switch-4 links to Switch-5 (Fa0/1-Fa0/4). All non-root links are 100 Mbps unless noted.
Switch-2

Switch-2 has three ways to go towards the root bridge.
- Fa0/3 (Fast Ethernet) of switch-3 is directly connected to Fa0/1 (Fast Ethernet) of the root bridge. The link works at 100 Mbps, so the link cost is 19.
- The second route towards the root bridge is via switch-3. The link between switch-2 and switch-3 costs 19, and the cost between switch-3 and the root bridge is 100. So, the total cost of the root is 19 + 100 = 119.
- The third root towards the root bridge is via switch-4, switch-5, and switch-3. The path cost of this root is 19+19+100+100=238
The lowest-cost path towards the root bridge is 19, a link from Fa0/3. Thus, port Fa0/3 becomes a root port, and the remaining ports become designated ports or blocked ports.
Switch-3
Similarly, switch-3 also has three ways toward the root bridge:
- The first root is directly connected with the root cost of 100.
- The second root is via switch-2. The root cost for this root is 19+19=38.
- The third root is via switch-5, switch-4, and switch-3. The root cost for this root is 100+19+19+19=157
The lowest-cost path towards the root bridge is 38, a link from the Fa0/1 switch-3 to switch-2. Thus, port Fa0/1 of this switch becomes a root port, and the remaining ports become designated ports or block ports.
Switch-4
This switch also goes four ways toward the root bridge.
- The first way is via switch-2 to the root bridge. The path cost is 19+19=38
- The second path is via switch-2 to switch-3 and then the root bridge. The path cost is 19+19+100=138.
- The third path is from switch-4 to switch-5, switch-3, and then the root bridge. The cost for this path is 19+100+100=219
- The fourth path is switch-5 to switch-3 to switch-2, and then the root bridge. The path cost for this root is 19+100+19+19 =157
The lowest-cost path towards the root bridge is 38, a link from switch-4 to switch-2. Thus, port Gig1/0/1 of this switch becomes a root port, and the remaining ports become designated ports or block ports.
Loop Resolution Summary:
| Loop | Blocked Ports | Reason |
|---|---|---|
| Root-S2-S3 | Eth2/1 (S3) | Higher cost path (119 vs. 19) |
| S2-S3-S4-S5 | Fa0/4 (S5) | Redundant 100Mbps loop (238 cost) |
Switch-5
Switch-5 also has four ways toward the root bridge.
- The first way is via switch-3 to the root bridge. The path cost is 100+100=200
- The second path is via switch-3 to switch-2 and then the root bridge. The path cost is 100+19+19=138.
- The third path is from switch-5 to switch-4, switch-2, and then the root bridge. The cost for this path is 19+19+19=57
- The fourth path is switch-4 to switch-2 to switch-3, and then the root bridge. The path cost for this root is 19+19+19+100 =157
So, the lowest-cost path towards the root bridge is 57, a link from switch-5 to switch-4, switch-2, and then the root bridge. So port Fa0/1 of this switch becomes a root port, and the remaining ports become designated ports or block ports.
Notice: The topology has two physical loops. The first loop is between the root bridge and switches 2 and 3, and the second is between switches 2, 3, 4, and 5. The spanning-tree algorithm blocks port Eth2/1 of switch-3 and port fa0/4 of switch-5 to avoid the loop.
Configure the Path Cost
In interface configuration mode, verify the path cost by using the “spanning-tree cost <cost_value>” command. To verify the port and path cost to the root bridge, enter the “show spanning-tree” command.
FAQs
What is path cost in the Spanning Tree Protocol?
Path cost in STP is a numerical value assigned to each port based on link speed, used by the Spanning Tree Algorithm to select the lowest-cost path to the root bridge. Slower links like 100 Mbps have higher costs (19 in revised standards) than 1 Gbps (4), ensuring faster paths are prioritized. This prevents loops by blocking redundant high-cost ports, maintaining a loop-free topology. Total cost is the sum of individual port costs along the path.
How is the root port determined using path costs?
The root port on a non-root switch is the one with the lowest cumulative path cost to the root bridge, calculated by summing costs of all links in the path. For example, in a 100 Mbps topology, a direct link (cost 19) beats a multi-hop path (cost 38+). This port always forwards traffic; others become designated or blocked based on segment costs, optimizing convergence and preventing broadcast storms.
What are the differences between legacy and revised STP path costs?
Legacy IEEE 802.1D-1998 costs cap at low values (e.g., 1 for 10/1000 Mbps), unsuitable for modern speeds like 10 Gbps. Revised 802.1D-2004+ scales costs higher for slower links (e.g., 19 for 100 Mbps, 2 for 10 Gbps) while keeping ultra-fast links at 1, allowing precise prioritization in data centers. Switches auto-detect but support manual tweaks via ‘spanning-tree cost’ command.
How do you manually configure path costs in Cisco switches?
Enter interface config mode with ‘interface ‘, then use ‘spanning-tree cost <1-200000000>’ to set a custom value, overriding auto-detected link speed costs. For example, ‘spanning-tree cost 10’ on a Fa0/1 port forces a lower cost for testing. Verify with ‘show spanning-tree’ to check roles and costs; use ‘no spanning-tree cost’ to revert to defaults, ensuring optimal STP topology without loops.
