STP uses the concepts of root bridge, root ports, and designated ports to
establish a loop-free path through the network. The first step in creating the
loop-free spanning tree is to elect a root bridge. The root bridge is the
reference point that all switches use to establish forwarding paths that will
avoid loops in the Layer 2 network.
When a topology change occurs as a result of switch link state changes, the
root will send messages throughout the tree regarding the topology change. This
allows the CAM tables to adjust and to provide for a new path that may be used
toward end host devices.
Timer information is also sent by the root
bridge to non-root bridges, informing them of the intervals to use as the ports
transition through the spanning tree port states.
The root bridge
maintains the stability of the forwarding paths between all switches for a
single STP instance. A spanning tree instance is when all switches exchanging
BPDUs and participating in spanning tree negotiation are associated with a
single root. If this is done for all VLANs, it is called a Common Spanning Tree
instance. There is also a Per VLAN Spanning Tree (PVST) implementation that
provides one instance, and therefore one root bridge, for each VLAN.

BPDU Fields Associated with Root Bridge Election
The Bridge ID
(BID) and Root ID are each 8-byte fields carried in a BPDU. These values are
used to complete the root bridge election process. A switch identifies the root
bridge by evaluating Root ID field in the BPDUs it receives. The unique Bridge
ID of the root bridge will be carried in the Root ID field of the BPDUs sent by
each switch in the tree.

When a switch first boots and begins sending BPDUs, it has no knowledge of a
Root ID so it will populate the Root ID field of outbound BPDUs with its own
Bridge ID.
The switch with the lowest numerical BID will assume the role of root bridge
for that spanning tree instance. Upon receipt of BPDUs with a lower bridge ID
than its own, a switch will place the lowest value seen in all BPDUs into the
Root ID field information of its outbound BPDUs.
The Bridge ID Field
in the BPDU
Spanning tree operation requires that each switch have a
unique Bridge ID (BID). In the original 802.1D standard, the bridge ID was
composed of the Priority Field and the MAC address of the switch, and all VLANs
were represented by a Common Spanning Tree. Because (PVST) requires that a
separate instance of spanning tree run for each VLAN, the bridge ID field is
required to carry VLAN ID (VID) information. This is accomplished by re-using a
portion of the priority field as the Extended System ID to carry a VID.
To accommodate the Extended System ID, the original 802.1D 16-bit Bridge
Priority field is split into 2 fields resulting in these components in the
Bridge ID:

-
Bridge Priority – a 4-bit field still used to carry Bridge Priority.
Because of the limited bit count, priority is now conveyed in discreet values
in increments of 4096 rather than discreet values in increments of 1 as they
would be with the full 16-bit field available. The default priority, in
accordance with IEEE 802.1D, is 32,768, which is the midrange value.
-
Extended System ID – a 12-bit field carrying, in this case, the VID
for PVST.
-
MAC address – a 6-byte field with the MAC address of a single
switch.
By virtue of the MAC address, a bridge ID is always unique. When the
Priority and Extended System ID are appended to the switch MAC address, each
VLAN on the switch can be represented by a unique bridge identifier or Bridge
ID.
If no priority has been configured, every switch will have the same
default priority and the election of the root for each VLAN will be based on
MAC address. This is a fairly random means of selecting the ideal root bridge
and for this reason, it is advisable to assign a lower priority to the switch
that should serve as root bridge.