Spanning Tree Protocol (STP) is a network protocol designed to prevent layer 2 loops. It is standardized as IEEE 802.D protocol. STP blocks some ports on switches with redundant links to prevent broadcast storms and ensure loop-free topology. With STP in place, you can have redundant links between switches to provide redundancy.
To better understand the importance of STP and how to use STP to prevent broadcast storms on a network with redundant links, consider the following example.
SW2 sends a broadcast frame to SW1 and SW3. Both switches receive the frame and forward the frame out every port, except the port the frame was received at. So, SW1 sends the frame to SW3. SW3 receives the frame, and sends the frame back to SW2! SW2 then agains forwards the frames to SW1! The same thing also happens in the opposite direction. Without STP in place, these frames would loop forever. STP prevents loops by placing one of the switch ports into blocking state. So, our toplogy above could look like this:
In the topology above, STP has placed one of the SW3 ports into blocking state. That way, SW3 will receive a broadcast frame only from SW1, and it will not forward that frame out ports connected to SW1 and SW2, because one port is blocked by STP, and another port was the port the frame was received on.
NOTE – STP enables layer 2 redundancy. In the example above, if the link between SW3 and SW1 fails, STP would converge and unblock the port on SW3.