All of the switches in the layer 2 network, participating in STP, gather information on other switches in the network through an exchange of BPDUs. The exchange of messages results in these actions:
Election of a unique root switch for each spanning tree instance
Election of a designated switch for every switched LAN segment
Removal of loops in the switched network by blocking layer 2 interfaces connected to redundant links
The switch with the highest switch priority (the lowest numerical priority value) is elected as the root switch. If all of the switches are configured with the default priority (32768) for a VLAN with ID 1 (that is, a bridge priority of 32769), then the switch with the lowest MAC address becomes the root switch. The switch priority value occupies the most significant bits of the bridge ID. The root switch is the logical center of the STP topology in a switched network. Redundant paths to the root are put in STP blocking mode.
BPDUs contain information about the sending switch and its ports. The information includes switch and port MAC addresses, switch priority, port priority, and path cost. The STP uses this information to elect the root switch, the root port for the switched network, the root port, and the designated port for each switched segment.