Spanning Tree Protocol - 802.1d

For preventing loops in a L2 network, STP goes through three stages:
1. Elect Root Bridge that acts like the center of network.
2. Elect one Root Port on each non-Root Switch - ports that are closest to the Root Switch.
3. Elect one Designated Port per Segment.

Initially when a switch comes up, all its ports start sending out BPDUs. But when on a certain port switch receives a BPDU from other switch which has better values e.g. lesser Bridge ID, it stops sending its own BPDUs from that port.

1. Root Bridge:
The bridge with the least value of Bridge ID is selected as a root bridge. Once a non-Root bridge receives BPDU from Root, it sends out BPDUs showing that Switch as the Root. Other downstream switches do the same as well. Note that in the BPDU Root BID shows the MAC of root bridge and Sender BID is the sending switch itself. MAC can be taken from the backplane or the supervisor.

2. Root Ports:
All non-Root switches select Root Ports. Root ports are the ones that have least cost to get to the Root Switch. Costs are based on port speed and can be configured/altered. Costs are added as the BPDU enters the switch port.

3. Designated Ports:
Each Segment in a switched network has to have one Designated Port (DP). DP are chosen based on cumulative cost to the Root Switch. All ports on Root Switch are DP. If there is a tie on cost for two ports in a segments, the port sending out BPDUs with lower Sender Bridge ID/MAC is chosen to the DP. If there is a tie on that then Lowest Port Id is chosen as a tie breaker.

All ports that are not Root or DP are put into Blocked state.