Switches and Bridges use STP to prevent bridging loops. It is actually a fairly complex process, so the we will only discuss an overview here.
First, two timers are decided upon – a “Hello” timer, and a “MaxAge” timer. Then, all devices are originally assigned as a root, until they collectively decide which one is the root. Then the root begins sending out exploratory CBPDU’s (Configuration Bridge Protocol Data Units) to the devices – one every “hello time”. The unit with the lowest cost path to the root unit becomes a “designated” or “root port” unit and is placed in the forwarding state.
the root sends a CBPDU, cost 0 out all it’s interfaces – this is repeated every Hello time. The default Hello time is 2 seconds
the bridges connected to the root add their cost and send CBPDU’s out their other ports (not the port connected to the root)
repeat step 2 to each bridge in the network – they learn the lowest cost paths to the other bridges, so that each bridge will use just one path to each other bridge
The proccess continue forever – if a bridge does not receive a CBPDU within the MaxAge time, it restarts the spanning tree process with other bridges
There are 4 states (2 are Stable, and 2 are Transitionary) :
Stable States - Blocking and Forwarding
Transitionary States – Listening and Learning