STP uses the following process to maintain a loop-free network:
Root Bridge Election:
The protocol selects a single switch to act as the root bridge. This decision is based on the switch with the lowest bridge ID, which is a combination of a priority value and the switch’s MAC address.
Path Selection:
STP calculates the shortest path from each switch to the root bridge. The cost of a path is determined by the bandwidth of the links. Higher bandwidth links have lower costs.
Port Roles:
Each port on a switch is assigned a role:
Root Port: The port with the shortest path to the root bridge.
Designated Port: The port on each segment that provides the shortest path to the root bridge.
Blocked Port: Any port not selected as a root or designated port is placed in a blocking state to prevent loops.