Spanning Tree Protocol and Loop Prevention
Root election, roles, and safeguards
Spanning Tree prevents Layer 2 loops by electing one root bridge and placing redundant ports into a blocking or alternate role. RSTP/MSTP converge faster than legacy 802.1D. The root is elected by lowest bridge priority, then lowest MAC; path cost then determines root port selection. MSTP adds regions: name, revision, and VLAN-to-instance mapping must match exactly. Edge/PortFast ports skip listening/learning for endpoints, but must be protected with BPDU guard. Root guard prevents downstream switches from becoming root; loop guard protects against unidirectional BPDU loss; BPDU filter should be used sparingly.
Traps: thinking the switch with the highest priority becomes root; mismatched MSTP region parameters; enabling BPDU guard on uplinks; expecting STP to fix a LAG misconfiguration; and ignoring topology change notifications. Also remember that a blocked port still receives BPDUs.
Worked example/rule of thumb: Two switches have priorities 32768 and 4096; the 4096 switch becomes root regardless of MAC. To force a core pair as root, set priority 0 or 4096 on primary and 8192 on secondary. Rule: configure root priority deliberately on the core, enable BPDU guard on all edge ports, and never rely on default timers for fast convergence.