Online admissions open for the SEO, web development and networking & cybersecurity courses. Enquire for the next batch.

VLANs Explained: 802.1Q Tagging, Trunks and Configuration

5 min read Updated By the SkillNewton team

What is a VLAN?

A VLAN (virtual local area network) divides one physical switched network into separate logical networks, each with its own broadcast domain. Devices in the same VLAN communicate as if they shared a switch, while traffic between VLANs must pass through a router or Layer 3 switch. VLANs are carried between switches using IEEE 802.1Q tags and are a core tool for segmentation.

Why networks use VLANs

Without VLANs, every device on a set of connected switches shares one broadcast domain. Every ARP request and DHCP Discover reaches every host, and a guest laptop sits on the same network as the finance server. VLANs fix both problems without buying separate switches for each group.

  • Segmentation: staff, guests, servers, CCTV cameras and IP phones get separate networks with their own subnets.
  • Security: traffic between VLANs passes through a routing point where access control lists or a firewall can filter it.
  • Smaller broadcast domains: broadcasts stay inside their own VLAN.
  • Flexibility: a user who moves desks keeps the same network by changing a port setting rather than a cable.

Each VLAN normally maps to one IP subnet, for example VLAN 10 to 192.168.10.0/24 and VLAN 20 to 192.168.20.0/24. Planning those subnets uses the skills from the subnetting guide.

How 802.1Q tagging works

When a frame travels between switches, the sending switch inserts a 4-byte 802.1Q tag after the source MAC address so the receiving switch knows which VLAN it belongs to. The receiving switch removes the tag before delivering the frame to an end device.

FieldSizePurpose
TPID16 bitsValue 0x8100, which marks the frame as tagged
PCP3 bitsPriority for quality of service, 0 to 7 (802.1p)
DEI1 bitMarks frames that may be dropped first under congestion
VID12 bitsThe VLAN ID, 0 to 4095

Twelve bits give 4,096 values, but 0 and 4095 are reserved, so usable VLAN IDs run from 1 to 4094. On Cisco switches VLAN 1 is the default for every port, and IDs 1002 to 1005 are reserved for legacy technologies.

Access ports, trunk ports and the native VLAN

Port typeCarriesTaggingConnects to
AccessOne data VLAN (plus an optional voice VLAN)Frames leave untaggedPCs, printers, cameras, access points in simple setups
TrunkMany VLANsFrames are tagged, except the native VLANOther switches, routers, hypervisors, multi-SSID access points

The native VLAN is the one VLAN whose frames cross a trunk without a tag. Both ends of a trunk must agree on it; a mismatch leaks traffic between VLANs and Cisco devices log a warning through CDP. Leaving the native VLAN as VLAN 1 also enables a VLAN-hopping trick called double tagging.

Configuring VLANs on a Cisco-style switch

This example creates staff, student and native VLANs, sets an access port for a PC and a trunk to another switch.

configure terminal
vlan 10
 name STAFF
vlan 20
 name STUDENTS
vlan 999
 name NATIVE_UNUSED
!
interface GigabitEthernet0/5
 description Staff PC
 switchport mode access
 switchport access vlan 10
 switchport nonegotiate
 spanning-tree portfast
!
interface GigabitEthernet0/24
 description Trunk to SW2
 switchport mode trunk
 switchport trunk native vlan 999
 switchport trunk allowed vlan 10,20
 switchport nonegotiate
end
!
show vlan brief
show interfaces trunk
show interfaces GigabitEthernet0/5 switchport
  1. Create each VLAN and give it a descriptive name.
  2. Set end-device ports to access mode and assign their VLAN.
  3. Set inter-switch links to trunk mode, choose an unused native VLAN and restrict the allowed list.
  4. Verify with show vlan brief and show interfaces trunk, checking that each VLAN appears as allowed and forwarding.

Some older switches that also support Cisco ISL need switchport trunk encapsulation dot1q before switchport mode trunk. On Linux, a tagged subinterface is created with ip link add link eth0 name eth0.10 type vlan id 10.

Routing between VLANs

Hosts in VLAN 10 and VLAN 20 are on different subnets, so a Layer 3 device must route between them. Each VLAN needs a gateway address on that device, and each host uses it as its default gateway.

Router-on-a-stick

interface GigabitEthernet0/0
 no shutdown
interface GigabitEthernet0/0.10
 encapsulation dot1Q 10
 ip address 192.168.10.1 255.255.255.0
interface GigabitEthernet0/0.20
 encapsulation dot1Q 20
 ip address 192.168.20.1 255.255.255.0

Layer 3 switch with SVIs

ip routing
interface Vlan10
 ip address 192.168.10.1 255.255.255.0
 no shutdown
interface Vlan20
 ip address 192.168.20.1 255.255.255.0
 no shutdown

Router-on-a-stick suits labs and small sites because one trunk link carries every VLAN. Switched virtual interfaces (SVIs) on a Layer 3 switch route in hardware and suit larger networks. Either way, add ip helper-address on each gateway if DHCP runs centrally, as described in how DHCP works, and filter between VLANs with ACLs or a firewall.

Hardening and troubleshooting VLANs

Most VLAN faults come down to a port in the wrong VLAN, a VLAN missing from a trunk or a gateway that does not exist. Work through them in that order.

SymptomLikely causeCheck
Host gets an address from the wrong subnetAccess port assigned to the wrong VLANshow interfaces GigabitEthernet0/5 switchport
Hosts on one switch work, the same VLAN on another switch does notVLAN not created on both switches or not allowed on the trunkshow vlan brief and show interfaces trunk
Hosts reach their own VLAN but not othersMissing or shut-down gateway interface, or wrong default gateway on hostsshow ip interface brief on the router or Layer 3 switch
Hosts in a VLAN get a 169.254 addressNo DHCP scope or relay for that VLANDHCP server scopes and ip helper-address
  • Shut down unused ports and assign them to an unused VLAN.
  • Keep switch management on its own VLAN, reachable only from administrator subnets.
  • Enable DHCP snooping and Dynamic ARP Inspection on user VLANs.
  • Document every VLAN ID, name, subnet and gateway so changes stay consistent across switches.

Practical exercise: build a two-VLAN lab

Use Cisco Packet Tracer or another simulator with two switches, one router and four PCs.

  1. Create VLAN 10 and VLAN 20 on both switches and put two PCs in each VLAN.
  2. Connect the switches with a trunk that uses native VLAN 999 and allows only VLANs 10 and 20.
  3. Configure router-on-a-stick with gateways 192.168.10.1 and 192.168.20.1, and give the PCs matching addresses.
  4. Ping within each VLAN, then between VLANs, and confirm both work.
  5. Remove VLAN 20 from the trunk allowed list and observe which pings fail, then restore it.

You are done when you can explain each failure from the output of show interfaces trunk. Multi-switch designs, inter-VLAN filtering and Layer 3 switching are taken further in the Advanced Networking course.

Common mistakes

  • Forgetting to add a new VLAN to the trunk allowed list, so its hosts cannot reach other switches.
  • Leaving the native VLAN mismatched on the two ends of a trunk.
  • Using VLAN 1 for user traffic and management.
  • Expecting hosts in different VLANs to communicate without a routing device.
  • Leaving unused ports in an active VLAN instead of shutting them down in an unused one.

Frequently asked questions

Is a VLAN the same as a subnet?

No. A VLAN is a Layer 2 broadcast domain and a subnet is a Layer 3 address range. In practice each VLAN usually carries one subnet, which is why the two are often discussed together.

How many VLANs can a switch support?

The 802.1Q standard allows IDs 1 to 4094, but each switch model has its own limit on how many it can hold at once. Check the vendor datasheet.

What is a voice VLAN?

A second VLAN on an access port reserved for an IP phone. The phone tags its traffic with the voice VLAN while the PC plugged into the phone stays in the data VLAN.

Do VLANs make a network secure on their own?

No. They separate traffic, but you still need filtering between VLANs, switch hardening and monitoring, as set out in network security fundamentals.

Want to Learn This Properly?

The Advanced Networking & Cybersecurity Mastery (Online) turns guides like this into practised skills, with projects on real websites.

WhatsApp Call Us Now

Free counselling

Send an Enquiry

Tell us which course you are interested in. We reply by email or phone with the next batch and how to enrol.

Protected by reCAPTCHA. Google Privacy and Terms apply.

We reply by email or phone within working hours. No spam.