What Is a VLAN in Networking?
In this article
A VLAN, or virtual local area network, is a way of splitting one physical network switch into several separate logical networks. Devices in the same VLAN can talk to each other as if they were plugged into the same switch, while devices in different VLANs are kept apart unless a router or a Layer 3 switch is configured to pass traffic between them. Network administrators use VLANs in offices, data centers, schools and home labs to group devices by function or department rather than by physical location.
How a VLAN Separates Traffic
A single managed switch with 24 ports can be divided into, say, VLAN 10 for the sales team on ports 1-8, VLAN 20 for engineering on ports 9-16, and VLAN 30 for guest Wi-Fi on ports 17-24. A broadcast frame sent by a device in VLAN 10 stays inside VLAN 10; the switch does not forward it to ports in VLAN 20 or 30. That containment is the core function: it reduces broadcast traffic and keeps one group's packets off another group's links.
The switch tags frames so it knows which VLAN they belong to. On an access port, which connects to an ordinary computer or printer, the switch adds the port's VLAN tag on ingress and strips it on egress, so the end device sees normal untagged Ethernet. On a trunk port, which connects two switches or a switch to a router, frames from many VLANs travel with their tags intact. The standard tag is defined by IEEE 802.1Q, which inserts a 4-byte field into the Ethernet frame carrying a 12-bit VLAN ID. That gives a usable range of VLAN IDs from 1 to 4094; 0 and 4095 are reserved.
Access ports and trunk ports
An access port belongs to exactly one VLAN and is the normal choice for end devices. A trunk port carries multiple VLANs and is used between network equipment. If you plug a laptop into a trunk port by mistake, the laptop usually cannot reach anything because it does not understand the tags. Some operating systems and network cards can be configured to accept tagged frames, but most desktops and printers cannot.
Why People Look Up VLANs
Most searches come from one of three situations. Someone has just been handed switch configuration duties and found VLAN settings in the web interface. Someone is studying for a networking certification and met the term in a chapter on switching. Or someone is trying to solve a practical problem, such as separating guest Wi-Fi from the office network or stopping a lab machine from reaching production servers.
In each case the practical question is the same: which devices should share a broadcast domain, and where should traffic be allowed to cross between them. A VLAN answers the first half. Routing between VLANs, sometimes called inter-VLAN routing, answers the second and requires a router, a firewall, or a Layer 3 switch with an interface in each VLAN.
Configuring VLANs on a Switch
The exact menu labels differ by vendor and firmware version, but the sequence is consistent across managed switches. Work through it in this order:
- Log in to the switch's management interface, usually a web page or a command-line console.
- Create each VLAN and give it an ID and a name, for example VLAN 10 named office and VLAN 20 named guest.
- Assign access ports to the correct VLAN. Keep a written record of which port carries which VLAN.
- Configure any uplink or switch-to-switch port as a trunk and allow only the VLANs that need to cross it.
- Set a native VLAN on trunks, or leave the default and make sure both ends agree, because a mismatch causes untagged traffic to land in the wrong VLAN.
- Save the configuration, then test from a device in each VLAN.
Do not change the management VLAN while you are connected through it unless you have console access as a fallback. A wrong management VLAN assignment locks you out of the web interface and leaves the console as the only way back in.
A small worked example
Take an office with 30 staff desks, 6 printers and a guest Wi-Fi network. Put the desks on VLAN 10 across ports 1-30, the printers on VLAN 20 across ports 31-36, and the guest access point uplink on VLAN 30. Trunk ports 47 and 48 to the core switch, allowing VLANs 10, 20 and 30. On the router or firewall, create one interface per VLAN with an address in each subnet, for example 192.168.10.1/24, 192.168.20.1/24 and 192.168.30.1/24. Then write firewall rules: VLAN 10 may reach VLAN 20 on the printer ports only, VLAN 30 may reach the internet and nothing internal. That gives three broadcast domains, one per group, with controlled paths between them.
VLANs Compared With Subnets
A VLAN is a Layer 2 concept and a subnet is a Layer 3 concept. In most designs one VLAN maps to one subnet, but the two are not the same thing. You can put two subnets on one VLAN, though it is unusual and makes addressing harder to follow. You cannot put one subnet across two VLANs without a router in between, because the devices would be in separate broadcast domains and could not resolve each other's addresses directly.
The practical rule: decide the subnets first, then assign one VLAN per subnet, then assign ports. Doing it in the other order usually produces a tangle of overlapping addresses that has to be rebuilt.
What VLANs do not do
A VLAN is not a security boundary on its own. Traffic between VLANs passes through a router or firewall, and that device's rules decide what is allowed; if the rules permit everything, the separation buys nothing beyond broadcast containment. A VLAN also does not encrypt traffic, does not replace authentication, and does not stop a device from being moved to another port. Port security settings, which limit which MAC addresses may appear on a port, address that last point and are configured separately.
Checking That a VLAN Works
Test from a device in each VLAN rather than from the switch itself. Confirm the device received an address from the correct range, then ping another device in the same VLAN; that should succeed. Ping a device in a different VLAN; that should fail unless a router rule allows it. If same-VLAN pings fail, check that both ports are assigned to the same VLAN and that the devices are in the same subnet.
If cross-VLAN traffic that should be allowed is blocked, check three things in order: the trunk allows both VLANs, the router has an interface in each subnet, and the firewall rule matches the actual source and destination addresses. If a device gets an address from the wrong subnet, its port is probably assigned to the wrong VLAN or the trunk's native VLAN does not match at both ends.
Keep a simple table of VLAN ID, name, subnet, and ports, and update it whenever a port changes. Most VLAN problems are not protocol failures; they are a port assigned to the wrong number months earlier and forgotten.