# Spanning tree election

> Source: Courseiva IT Certification Glossary — https://courseiva.com/glossary/spanning-tree-election

## Quick definition

Spanning tree election is how network switches choose a leader switch and then decide which paths to keep open and which to block. This prevents data from looping endlessly around the network. The election happens automatically when switches first connect. It also reoccurs if the network topology changes.

## Simple meaning

Imagine a busy office hallway with multiple routes to the same meeting room. If everyone takes different paths, some routes get clogged and people keep circling around, never reaching their destination. Spanning tree election is like appointing a traffic manager who decides: this is the main hallway, these are allowed shortcuts, and these doors are locked to prevent anyone from going in circles. In a computer network, switches are the traffic managers. They send messages back and forth to decide which switch is the most central and reliable, called the root bridge. Once everyone agrees on the root, each switch calculates the shortest path to that root. All other paths are disabled, or blocked, so data never travels in a loop. The election happens automatically when the network starts up or whenever a cable is unplugged, a switch fails, or a new switch is added. The goal is to keep the network working with no delays and no duplicate data. In everyday terms, think of a group of friends in a park trying to find the best way to get to the ice cream truck. They elect one person to be the leader, then everyone follows the leader's path. If that path gets blocked, they quickly choose a new leader and a new path. Spanning tree election is exactly that, but for network switches and data packets.

## Technical definition

The Spanning Tree Protocol (STP), defined in IEEE 802.1D, is a network protocol that ensures a loop-free topology in Ethernet networks. The spanning tree election is the process through which switches elect a single root bridge and then determine the best loop-free path to that root. The election begins when switches power on and exchange Bridge Protocol Data Units (BPDUs). Each BPDU contains a bridge ID, which is a combination of a configurable priority value (0-65535, default 32768) and the switch's MAC address. The switch with the lowest bridge ID is elected as the root bridge. Ties are broken by comparing MAC addresses: the lowest MAC address wins. After the root bridge is selected, every non-root switch calculates its shortest path to the root based on path cost. Path cost is determined by the speed of the link; for example, a 10 Mbps link has a cost of 100, while a 1 Gbps link has a cost of 4. Each switch then elects one of its ports as the root port, which is the port with the lowest path cost to the root bridge. On each network segment (collision domain), switches elect a designated port, which is the port on that segment with the lowest path cost back to the root. All other ports become blocked or alternate ports. The root bridge itself has all its ports as designated ports, except on the root bridge there is no root port. The election also determines roles for ports: root port (RP), designated port (DP), and alternate/blocked port. STP has several states for ports: blocking, listening, learning, and forwarding. The topology change mechanism allows the network to reconverge when a link fails or a new switch is added. Rapid Spanning Tree Protocol (RSTP, IEEE 802.1w) accelerates this process with faster convergence times. In RSTP, port roles include root, designated, alternate, and backup, and the election process uses proposal-agreement handshakes instead of timer-based transitions. STP and RSTP are fundamental to enterprise network design to prevent broadcast storms and MAC table instability caused by loops. In modern data center environments, protocols like Multiple Spanning Tree Protocol (MSTP, IEEE 802.1s) allow for multiple VLANs to be mapped to different spanning tree instances, improving load balancing. The election process is crucial because without it, a single broadcast would circulate forever, consuming bandwidth and crashing switches.

## Real-life example

Think of a small town with several intersections and traffic lights. There are multiple ways to drive from your house to the grocery store. Without any rules, some drivers might take shortcuts that cause traffic jams, and others might end up driving in circles around the same block without ever reaching the store. Now imagine the town decides to form a traffic committee. They pick one person to be the central traffic controller, or the root leader. This person determines the best main road from each neighborhood to the store. Then, the committee instructs everyone to only use that main road and a few approved short roads. All other roads that could create loops are closed with barriers. If the main road gets blocked by construction, the committee quickly picks a new central controller and a new main road. In network terms, the switches are like the traffic committee. The root bridge is the central traffic controller. The root port on each switch is the best entry point to the main road. The designated port on each network cable is the road that is kept open. Blocked ports are the closed roads with barriers. Spanning tree election is the meeting where the committee votes on who is the best central controller based on their experience (priority) and their unique identifier (MAC address). After that, they each calculate the shortest, loop-free path to that controller and block everything else. This real-life analogy shows how the election prevents chaos, ensures everyone can reach the store, and quickly adapts to changes without causing gridlock.

## Why it matters

In any IT network with more than one switch, spanning tree election is critical for reliability and performance. Without it, redundant links that are meant to provide backup would actually cause data loops, broadcast storms, and complete network failure. Professionals need to understand the election to design networks that are both resilient and efficient. When configuring switches, you might need to manually set the bridge priority to influence which switch becomes root, often placing the root in the core of the network for optimal traffic flow. If the election is left to defaults, an older or slower switch in a closet could become root, causing inefficient paths and unnecessary latency. Understanding election also helps when troubleshooting intermittent network issues. If users report slow connections or packet loss, the problem could be due to a topology change that triggered a reconvergence, or perhaps a switch with a very low priority accidentally became root due to a misconfiguration. Spanning tree election also matters for security. An attacker could plug in a rogue switch with a very low bridge priority, forcing the network to elect it as root and potentially intercept traffic. Therefore, features like BPDU Guard and Root Guard are used to protect the election process. Mastering spanning tree election is not just an exam topic; it is a daily reality for network administrators who need to keep corporate networks stable, secure, and fast.

## Why it matters in exams

Spanning tree election is a core topic in many entry-level and intermediate IT certification exams, including CompTIA Network+ (N10-008), Cisco CCNA (200-301), and Juniper JNCIA-Junos. In CompTIA Network+, the exam objectives cover STP concepts, the purpose of blocking loops, and basic understanding of root bridge election. You may see a question about why redundant links are used and how STP prevents loops. For the CCNA 200-301 exam, spanning tree election is a major topic under the Network Access domain. Cisco expects you to know the election process in detail, including how bridge priority and MAC address determine the root bridge, how port roles (root, designated, alternate) are assigned, and how port states (blocking, listening, learning, forwarding) work. You might encounter multiple-choice questions asking which switch becomes root based on given priority and MAC values, or which port on a switch will be the root port given a topology diagram. Troubleshooting questions may describe a network with connectivity issues and ask you to identify that a misconfigured priority caused the wrong root bridge. In the JNCIA-Junos exam, you need to understand the same principles, often applied in the context of Juniper's implementation of RSTP and MSTP. The exam could ask about the difference between STP and RSTP election timers or about the BPDU format. Regardless of the vendor, the underlying theory of election based on bridge ID remains constant. Questions often present a scenario with multiple switches and ask you to calculate the root bridge, the root port on a specific switch, or the designated port on a segment. You must be prepared to apply the election rules step by step: first compare bridge priorities, then MAC addresses, then compare path costs. Exam traps often involve giving two switches the same priority, so you must remember that the lowest MAC address wins. Also, be careful with path cost values for different link speeds, as the standard values changed with the introduction of faster Ethernet (e.g., 1 Gbps cost = 4 or 19 depending on the standard used). Understanding spanning tree election is not optional for these certifications; it is a fundamental skill that appears in at least 5-10% of the questions.

## How it appears in exam questions

Exam questions about spanning tree election typically fall into three categories: configuration, scenario-based calculation, and troubleshooting. In configuration questions, you might be asked to choose the correct command to set the bridge priority on a Cisco switch, such as 'spanning-tree vlan 1 priority 4096'. Or you could be asked what value to set to ensure a specific switch becomes the root bridge. The answer will involve choosing the lowest priority among the options, or using the 'root primary' macro. Scenario-based calculation questions often present a diagram with four or five switches, each with a given bridge priority and MAC address, and links with specific speeds. You will be asked: 'Which switch becomes the root bridge?', 'Which port on Switch C is the root port?', or 'Which port on the segment between Switch A and Switch B is the designated port?' To answer correctly, you must apply the election rules: first compare bridge priorities, then MAC addresses, then for root port election, compare path cost, then neighbor bridge ID, then neighbor port ID. Troubleshooting questions describe a network symptom, such as users in one VLAN experiencing intermittent disconnects, and a show output like 'show spanning-tree' from a switch. You might see that a switch in the distribution layer has been elected root instead of the core switch, causing suboptimal paths. The answer would be to identify that the distribution switch has a lower priority than intended, and the fix is to increase its priority or configure the core switch with a lower priority. Another common question involves BPDU Guard. You are given a scenario where a user plugs in a consumer switch in their office, and the network becomes unstable. The question asks: 'What feature should be enabled on the access port to prevent this from affecting the spanning tree election?' The correct answer is 'Spanning-tree portfast bpduguard enable'. Also, questions about RSTP election are common. You may be asked to identify the difference between STP and RSTP in terms of convergence time, or to name the RSTP port role that replaces the STP blocking state for alternate paths. In all these question types, careful reading of the provided values and topology is essential. Many learners miss points because they forget to compare MAC addresses after identical priorities, or they use the old path cost values instead of the newer ones for 10 Gbps links.

## Example scenario

You are setting up a small office network with three switches: Switch A, Switch B, and Switch C. Switch A is connected to Switch B with a 1 Gbps link, and also to Switch C with a 1 Gbps link. Switch B is connected to Switch C with a 100 Mbps link. The default bridge priority is 32768 for all switches. Switch A has a MAC address of aaaa.bbbb.cccc, Switch B has a MAC address of aaaa.bbbb.dddd, and Switch C has a MAC address of aaaa.bbbb.eeee. When you power on all three switches simultaneously, the spanning tree election process begins. First, the switches exchange BPDUs to elect a root bridge. Since all have the same default priority (32768), the tie is broken by comparing MAC addresses. The lowest MAC address is aaaa.bbbb.cccc, so Switch A becomes the root bridge. Now, every other switch calculates its shortest path to Switch A. Switch B is directly connected to Switch A via a 1 Gbps link, which has a cost of 4. That is the best path for Switch B, so its port connected to Switch A becomes the root port. Similarly, Switch C is directly connected to Switch A via a 1 Gbps link, also cost 4, so that port becomes its root port. On the link between Switch B and Switch C, an election for the designated port takes place. The designated port is the port on that segment that has the lowest path cost back to the root. The path cost from Switch B to the root via its root port is 4. The path cost from Switch C to the root via its root port is also 4. In this case, the tie is broken by comparing the bridge ID of the two switches. Switch B has the lower MAC address (aaaa.bbbb.dddd compared to aaaa.bbbb.eeee), so Switch B's port on that link becomes the designated port (DP). Switch C's port on that link becomes an alternate port, which is placed in blocking state to prevent a loop. The final topology is loop-free: all traffic between Switch B and Switch C must go through Switch A. If the link between Switch A and Switch C fails, the election process will detect the loss of BPDUs, and Switch C's alternate port to Switch B will transition through listening and learning states to forwarding, restoring connectivity after a delay of about 50 seconds (with classic STP). This scenario illustrates the entire election process in a simple three-switch network.

## Common mistakes

- **Mistake:** Thinking that the switch with the highest bridge priority becomes root.
  - Why it is wrong: The election selects the switch with the lowest bridge priority as root. A higher priority number means it is less likely to be elected.
  - Fix: Remember: root = lowest numeric priority value. For example, a priority of 4096 beats 32768.
- **Mistake:** Assuming that the root port is chosen solely based on the speed of the directly connected link.
  - Why it is wrong: The root port is the port with the lowest total path cost from that switch to the root bridge, which includes the cost of all links in the path, not just the first link.
  - Fix: Calculate the cumulative path cost from your switch all the way to the root bridge, not just the immediate link cost.
- **Mistake:** Forgetting to compare neighbor bridge IDs when path costs are equal during designated port election.
  - Why it is wrong: When two switches on the same segment have the same path cost to the root, the one with the lower bridge ID (priority + MAC) wins the designated port election. Many learners stop at path cost.
  - Fix: Always apply tie-breakers in order: lowest path cost, then lowest neighbor bridge ID, then lowest neighbor port ID.
- **Mistake:** Believing that all switches must have different bridge priorities for an election to happen.
  - Why it is wrong: Default priorities are often identical, but the election uses the MAC address as a tiebreaker. Switches with the same priority still elect a root based on the lowest MAC address.
  - Fix: Know that the bridge ID is a combination of priority and MAC. Even with equal priorities, the MAC address ensures a unique root is elected.
- **Mistake:** Confusing root bridge election with root port election.
  - Why it is wrong: Root bridge election happens once network-wide to pick one switch. Root port election happens on every non-root switch to pick the best path back to the root. They are different processes.
  - Fix: Think globally for root bridge, locally for root port. The root bridge has no root port.

## Exam trap

{"trap":"In a question, two switches have the same priority and the same MAC address (which is impossible in real networks). The question asks which switch becomes root. The trap is that learners may apply the MAC address tiebreaker, but the intent is to realize that identical MACs cannot occur, so the question is flawed or they need to look for another distinguishing factor like a configured VLAN mapping.","why_learners_choose_it":"Learners often rush to apply the rule 'lowest MAC wins' without first confirming that the scenario is physically possible. They pick the first switch based on MAC, ignoring that the question may be testing their understanding that MAC addresses are unique.","how_to_avoid_it":"Always question the plausibility of the given data. If two switches appear to have the same MAC, remember that is unrealistic. The correct answer might be that the configuration is invalid, or that the network cannot function. More commonly, exam traps use very similar priorities but different MACs, and you must compare them accurately."}

## Commonly confused with

- **Spanning tree election vs Root bridge:** Root bridge is the specific switch elected as the central reference point in a spanning tree domain. The spanning tree election is the overall process that determines the root bridge, but the root bridge is the outcome, not the process itself. (Example: Think of a presidential election (the process) versus the president (the outcome). The election is the voting, and the root bridge is the winner.)
- **Spanning tree election vs Spanning tree protocol (STP):** STP is the entire protocol that includes the election, port roles, BPDUs, and loop prevention. Spanning tree election is just one phase of STP. STP covers the full lifecycle from election to blocking and forwarding. (Example: STP is like the whole game of chess. The election is just the first move where players decide who goes first.)
- **Spanning tree election vs Rapid Spanning Tree Protocol (RSTP):** RSTP is an evolution of STP that speeds up the election and convergence process. While both include an election, RSTP uses a proposal-agreement handshake instead of timers, resulting in faster transition to forwarding state. (Example: STP election is like mailing in a ballot and waiting a week for results. RSTP election is like voting electronically and getting results in seconds.)

## Step-by-step breakdown

1. **Initial State** — When switches power on, all ports are in a blocking state. They listen for BPDUs from other switches but do not forward traffic yet. This prevents any loops from forming before the election is complete.
2. **BPDU Exchange Begins** — Every switch starts sending BPDUs out of all its ports. The BPDU contains the switch's own bridge ID (priority + MAC) and a root ID, initially set to itself. Switches listen to BPDUs from neighbors and compare the root IDs received.
3. **Root Bridge Election** — Each switch compares the root ID in received BPDUs to its own. If it sees a lower bridge ID from a neighbor, it stops claiming to be root and starts advertising that neighbor's ID as the root. Eventually, all switches agree on the single switch with the lowest bridge ID. That switch becomes the root bridge.
4. **Root Port Election on Non-Root Switches** — Every non-root switch now calculates the total path cost to the root bridge using the cost of each link. The port with the lowest cumulative path cost becomes the root port (RP) on that switch. If multiple ports have equal cost, the switch chooses the port connected to the neighbor with the lowest bridge ID, then lowest port ID.
5. **Designated Port Election on Each Segment** — On each network segment (a cable connecting two switches), the two switches compare their path cost to the root. The switch with the lower path cost wins the right to have its port be the designated port (DP) on that segment. The other switch's port becomes an alternate (blocked) port. The root bridge always has designated ports on all its active segments.
6. **Port State Transition** — Once roles are assigned, alternate ports remain in blocking state. Root and designated ports transition through listening (15 seconds), learning (15 seconds), and finally forwarding. RSTP speeds this up with a proposal-agreement handshake, reducing time to a few seconds.

## Practical mini-lesson

Spanning tree election is not just a theoretical exam topic; it is a daily reality for network engineers. In practice, you must understand how to influence the election to optimize traffic flow. Most networks have a three-tier design: core, distribution, and access. You typically want the root bridge to be in the core layer because traffic from all access switches should flow through the core. To achieve this, you manually lower the bridge priority on core switches. For example, on a Cisco switch you might use 'spanning-tree vlan 1 priority 4096' or the macro 'spanning-tree vlan 1 root primary'. The macro automatically sets the priority to 24576 if the current root has a priority of 32768, ensuring your switch becomes the new root. On Juniper devices, you configure the priority under the spanning-tree hierarchy with 'set protocols spanning-tree bridge-priority 4096'. You must also think about VLANs. With Per-VLAN Spanning Tree (PVST+), each VLAN has its own election. You can balance traffic by making different switches root for different VLANs. For instance, set Switch A as root for VLAN 10 and Switch B as root for VLAN 20. This allows traffic for different VLANs to take different paths, using all links. A common mistake in practice is forgetting to configure PortFast and BPDU Guard on access ports connected to end devices. PortFast makes the port transition directly to forwarding, bypassing the election delay. BPDU Guard shuts down the port if a BPDU is received, preventing an unauthorized switch from participating in the election and potentially becoming root. In production, you might also use Root Guard to prevent a misconfigured switch from becoming root. If you connect a new switch with a very low priority, Root Guard places the port into a root-inconsistent state, preserving your intended root bridge. Another practical aspect is understanding convergence time. In classic STP, a link failure causes a 30-50 second outage while the election reoccurs. This is unacceptable in modern networks. Therefore, RSTP or MSTP should be used. When implementing RSTP, the election still happens, but convergence is near-instantaneous (a few seconds). You need to ensure all switches in the network support the same STP variant, or at least have a common interpretation, or you may have interoperability issues. Finally, monitoring the election state is critical. Use commands like 'show spanning-tree' on Cisco or 'show spanning-tree interface' on Juniper to verify the root bridge, root ports, and designated ports. If you see unexpected blocking ports or a switch that is not the intended root, you know there is a misconfiguration. Mastering spanning tree election in practice means you can design resilient, loop-free, and high-performance networks that adapt quickly to changes.

## Memory tip

Lowest bridge ID wins the crown. Priority first, then MAC. Root ports cost the least, designated ports beat the rest.

## FAQ

**What is the purpose of the root bridge in spanning tree election?**

The root bridge is the central reference point. All other switches calculate their best path to it. The root bridge does not have a root port, and all its ports are designated. It ensures a loop-free topology.

**How long does spanning tree election take?**

Classic STP takes about 30-50 seconds for a topology change (listening and learning states). RSTP reduces this to a few seconds via a proposal-agreement handshake.

**Can I manually choose which switch becomes the root bridge?**

Yes. By setting a lower bridge priority on a switch, you influence the election. For example, setting priority to 4096 on a core switch makes it more likely to be elected root.

**What happens if two switches have the same priority and MAC address?**

This cannot happen because MAC addresses are globally unique. If a question presents that scenario, it is likely a trick. In real life, it is impossible.

**Does spanning tree election work differently for VLANs?**

In PVST+ and MSTP, each VLAN or instance has its own election. You can have different root bridges for different VLANs to balance traffic.

**What is BPDU Guard and how does it relate to election?**

BPDU Guard is a security feature that disables a port if a BPDU is received. This prevents unauthorized switches from participating in the election and potentially becoming root.

## Summary

Spanning tree election is the foundational process that enables redundant network links without causing data loops. It works by having switches exchange BPDUs and elect a single root bridge based on the lowest bridge ID. Non-root switches then choose a root port as their best path to the root, and designated ports are selected on each segment to ensure only one path is active per link. The remaining ports are blocked, creating a loop-free tree topology. This election is critical for network stability and performance. Without it, broadcast storms would crash networks. In exams like CompTIA Network+ and Cisco CCNA, you must understand the election rules, including priority and MAC comparison, path cost calculation, and port roles. You should also be aware of the differences between STP, RSTP, and MSTP. Practical configuration involves setting bridge priorities, enabling PortFast and BPDU Guard, and monitoring with show commands. Mastering this topic ensures you can design, configure, and troubleshoot enterprise networks effectively. The key exam takeaway is to always apply the decision process step by step: root bridge first, then root port, then designated port, using the correct tie-breakers.

---

Practice questions and the full interactive page: https://courseiva.com/glossary/spanning-tree-election
