**How STP elects the Root Bridge**- STP elects the root bridge by comparing Bridge IDs (BIDs) carried in BPDUs. The lowest BID wins.- Bridge ID = Bridge Priority (16-bit) + System ID Extension (VLAN ID) + MAC address. Effectively compared as: lowest priority → lowest MAC as tiebreaker.- BPDUs propagate from the current root; switches select paths based on cumulative path cost to that root.**Port role determination**- Root Port (RP) - On each non-root switch, the port with the lowest cumulative path cost to the root becomes the Root Port. - Tie-breakers: lower received root path cost, then lower sending bridge ID, then lower sending port ID.- Designated Port (DP) - For each network segment, the port on the switch that offers the lowest path cost to the root becomes the Designated Port and forwards traffic for that segment. - If equal cost, the switch with lower BID wins; if still tied, lower port ID wins.- Blocked Port - Any port that is neither RP nor DP is put into Blocking to prevent loops; it still listens for BPDUs.**Path cost influence**- Path cost is cumulative: each link contributes a cost value based on link speed. STP selects ports based on the lowest total cost to the root.- You can influence selection by changing either: - Interface cost (per-port): e.g., lower the cost on desired links so they become preferred. - Bridge priority (global per VLAN): lower priority makes the switch more likely to be root.**Commands / Example to force a switch to be root (Cisco IOS examples)**- Make this switch the primary root for VLAN 10:bash
configure terminal
spanning-tree vlan 10 root primary
end
- Or set priority explicitly (lower is better; default 32768; valid increments of 4096):bash
configure terminal
spanning-tree vlan 10 priority 4096
end
- Set an interface path cost to prefer a link:bash
configure terminal
interface GigabitEthernet1/0/1
spanning-tree cost 2000
end
**Practical notes**- Use “root primary/secondary” helpers on Cisco to automate safe priority values.- When planning changes, account for VLAN-specific BIDs (system ID) and avoid abrupt topology changes during production hours.