spanning-tree vlan [id] root [primary/secondary]
A powerful IOS macro command used to rig the Spanning Tree Protocol (STP) election. Instead of manually guessing what Bridge Priority number to assign, this command inspects the network, calculates the current Root Bridge's priority, and automatically lowers the local switch's priority to guarantee it wins the election.
Quick Reference
Switch(config)#(+ VLAN ID)spanning-tree vlan [id] priority [value]Syntax Breakdown
| Role Option | Macro Calculation Behavior |
|---|---|
| primary | The switch checks the current Root Bridge's priority. • If the current root is sitting at the default 32768, this switch sets its own priority to 24576. • If another switch has already lowered its priority, this switch will calculate a priority that is exactly 4096 less than the current root to steal the crown. |
| secondary | Designates the switch as the backup Root Bridge. It hardcodes the local priority to 28672. This ensures it will beat all default switches (32768), but still lose to the primary root (24576). |
CLI Deployment Scenarios
Scenario 1: Securing the Core Architecture
You have a powerful Multilayer Core Switch. You must guarantee it becomes the center of the spanning tree so all traffic flows efficiently through the high-speed backplane.
Scenario 2: The Manual Priority Override
Instead of using the macro, you want to absolutely guarantee a switch remains the root bridge forever by hardcoding the lowest mathematically possible priority value.
CCNA Exam Gotchas
The 4096 Multiplier Rule
If an exam question asks you to manually set a spanning-tree priority, the value must be an exact multiple of 4096 (0, 4096, 8192, 12288, 16384, etc.). If you try to type spanning-tree vlan 10 priority 100, the CLI will reject it. This is because the other 12 bits in the 16-bit priority header are reserved for the System Extended ID (the VLAN number).
Preemption is Automatic
Unlike routing protocols (like HSRP) where you have to explicitly configure preemption, Spanning Tree preempts automatically. The moment a switch powers on with a superior (lower) priority, it instantly forces a network recalculation and steals the Root Bridge role.