Every company nowadays have redundancy and redundancy causes layer 2 loops which eventually becomes Broadcast storms. manageable switches used STP to avoid the layer 2 loops by blocking port number.
STP Election so that we will find which port will be locked.
- Find the Root Bridge [ Bridge ID = Lowest Priority + Lowest Mac address ] > Switch 1 will become Root Bridge.
- Cost towards Root Bridge
- Sender [ Bridge ID = Lowest Priority + Lowest Mac address ]

TTL - To Prevent Routing Loops

STP runs automatically to avoid the loops and block ports.
Layer 2 loop —causes- Broadcast Storm



spanning-tree mode rapid-pvst
spanning-tree vlan 2 priority 4096
show spanning tree
spanning-tree portfast default