Sub topic 6
Inside the 802.1Q tag
This chapter assumes you already know the Ethernet frame layout, how a switch learns MAC addresses, and how to read basic switch output. It covers the 4 bytes that 802.1Q inserts into a frame, the meaning of each field, how the tag is read from raw bytes, and the mistakes people make with it.
Why a tag exists
An access port needs no tag, because the switch knows the VLAN from the port configuration. A trunk carries frames from many VLANs on one wire, so each frame must say which VLAN it belongs to. The 802.1Q standard does this by inserting a 4-byte tag into the Ethernet header. Frames on a trunk are therefore tagged, with one exception covered in the native VLAN chapter.
Where the tag sits
The tag goes between the source MAC address and the original EtherType field. Nothing before it changes. The destination and source MAC addresses stay in place.
| Offset (bytes) | Size | Field | Notes |
|---|---|---|---|
| 0 | 6 | Destination MAC | Unchanged |
| 6 | 6 | Source MAC | Unchanged |
| 12 | 2 | TPID | 0x8100 for an 802.1Q tag |
| 14 | 2 | TCI | Priority, DEI and VLAN ID |
| 16 | 2 | EtherType | The original type, such as 0x0800 for IPv4 |
| 18 | 46 to 1500 | Payload | Unchanged |
| end | 4 | FCS | Recalculated over the tagged frame |
The tag is 4 bytes in total: the 2-byte TPID and the 2-byte TCI.
The TPID
The Tag Protocol Identifier is the first 2 bytes of the tag. For 802.1Q it is always 0x8100. It occupies the same position that the EtherType normally has, so a receiver that looks at bytes 12 and 13 sees 0x8100 and knows a tag follows. This is why 0x8100 is not a usable payload type for ordinary traffic.
The TCI
The Tag Control Information field is 16 bits, split into three parts.
| Bits | Size | Field | Purpose |
|---|---|---|---|
| 15 to 13 | 3 bits | PCP, Priority Code Point | Class of service, values 0 to 7 |
| 12 | 1 bit | DEI, Drop Eligible Indicator | Marks a frame that may be dropped first under congestion |
| 11 to 0 | 12 bits | VID, VLAN ID | The VLAN the frame belongs to |
Priority Code Point
The PCP carries an 802.1p class of service. Eight values (0 to 7) let switches queue important traffic, such as voice, ahead of bulk traffic. A switch only uses this value if quality of service is configured to trust or map it. The default priority is 0.
Drop Eligible Indicator
The DEI was called the Canonical Format Indicator (CFI) in older versions of the standard. Modern equipment uses it to mark frames that can be discarded first when a link is congested. Treat it as 0 unless you have a policing design that sets it.
VLAN ID
The 12-bit VID gives 4096 possible values, 0 to 4095. Two are reserved. Value 0 means the frame has a priority but no VLAN, and 4095 is reserved. In practice usable VLANs run from 1 to 4094. Value 1 is the default VLAN on most switches and cannot be deleted. Some vendors reserve further ranges for internal use, so check your platform before choosing IDs.
Reading a tag from raw bytes
The two Python examples show the structure from both directions. The first reads the fields from a captured frame.
import struct
def parse_dot1q(frame: bytes):
"""Return the 802.1Q fields of an Ethernet frame, or None if it is untagged."""
tpid, tci = struct.unpack("!HH", frame[12:16])
if tpid != 0x8100:
return None
return {
"pcp": tci >> 13,
"dei": (tci >> 12) & 0x1,
"vid": tci & 0x0FFF,
}The function reads bytes 12 to 15 in network byte order. If the first two are not 0x8100, the frame has no 802.1Q tag and the function returns None. Otherwise it shifts and masks the TCI. Shifting right by 13 keeps the top 3 bits. Shifting right by 12 and masking with 1 isolates the DEI. Masking with 0x0FFF keeps the low 12 bits.
As a worked example, suppose the 4 tag bytes are 81 00 20 0A. The TPID is 0x8100, so the frame is tagged. The TCI is 0x200A, which is binary 0010 0000 0000 1010. The top three bits are 001, so PCP is 1. The next bit is 0, so DEI is 0. The low 12 bits are 0x00A, so the VID is 10.
The second example builds a tagged frame with Scapy, a Python packet library. It needs pip install scapy and is meant for a lab network.
from scapy.all import Ether, Dot1Q, IP, ICMP
frame = (
Ether(dst="ff:ff:ff:ff:ff:ff")
/ Dot1Q(vlan=10, prio=0)
/ IP(dst="192.168.10.255")
/ ICMP()
)
frame.show()The output lists an Ethernet layer, a Dot1Q layer showing prio, id (the DEI bit) and vlan, then IP and ICMP. Scapy sets the Ethernet type to 0x8100 for you and moves the real type into the Dot1Q layer.
Tagging on a Linux host
A Linux host sends and receives tagged frames through a VLAN subinterface. The kernel inserts and removes the tag, so applications see ordinary traffic.
sudo ip link add link eth0 name eth0.10 type vlan id 10
sudo ip addr add 192.168.10.5/24 dev eth0.10
sudo ip link set eth0.10 upFrames sent out of eth0.10 leave eth0 with VID 10. Frames received on eth0 with VID 10 are delivered to eth0.10. The switch port must be a trunk that allows VLAN 10, or the host receives nothing.
What happens to the tag at each hop
The tag exists only on links that carry it. When a frame enters a switch on an access port, the switch adds the VLAN association internally, with no tag on the wire. When the frame leaves through a trunk port, the switch inserts the tag with the VID. When it leaves through an access port, the switch removes the tag. Because the frame contents change, the switch recalculates the Frame Check Sequence (FCS) on every insertion or removal.
Size effects
The tag adds 4 bytes, so the largest standard frame grows from 1518 to 1522 bytes. The payload limit (MTU) stays at 1500. Most modern switches accept the larger frame on all ports. A device that enforces 1518 bytes can drop full-size tagged frames. These are counted as giants or oversize errors, and the symptom is that small packets such as ping work while large transfers stall.
Common errors
- Expecting the tag on access ports. A packet capture on a host connected to an access port shows no tag. Tags appear only on trunks.
- Reading the VID as a priority. PCP and VID are separate. Changing the PCP never moves a frame to another VLAN.
- Using VID 0 or 4095 as a VLAN. Neither is a normal VLAN. Switches reject them.
- Missing tags in captures on the sending host. Many network cards strip or insert tags in hardware, so a capture on the host may show a frame without a tag that is tagged on the wire. Capture on a mirror port when exactness matters.
- A host NIC that does not understand tags. A server connected to a trunk without a VLAN subinterface sees tagged frames as unknown traffic and drops them.
Exercises
Exercise
A trunk delivers a frame whose bytes 12 to 15 are 81 00 60 14. Is it tagged, and what are the PCP, DEI and VID?
Show answer
Bytes 12 and 13 are 0x8100, so the frame is tagged. The TCI is 0x6014, binary 0110 0000 0001 0100. PCP is the top 3 bits, 011, which is 3. DEI is the next bit, 0. The VID is the low 12 bits, 0x014, which is 20.
Exercise
Why does a full 1500-byte payload frame grow to 1522 bytes on a trunk, and what symptom would you see if a device drops frames over 1518 bytes?
Show answer
The 802.1Q tag adds 4 bytes to the 1518-byte maximum untagged frame. A device limited to 1518 bytes drops full-size tagged frames as oversize or giant errors. Small packets such as ping still pass, while large transfers stall or fail.