STP uses the Spanning Tree Protocol (STP) to prevent network loops. STP elects a root bridge and places its ports in forwarding state. Other non-root bridges determine the best path to the root bridge and place that port in forwarding state. On shared links, the switch with the lowest cost to the root is placed in forwarding state while other ports are blocked. For example, if SW1 has the lowest ID it is elected root bridge. SW2 and SW3 select the lowest cost ports to SW1 as the root ports and place them in forwarding state, blocking the other shared link port. BPDUs are exchanged to share topology information and elect the root bridge.