This protocol prevents bridging loop created by redundant links within switch network. STP calculation will make switch/es block its own port so that the switch path is one straight line and not a loop.
This is perhaps the most confusing concept in switch, it is not extremely difficult but many terminologies and the method on how port/s is/are blocked is easily forgotten and misinterpreted by network engineers. Even experienced network engineers would at times confused with this protocol causing confusing debate during discussion.
The purpose of this post is to demystify STP and move ahead with RSTP and MSTP discussion, and to ask my colleagues and myself to refer to this post instead of insisting our misinterpreted fact. To appreciate RSTP and MSTP operation, we should first understand STP.
Root bridge
1. Root bridge has all its switch interfaces in forwarding state.
2. BPDU is originated from root bridge.
3. If there is topology changed switch sends topology changed notification (TCN) to root bridge. Root bridge then sends out BPDU with TC flag turned on to all switches.
Root bridge election
1. Bridge/Switch with the lowest bridge ID (BID) is elected as root bridge. Root bridge = bridge priority + MAC address. PERIOD
2. If bridge priority of switches are the same (32768), then lowest MAC address is the tie breaker for root bridge election.
Port roles
1. Desginated port – Root bridge has all its interfaces in designated port role. For non-root bridge it is the forwarding port that is not a root port. Designated port is in forwarding state.
2. Root port – The port that takes the lowest cost to reach the root bridge, in other words in the point of view of switch the “shortest” path to reach the root bridge.
3. Alternate port – This is the alternate path to the root bridge, if the existing root port fails alternate port becomes the root port.

Root port election
1. Lowest cost to the root bridge. In the above diagram all links have equal cost, hence the next condition can be the tie breaker. Port cost is adjustable in Cisco switch.
2. Lowest upstream BID, refer to diagram, Bridge mac 3333.0000.2222 has two upstream switches 1111.0000.2222 and 2222.0000.2222. Because all bridge priority is the same, mac address is used as the tie breaker. 1111.0000.2222 is the root bridge, its downstream switch (3333.0000.2222) port (gi0/1) will be the root port.
2. Lowest port priority, in Cisco default is 128, can be adjusted in Cisco switch. Port priority is locally significant between two connected switches.
3. If all port priority is the same, the lowest port ID (such as interface gi0/1) of the switch is the root port.
Port States
1. Disabled – Not a STP state. Switch interface is shutdown.
2. Blocking – Switch port does not send nor receive frames, no mac address is learned. This state is to prevent possible bridging loops during converging and is 20 second which is not adjustable in Cisco switch.
Blocking state only applies to switch port that is first initialized i.e. when the switch reboots or when the switch just turns on. Blocking state does not apply to topology changes due to link failure.
3. Listening – Switch listens to BPDU, hence it sends and receives BPDU to participate in root bridge election and port role election. No frames is sent nor received, no mac address is learned. Listening delay is 15 seconds.
4. Learning – Switch learns about switch roles (root or non-root) and port roles, can exchange (send and receive) BPDU, mac addresses can be recorded in CAM table but no frames is sent nor received. Learning delay is 15 seconds.
5. Forward – Forwarding delay = listening delay + learning delay = 30 seconds by default. Exchanges BPDU, learns mac addresses and exchanges frames. This is the only state that data frames is exchanged.
Listening and learning delay must be equal.
Cisco default STP timer
1. Hello time – 2 seconds. The interval a root bridge sends BPDU and the frequency of any switch sending TCN BPDU.
2. Max Age – 20 seconds. The time to preserve BPDU. BPDU that is beyond Max Age is outdated and is discarded.
3. Forward delay – 15 seconds. The delay timer for each Listening and Learning state.
STP topology change
Caused by: –
1. Forwarding state changes caused by link failure, port shutdown, link instability.
2. Blocking port transiting to forward state. Example when a new switch is introduced, the new switch just boots up, the ports are transiting from blocking state.
Operation: –
Step 1: A switch detects TC, sends TCN to root bridge.
Step 2: Root bridge sends BPDU to all switches with TC flag set.
Step 3: All switches receives BPDU with TC set reduce their own mac address table aging time to the forwarding delay time.
Step 4: Mac address table is flushed after mac address table aging time is up. Flushed mac address is re-learned during learning state and forwarding state.
Cisco Portfast
There are people saying portfast is to turn off STP, this is NOT true. Portfast port will not generate TCN during port link up and down. Portfast port will transit immediately to forward state skipping listening and learning states. Portfast port will cause bridging loop when connecting to non-host port of adjacent switch.
Demonstration

Default
Bridge priority default, port priority default and port cost as it is.
SW4-3560-2#show spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 32769 Address 001a.6ce4.2e00 This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 001a.6ce4.2e00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 300 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Desg FWD 4 128.1 P2p Gi0/2 Desg FWD 4 128.2 P2p SW4-3560-2# Sw2-3560#show spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 32769 Address 001a.6ce4.2e00 Cost 4 Port 1 (GigabitEthernet0/1) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 081f.f3a0.ec00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 300 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Root FWD 4 128.1 P2p Gi0/2 Altn BLK 4 128.2 P2p Sw2-3560#
001a.6ce4.2e00 is the root bridge by default. Because MAC address was used as a tie breaker for root bridge election since bridge priority of both switches is the same.
All root bridge ports are designated ports. 081f.f3a0.ec00 is the non-root bridge, interface gi0/1 is elected as the root port, because port ID is used as tie breaker, lowest upstream port ID wins.
Influence root bridge election by changing bridge priority
Bridge ID = Bridge priority + mac address. PERIOD. No arguments about this anymore. Lowest bridge ID wins root bridge election. If bridge priority is the same, mac address is the tie breaker.
Sw2-3560#show spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 32769 Address 001a.6ce4.2e00 Cost 4 Port 1 (GigabitEthernet0/1) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 081f.f3a0.ec00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Root FWD 4 128.1 P2p Gi0/2 Altn BLK 4 128.2 P2p Sw2-3560#
By default 001a.6ce4.2e00 is the root bridge because 081f.f3a0.ec00 is higher than the root bridge mac address. To influence root bridge election, bridge priority can be changed using macro command spanning-tree vlan 1 root primary
or just manually specify the bridge priority spanning-tree vlan 1 priority 4096
Sw2-3560(config)#spanning-tree vlan 1 root primary Sw2-3560(config)#do sh spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 24577 (priority 24576 sys-id-ext 1) Address 081f.f3a0.ec00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Desg FWD 4 128.1 P2p Gi0/2 Desg LIS 4 128.2 P2p Sw2-3560(config)#
081f.f3a0.ec00 has a lower bridge ID than 001a.6ce4.2e00 because bridge priority is lowered. Topology changed is triggered, no blocking state, only Listening, Learning and Fowarding state. Gi0/2 is transiting from listening to learning state which will by default take 15 seconds as stated by default Forward delay timer.
Sw2-3560(config)#do sh spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 24577 (priority 24576 sys-id-ext 1) Address 081f.f3a0.ec00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Desg FWD 4 128.1 P2p Gi0/2 Desg LRN 4 128.2 P2p
From learning to forwarding takes another 15seconds based on default forward delay timer.
Sw2-3560(config)#do sh spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 24577 (priority 24576 sys-id-ext 1) Address 081f.f3a0.ec00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Desg FWD 4 128.1 P2p Gi0/2 Desg FWD 4 128.2 P2p Sw2-3560(config)#
Influence root port election by adjusting port cost
The root port is the port that has the “shortest” path to root bridge, so to the perception of a switch a higher bandwidth link which has the lower port cost by default should be the root port, because it takes a shorter time to reach the root bridge.
Influence root port election of non-root bridge by adjusting port cost on non-root bridge.
SW4-3560-2#sh spanning-tree vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 Cost 4 Port 1 (GigabitEthernet0/1) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 001a.6ce4.2e00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 300 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Root FWD 4 128.1 P2p Gi0/2 Altn BLK 4 128.2 P2p SW4-3560-2#
Gi0/1 of non-root bridge is the default root port. Adjust the local switch port gi0/1 cost to be higher than gi0/2 will cause gi0/2 to be elected as root bridge.
SW4-3560-2(config)#int gi0/1 SW4-3560-2(config-if)#spanning-tree vlan 1 cost 10 SW4-3560-2(config-if)#do sh spann vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 Cost 4 Port 2 (GigabitEthernet0/2) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 001a.6ce4.2e00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Altn BLK 10 128.1 P2p Gi0/2 Root LIS 4 128.2 P2p SW4-3560-2(config-if)# SW4-3560-2(config-if)#do sh spann vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 Cost 4 Port 2 (GigabitEthernet0/2) Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 32769 (priority 32768 sys-id-ext 1) Address 001a.6ce4.2e00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Altn BLK 10 128.1 P2p Gi0/2 Root FWD 4 128.2 P2p SW4-3560-2(config-if)#
Influence root port election by changing upstream port priority
SW4-3560-2#sh spanning-tree vlan 1 | beg Inter Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Root FWD 4 128.1 P2p Gi0/2 Altn BLK 4 128.2 P2p SW4-3560-2#
Gi0/1 is the default root port. To influence gi0/2 to be elected as root port, port priority can be adjusted of upstream switch.
Sw2-3560#conf t Sw2-3560(config)#int gi0/2 Sw2-3560(config-if)#spanning vlan 1 port-priority 16 Sw2-3560(config-if)#do sh spanning vlan 1 VLAN0001 Spanning tree enabled protocol ieee Root ID Priority 24577 Address 081f.f3a0.ec00 This bridge is the root Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Bridge ID Priority 24577 (priority 24576 sys-id-ext 1) Address 081f.f3a0.ec00 Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec Aging Time 15 sec Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Desg FWD 10 128.1 P2p Gi0/2 Desg FWD 4 16.2 P2p Sw2-3560(config-if)#
Upstream port priority adjustment influences downstream switch root port election.
SW4-3560-2#show spanning-tree vlan 1 | beg Interface Interface Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- Gi0/1 Altn BLK 4 128.1 P2p Gi0/2 Root FWD 4 128.2 P2p SW4-3560-2#