codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🌐

Computer Networks

26 chapters

1Network Topologies & LAN/WAN2Network Devices (Hub, Switch, Router)3OSI Reference Model4OSI Model & TCP/IP Suite5TCP/IP Protocol Suite6Switching Techniques (Circuit, Packet)7Data Link: Framing & Error Detection8Error Correction (Hamming Code)9Flow Control (Stop-and-Wait, Sliding Window)10MAC: CSMA/CD & CSMA/CA11Network Layer & Routing12IP Addressing (IPv4, IPv6)13Subnetting & CIDR14Routing Algorithms (Distance Vector, Link State)15ARP, ICMP, and NAT16DHCP Protocol17Transport Layer Services18Transport Layer: UDP19Transport Layer: TCP & 3-Way Handshake20TCP Congestion Control21Application Layer: DNS & HTTP22Application Layer: SMTP & FTP23Socket Programming Basics24Wireless Networks & Wi-Fi Standards25VLANs & Spanning Tree Protocol26Network Security & Cryptography
SubjectsComputer Networks

VLANs & Spanning Tree Protocol

Updated 2026-04-22
2 min read

VLANs & Spanning Tree Protocol

1. VLANs (Virtual Local Area Networks)

A VLAN allows a network administrator to logically divide a single physical switch (or group of switches) into multiple separate, isolated broadcast domains. Devices in different VLANs cannot communicate directly, even if they are connected to the same physical switch.

Why VLANs?

  • Security: The Finance department's traffic is completely isolated from the Marketing department's traffic.
  • Performance: Broadcasts from VLAN 10 do not flood devices on VLAN 20, reducing unnecessary network traffic.
  • Flexibility: An employee can be moved to a different floor without changing their VLAN membership; the switch port is simply reassigned.

Trunk Ports and 802.1Q Tagging

When a frame needs to traverse a link between two switches, the switch must indicate which VLAN the frame belongs to. IEEE 802.1Q inserts a 4-byte VLAN Tag into the Ethernet frame header, containing a 12-bit VLAN ID (supporting up to 4,096 VLANs). A Trunk Port carries traffic for multiple VLANs between switches.

2. Spanning Tree Protocol (STP)

The Problem: Switching Loops

For redundancy, switches are often connected in loops (if one link fails, traffic can use an alternate path). However, loops cause Broadcast Storms: a broadcast frame is forwarded endlessly around the loop, consuming all bandwidth and crashing the network within seconds.

The Solution: STP (IEEE 802.1D)

STP automatically detects loops in the network topology and disables redundant links, creating a loop-free tree topology. If an active link fails, STP re-enables a previously disabled redundant link to restore connectivity.

How STP Works:

  1. Root Bridge Election: All switches exchange BPDU (Bridge Protocol Data Unit) messages. The switch with the lowest Bridge ID (priority + MAC address) becomes the Root Bridge.
  2. Root Port Selection: Each non-root switch selects its Root Port — the port with the lowest cost path to the Root Bridge.
  3. Designated Port Selection: On each network segment, the port with the lowest cost to the Root Bridge becomes the Designated Port.
  4. Blocking: All other ports are placed in a Blocking state. They do not forward data frames but still listen for BPDUs.

RSTP (Rapid STP - 802.1w)

Standard STP can take 30-50 seconds to converge after a topology change. RSTP dramatically reduces convergence time to under 6 seconds by introducing new port states and a faster handshake mechanism. RSTP is the standard in modern networks.



PreviousWireless Networks & Wi-Fi StandardsNextNetwork Security & Cryptography

Recommended Gear

Wireless Networks & Wi-Fi StandardsNetwork Security & Cryptography