A VLAN allows a network administrator to logically divide a single physical switch (or group of switches) into multiple separate, isolated broadcast domains. Devices in different VLANs cannot communicate directly, even if they are connected to the same physical switch.
When a frame needs to traverse a link between two switches, the switch must indicate which VLAN the frame belongs to. IEEE 802.1Q inserts a 4-byte VLAN Tag into the Ethernet frame header, containing a 12-bit VLAN ID (supporting up to 4,096 VLANs). A Trunk Port carries traffic for multiple VLANs between switches.
For redundancy, switches are often connected in loops (if one link fails, traffic can use an alternate path). However, loops cause Broadcast Storms: a broadcast frame is forwarded endlessly around the loop, consuming all bandwidth and crashing the network within seconds.
STP automatically detects loops in the network topology and disables redundant links, creating a loop-free tree topology. If an active link fails, STP re-enables a previously disabled redundant link to restore connectivity.
Standard STP can take 30-50 seconds to converge after a topology change. RSTP dramatically reduces convergence time to under 6 seconds by introducing new port states and a faster handshake mechanism. RSTP is the standard in modern networks.