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 in order to provide redundancy.
To better understand the importance of STP and how STP prevents broadcast storms on a network with redundant links, consider the following example:
SW1 sends a broadcast frame to SW2 and SW3. Both switches receive the frame and forward the frame out every port, except the port the frame was received on. So SW2 forwards the frame to SW3. SW3 receives that frame, and forwards it to SW1. SW1 then again forwards the frame to SW2! 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 in blocking state.
So, our toplogy above could look like this:
In the topology above, STP has placed one port on SW3 in the blocking state. That port will no longer process any frames except the STP messages. If SW3 receives a broadcast frame from SW1, it will not forward it out the port connected to SW2.