spanning-tree cost [value]
Sets the path cost for a specific interface in Spanning Tree Protocol (STP) calculations, overriding the default cost based on interface speed.
Definition: spanning-tree cost [value] is a Cisco IOS interface config command. Sets the path cost for a specific interface in Spanning Tree Protocol (STP) calculations, overriding the default cost based on interface speed.
Overview
The `spanning-tree cost [value]` command is an interface-level configuration command used to manually set the path cost for a specific port in Spanning Tree Protocol (STP) calculations. In STP, each port has a default cost based on its speed (e.g., 100 Mbps = 19, 1 Gbps = 4, 10 Gbps = 2). However, there are scenarios where you need to influence the root port selection or alter the active topology without changing physical link speeds.
This command overrides the default cost, allowing you to make a path more or less preferred. It is critical for load balancing, redundancy optimization, and ensuring deterministic failover behavior. You would reach for this command when you need to manually steer traffic away from a particular link, perhaps because it is a slower backup link or you want to force a specific switch to become the root bridge.
Alternatives include using `spanning-tree vlan <vlan> cost <value>` for per-VLAN STP (PVST+), or adjusting bridge priority with `spanning-tree vlan <vlan> priority <value>`. The command fits into the broader STP configuration workflow: after setting the root bridge priority, you may fine-tune port costs to control which ports become root ports or designated ports. In terms of IOS behavior, the command is executed in interface configuration mode, and the change is immediately applied to the running configuration.
It requires privileged EXEC access (enable mode) to enter global configuration. The cost value is an integer from 1 to 200000000 (though practical values are much lower). Setting an extremely high cost effectively disables the port from being selected as a root port.
The command is saved to the running config and can be written to startup config. It is supported in all IOS versions, including IOS-XE, and is fundamental to STP tuning.
spanning-tree cost [value]When to Use This Command
- Influencing the root port selection by manually setting a lower cost on a preferred link.
- Forcing traffic to take a specific path in a redundant network by adjusting costs.
- Load balancing across multiple links by setting equal costs for equal-cost paths.
- Troubleshooting suboptimal STP topology by increasing cost on a less desirable link.
Parameters
| Parameter | Syntax | Description |
|---|---|---|
| value | <1-200000000> | The path cost for the interface. Valid range is 1 to 200000000. Common values: 19 for 100 Mbps, 4 for 1 Gbps, 2 for 10 Gbps. A lower cost makes the path more preferred. Common mistake: using values outside the range or not matching the speed (e.g., using 19 on a 1 Gbps link). |
Command Examples
Setting a custom port cost on an interface
spanning-tree cost 19No output is generated upon successful configuration. The command sets the STP cost to 19 for the current interface, overriding the default cost (e.g., 100 Mbps default cost is 19).
Verifying the configured cost
show spanning-tree interface gigabitethernet 0/1Vlan Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- ---------------------------- VLAN0001 Desg FWD 19 128.1 P2p VLAN0010 Desg FWD 19 128.1 P2p
The 'Cost' column shows the configured cost of 19 for both VLANs. 'Desg' indicates the interface is a designated port, 'FWD' means forwarding state, 'Prio.Nbr' shows priority and port number, and 'Type' indicates point-to-point link.
Understanding the Output
When using 'show spanning-tree interface', the output displays per-VLAN STP information. The 'Cost' field shows the port cost used in STP calculations. A lower cost makes the port more likely to be selected as root port.
Default costs are based on interface speed: 10 Mbps = 100, 100 Mbps = 19, 1 Gbps = 4, 10 Gbps = 2. Manually set costs override defaults. In a stable network, all ports should be in forwarding (FWD) or blocking (BLK) state.
Watch for unexpected costs that could cause suboptimal paths or loops.
Configuration Scenarios
Force a specific port to become root port on a non-root switch
In a network with redundant links, you want SwitchB to use its GigabitEthernet0/1 link as the root port instead of the default selection based on lowest path cost to the root bridge.
Topology
SwitchA (Root) --- Gi0/1 (cost 4) --- SwitchB
SwitchA (Root) --- Gi0/2 (cost 19) --- SwitchBSteps
- 1.Step 1: Enter privileged EXEC mode: enable
- 2.Step 2: Enter global configuration: configure terminal
- 3.Step 3: Enter interface configuration for Gi0/1: interface GigabitEthernet0/1
- 4.Step 4: Set the STP cost to 4 (default for 1 Gbps): spanning-tree cost 4
- 5.Step 5: Exit and verify: end, show spanning-tree
SwitchB# configure terminal SwitchB(config)# interface GigabitEthernet0/1 SwitchB(config-if)# spanning-tree cost 4 SwitchB(config-if)# end
Verify: Use `show spanning-tree` on SwitchB. The root port should be Gi0/1 with cost 4. Expected output snippet: 'Root ID Priority 32768, Address aaaa.bbbb.cccc ... Interface Gi0/1 (designated) ... Cost 4'
Watch out: If you set the cost too low on a port that is not directly connected to the root, it may become a designated port incorrectly. Always verify the STP topology after change.
Make a backup link less preferred to avoid forwarding loops
You have a primary 1 Gbps link and a backup 100 Mbps link between two switches. You want the backup link to be blocked unless the primary fails.
Topology
SwitchA --- Gi0/1 (1 Gbps, cost 4) --- SwitchB
SwitchA --- Gi0/2 (100 Mbps, cost 19) --- SwitchBSteps
- 1.Step 1: Enter privileged EXEC mode: enable
- 2.Step 2: Enter global configuration: configure terminal
- 3.Step 3: Enter interface configuration for the backup link: interface FastEthernet0/1
- 4.Step 4: Increase the cost to make it less preferred: spanning-tree cost 100
- 5.Step 5: Exit and verify: end, show spanning-tree
SwitchA# configure terminal SwitchA(config)# interface FastEthernet0/1 SwitchA(config-if)# spanning-tree cost 100 SwitchA(config-if)# end
Verify: Use `show spanning-tree` on SwitchA. The backup port should be in blocking state. Expected output: 'Interface Fa0/1 (alternate) ... Cost 100' and state 'BLK'.
Watch out: If you set the cost too high, the port may never become forwarding even when the primary fails if the root bridge path cost is also high. Ensure the cost is still reachable.
Troubleshooting with This Command
When troubleshooting STP issues, the `spanning-tree cost` command is often used to verify or adjust path costs. Healthy output from `show spanning-tree` shows consistent cost values that match the interface speed (unless manually overridden). Problem indicators include unexpected root port selection, loops, or ports stuck in blocking state.
Focus on the 'Cost' field per interface; if a port has an unusually high or low cost, it may be misconfigured. Common symptoms: a port that should be root port is alternate, or a port that should be designated is root. To diagnose, first check the root bridge with `show spanning-tree root`.
Then examine the path cost to the root from each switch. Use `show spanning-tree interface <interface>` to see the cost and state. A step-by-step diagnostic flow: 1) Identify the root bridge. 2) On non-root switches, check which port is root port (should have lowest cost to root). 3) If root port is not the expected one, compare costs. 4) Use `debug spanning-tree events` to see topology changes.
Correlate with `show cdp neighbors` to ensure link speeds are correct. If a manually configured cost is causing issues, remove it with `no spanning-tree cost` to revert to default. Also check for inconsistent costs in a VLAN environment with `show spanning-tree vlan <vlan>`.
Remember that STP recalculates after each change; use `show spanning-tree active` to see the current active topology.
CCNA Exam Tips
Remember default costs: 10Mbps=100, 100Mbps=19, 1Gbps=4, 10Gbps=2.
The 'spanning-tree cost' command is configured in interface configuration mode.
CCNA may test that manually set costs override default costs and influence root port selection.
Be able to interpret 'show spanning-tree' output to identify root ports and designated ports based on cost.
Common Mistakes
Setting the cost on the wrong interface (e.g., on an access port instead of trunk).
Forgetting that cost is per-VLAN; if PVST+ is used, cost applies to all VLANs on that interface.
Using too low a cost that causes unexpected root port changes or instability.
spanning-tree cost [value] vs show spanning-tree
Both commands are essential for Spanning Tree Protocol (STP) management, but they serve different purposes: one configures path cost on an interface, the other displays the overall STP state. They are often used together when tuning STP behavior and verifying the results.
| Aspect | spanning-tree cost [value] | show spanning-tree |
|---|---|---|
| Scope | Single interface | Global (all VLANs or specific VLAN) |
| Configuration Mode | Interface Configuration | Privileged EXEC (show command) |
| Persistence | Saved to running-config | Display only; no config change |
| Precedence | Overrides default cost based on speed | N/A (show command) |
| Typical Use | Tune path cost to influence root port selection | Verify STP topology, root bridge, port roles |
Use spanning-tree cost [value] when you need to manually adjust the path cost of a specific interface to influence STP root port or alternate port selection.
Use show spanning-tree when you need to verify the current STP state, including root bridge, port roles, and path costs for troubleshooting or validation.
Platform Notes
In IOS-XE (e.g., Catalyst 9000 series), the command syntax is identical: `spanning-tree cost <value>`. Output format is similar but may include additional fields like 'OperCost' for operational cost. In NX-OS (e.g., Nexus switches), the equivalent command is `spanning-tree cost <value>` under interface mode, but NX-OS uses a different default cost calculation (long method) and supports `spanning-tree cost <value> [port-channel]`.
For ASA firewalls, STP is not typically used; instead, use `priority` and `cost` in the context of EtherChannel or failover. In IOS-XR, STP is not supported; instead, use Ethernet OAM or other mechanisms. Between IOS versions, the cost range expanded from 1-65535 to 1-200000000 in later versions (12.2(25)SEC and later).
Always verify the version. On older IOS (12.x), the command may not accept values above 65535. The command is present in all IOS-based switches and routers that support STP, including Catalyst 2960, 3560, 4500, and 6500 series.
Related Commands
Practice for the CCNA 200-301
Test your knowledge with practice questions covering all CCNA 200-301 exam domains.
Practice CCNA 200-301 Questions