STP establishes a tree with root and branches. (In this section, we use switches and bridges interchangeably, knowing that they performs the same function -- a bridge with more than 2 ports can also be called switch.) The primary decision-making switch in an STP environment is called the root bridge. The frames flows out from the root bridge to form a logical branched network. All switches in a LAN participating in STP branch from the root switch/bridge port.
The first problem the STP must solve is to decide where the spanning tree begins by electing a root bridge or switch port. The root bridge is used to build a reference point in the network, with which all paths from all bridges must be traceable back to the root bridge. All paths not needed to trace back to the root bridge are placed in backup mode. Each switch in the network exchange information about the network topology with neighbor switches in the same network through a data units called bridge protocol data units, or BPDUs.
Bridge Protocol Data Units (BPDUs)
BPDUs are data messages exchanged between the switches and bridges within an extended LAN using the STP. A BPDU frame contains information on originating switch's port, MAC address, switch port priorities and cost to reach root bridge and ensure that the data ends up where it was intended to go.
SPT assign each switch in the extended LAN a unique bridge ID. The bridge ID contains bridge priority followed by MAC address, which is the 48 byte hardware address of the NIC. By default, all STP switches have a bridge priority value of 32,768. After the exchange of BPDUs, the switch with the lowest priority value becomes the root bridge.
SPT have to answer the question of among many possible paths from a switch to root bridge, which one is the the lowest cost path. The root port represent a switch's lowest cost path to the root bridge.
The cost of a switch is based on the number of network segments a frame has to traversal in order to reach its destination. Besides switch cost, each individual ports on the switch also have a cost called port cost. The port cost is determined by the network bandwidth -- the faster the port, the lower its cost. For example, the default IEEE cost for Fast Ethernet (100Mbps) is 10 and Ethernet (10Mbps) is 100. A switch uses the port cost to determine the root port for each switch in the network. All nonroot bridges have one root port that is used as the link over which data traffic is forwarded across the network; the nonroot ports are either standby or disabled.
On a spanning-tree network, each network segment has one port identified as the designated port. The designated port is the port that is the single interface to forward traffic to the root bridge. Since there could be multiple bridges connected to a segment, on each segment, STP need to select one of the connected bridge ports as the designated port. This is always the switch port on the segment with the lowest port cost. When two ports has the same port cost, MAC addresses are used to determine the designated port, port with lower MAC address is selected as designated port. Once STP elected the designated port for a network segment, the designated port is put to forwarding mode, while the rest of the ports connected to network segment are put to blocking mode. As a result, all traffic from this network segment will exit the segment via the designated port.
As you can see from above, root port and designated port are elected based on the same criteria -- the lowest port cost, which is decided by the network link connected to it. Therefore once you find a root port, on the other side of the network link, you will find a designated port.
[ICND1 and ICND2 break down]