What is a VLAN
A VLAN (Virtual Local Area Network) is a communication technology that logically divides a physical LAN into multiple broadcast domains. Hosts in the same VLAN can communicate with each other directly, while hosts in different VLANs cannot, so broadcast packets stay within a single VLAN.
VLANs solve a problem that comes from the way Ethernet was designed. Ethernet was originally based on a shared communication medium using CSMA/CD (Carrier Sense Multiple Access/Collision Detection). When the number of hosts grows, this causes serious conflicts, broadcast flooding, significant performance degradation, and even network unavailability. Interconnecting LANs through switches resolves the conflicts, but switches alone cannot isolate broadcast packets. VLANs add that isolation.
How VLANs Work
VLAN tag. A VLAN is identified by a unique VLAN tag, also known as the 802.1Q tag.
Port-based membership. The simplest way to define a VLAN is by switch interface. After an interface is added to a VLAN, it can forward that VLAN's packets, so hosts in the VLAN communicate directly at Layer 2, while hosts in different VLANs cannot.
Interface types. Depending on how an interface identifies VLAN frames, it is one of three types:
Interface type | Connects to | Number of VLANs |
|---|---|---|
Access | Hosts | 1 |
Trunk | Switches or routers | 1 to 4094 |
Hybrid | Hosts, switches, or routers | 1 as an access link, 1 to 4094 as a trunk link |
Hosts send and receive untagged packets, while tagged packets are carried both within and between switches.
VID and PVID. The VID is the VLAN ID. For example, member ports of VLAN 100 have a VID of 100 and can receive packets tagged with 100. The PVID (Port-based VLAN ID) is a single VLAN ID assigned to an interface. An interface can belong to many VLANs, but it has only one PVID. When an interface receives a packet without a tag, the switch tags it with the PVID and processes it as a packet of that VLAN. For example, if a port joins VLAN 100 in untagged mode and also joins VLAN 200, its PVID is 100. The PVID is used only when untagged frames arrive from outside, and it has no effect when the switch forwards data internally. When two devices are connected, the PVID on both ends of the link should be the same.
Sending and receiving rules. The switch handles packets according to the interface type:
Access: untagged packets are accepted and tagged. Tagged packets are accepted only if their tag matches the port's PVID. Packets leaving the port have the tag removed.
Trunk: tagged packets are accepted if their tag is in the port's allowed list, and discarded otherwise. Packets leaving the port have the tag removed if it matches the PVID, and keep their tag otherwise.
Communication between VLANs. Users in different VLANs cannot communicate directly, but Layer 3 interworking can be set up with a VLAN interface. A VLAN interface is a virtual Layer 3 interface that does not exist as a physical entity. Each VLAN has one, and its IP address serves as the gateway for devices in the VLAN. Packets that need to cross network segments are then forwarded at Layer 3 based on IP addresses.
Why VLANs are Beneficial
Smaller broadcast domains: Broadcast packets are limited to a single VLAN, which prevents broadcast flooding and the performance loss that comes with it.
Isolation between groups: Hosts in the same VLAN communicate directly, while different VLANs are isolated at Layer 2. A company can place each department's users and servers in a separate VLAN so that employees reach only their own department's servers.
Controlled Layer 3 interworking: When communication between VLANs is needed, it is set up explicitly through VLAN interfaces and IP addresses.
Flexible membership: VLAN membership follows the switch interface, so ports on the same switch, or on different switches, can belong to the same VLAN.