A switch normally puts all its ports in one broadcast domain. VLANs divide a physical switch into several logical networks.
Concept of VLANs
A Virtual LAN (VLAN) is a logical group of devices that behave as if they were on their own separate LAN, even though they share the same physical switches. Each VLAN is a separate broadcast domain: broadcasts in one VLAN do not reach others. Devices can be grouped by function (accounts, labs, staff) rather than by physical location. Traffic between VLANs must pass through a router or a layer 3 switch (inter-VLAN routing), where it can be controlled.
Definition: VLAN. A Virtual Local Area Network, a logical subdivision of a switched network into separate broadcast domains, independent of the physical location of devices.
VLAN Membership and Tagging
VLANs are numbered with a VLAN ID from 1 to 4094; VLAN 1 is the default. Access ports belong to a single VLAN and connect end devices; frames on them are untagged. Trunk ports carry traffic of many VLANs between switches or to a router. To show which VLAN each frame belongs to, the IEEE 802.1Q standard inserts a 4-byte tag into the Ethernet frame after the source MAC address. The tag contains the TPID (0x8100), a 3-bit priority (PCP, used for QoS), and the 12-bit VLAN ID. The native VLAN on a trunk is sent untagged.
Configuration
On a managed switch (for example, a Cisco switch in Packet Tracer): create VLANs with vlan 10, name STUDENTS; assign an access port with interface fa0/1, switchport mode access, switchport access vlan 10; and make a trunk with interface gig0/1, switchport mode trunk. The command show vlan brief verifies the configuration. For inter-VLAN routing, a router uses sub-interfaces with 802.1Q encapsulation ("router on a stick"), or a layer 3 switch uses SVIs (switched virtual interfaces).
Benefits and Use Cases
VLANs give security (sensitive departments are separated), reduced broadcast traffic and better performance, flexibility (users can move without re-cabling), easier management, and cost savings, since one switch serves several groups. Typical uses are separating staff and student networks in a college, a guest Wi-Fi VLAN, a voice VLAN for IP phones with priority, and a management VLAN for network devices.
Table 2.8: Access and trunk ports
| Feature | Access port | Trunk port |
|---|---|---|
| VLANs carried | One | Many |
| Tagging | Untagged | 802.1Q tagged (native untagged) |
| Connects | End devices | Switches, routers |
| Example command | switchport access vlan 10 | switchport mode trunk |
Example 2.8: Planning VLANs for a college
Problem: A college switch serves 10 staff PCs, 40 lab PCs and a printer used by staff. Plan the VLANs and explain how a staff PC and a lab PC communicate.
Solution:
- Create VLAN 10 (STAFF) for staff PCs and the printer, and VLAN 20 (LAB) for lab PCs.
- Make their ports access ports in the matching VLAN; make the uplink to the router a trunk.
- Give each VLAN its own subnet, such as 10.0.10.0/24 and 10.0.20.0/24.
- A staff PC reaches a lab PC only through the router's inter-VLAN routing, where access rules can block students from the staff network.
Result: Two broadcast domains; lab broadcasts no longer reach staff, and access between them is controlled.
vlans = {10: "STAFF", 20: "LAB", 99: "MGMT"}
ports = {"fa0/1": 10, "fa0/2": 10, "fa0/3": 20, "fa0/4": 20,
"gig0/1": "trunk"}
for vid, name in vlans.items():
members = [p for p, v in ports.items() if v == vid]
plist = ", ".join(members) or "-"
print(f"VLAN {vid:<3} {name:<6} ports: {plist}")
# TPID 0x8100, priority 5, VLAN 20
tag = (0x8100 << 16) | (5 << 13) | 20
print(f"802.1Q tag for VLAN 20, priority 5: 0x{tag:08X}")
Output
VLAN 10 STAFF ports: fa0/1, fa0/2
VLAN 20 LAB ports: fa0/3, fa0/4
VLAN 99 MGMT ports: -
802.1Q tag for VLAN 20, priority 5: 0x8100A014
Common mistakes
- Expecting devices in different VLANs to talk without a router or layer 3 switch.
- Connecting switches with access ports when several VLANs must cross the link.
- Leaving all ports in the default VLAN 1, which weakens security.
Key takeaways
- A VLAN is a separate broadcast domain on shared switches.
- Access ports carry one VLAN; trunks carry many with 802.1Q tags.
- The 802.1Q tag holds a 12-bit VLAN ID and a 3-bit priority.
- Benefits: security, less broadcast traffic, flexibility and easy management.
Practice questions
- What is a VLAN?
- Which standard defines VLAN tagging?
- How do devices in different VLANs communicate?
Answers to the practice questions
- A logical subdivision of a switched network into a separate broadcast domain.
- IEEE 802.1Q.
- Through a router or a layer 3 switch (inter-VLAN routing).
Sources
- Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit II
