Spanning Tree Protocol (STP) was developed to prevent network loops by selectively blocking ports on switches. There have been several variants of STP over time as technologies changed. The original STP blocked all ports except one per switch to avoid loops. Later variants like PVST+ and RPVST+ support multiple instances of STP to allow port blocking on a per-VLAN basis. STP works by electing a root bridge and placing ports into different states - blocking, listening, learning, forwarding - to determine the best path to the root without creating loops.