← Interview Prep

VLAN & VXLAN — Theory

L2 segmentation at both scales: 802.1Q VLANs (access/trunk/native, QinQ, inter-VLAN routing, the 4094 limit) and VXLAN (MAC-in-UDP, VTEP/VNI, BUM handling, flood-and-learn vs BGP EVPN, distributed anycast gateway).

VLANs slice one physical switch into many broadcast domains; VXLAN stretches those domains over an L3 fabric and lifts the 4094-segment ceiling to 16 million. Same goal — isolate L2 — at two very different scales. This is the theory to explain both, and why the data center moved from one to the other.

A VLAN = one broadcast domain, tagged with a 12-bit ID, confined to an L2 network. VXLAN = an L2 frame tunneled in UDP across an L3 underlay, tagged with a 24-bit VNI — L2 anywhere the IP fabric reaches.

VLANs

A VLAN is a logical broadcast domain. Frames carry the 802.1Q tag (see Protocol Headers): a 12-bit VID → 0–4095, with 0 and 4095 reserved, so ~4094 usable.

The tag is inserted right after the source MAC, before the EtherType/Length — that's the only change to a normal Ethernet II frame (+4 bytes):

  untagged Ethernet II frame:
  +-------------+-------------+-----------+--------------------+-----+
  | Dst MAC (6) | Src MAC (6) | EtherType | Payload (46-1500)  | FCS |
  +-------------+-------------+-----------+--------------------+-----+

  802.1Q-tagged frame  (tag = 4 bytes, inserted after Src MAC):
  +-------------+-------------+===============+-----------+---------+-----+
  | Dst MAC (6) | Src MAC (6) | 802.1Q tag(4) | EtherType | Payload | FCS |
  +-------------+-------------+===============+-----------+---------+-----+
                              |               |
                              v               v
                 +-------------------+---+---+------------------+
                 | TPID = 0x8100 (16)|PCP|DEI|   VID (12 bits)  |
                 +-------------------+---+---+------------------+
                  \_____ 2 bytes ____/ \______ TCI: 2 bytes ____/
  PCP = 3-bit priority (802.1p CoS)   DEI = 1-bit drop-eligible   VID = VLAN 0-4095
ConceptMeaning
Access portBelongs to one VLAN; frames are untagged to the host. The port's VLAN = its PVID.
Trunk portCarries many VLANs, tagged (802.1Q), between switches. Prune with an allowed-VLAN list.
Native VLANThe one VLAN sent untagged on a trunk. A native-VLAN mismatch merges two domains — a classic bug.
Voice VLANAn access port tags voice while data stays untagged — phone + PC on one port.
RangesNormal 1–1005, extended 1006–4094 (Cisco).

QinQ (802.1ad)

Stack two tags — an outer provider S-tag (0x88A8) plus the customer C-tag (0x8100) — so a carrier can transport customer VLANs transparently and scale past 4094 at the edge. The outer (S) tag is pushed in front; order is outermost first:

  +-------------+-------------+===============+===============+-----------+---------+-----+
  | Dst MAC (6) | Src MAC (6) | S-tag  0x88A8 | C-tag  0x8100 | EtherType | Payload | FCS |
  +-------------+-------------+===============+===============+-----------+---------+-----+
                               \__ provider __/ \__ customer __/
                                  (outer VID)      (inner VID)

Still L2, still bounded by the L2 domain — QinQ scales the edge, not the whole fabric.

Why VLANs run out of room

VXLAN

MAC-in-UDP: a full Ethernet frame is encapsulated in an 8-byte VXLAN header + UDP (dst 4789) + outer IP/Ethernet, and forwarded across a routed L3 underlay. The 24-bit VNI identifies the segment — ~16 million vs 4094.

Read the encapsulation from the wire inward — the underlay headers come first, the tenant's original frame is the payload:

  |<----------------- added by the VTEP (~50 bytes) ---------------->|<-- original -->|
  +-----------+----------+----------+------------+---------------------+---------------+
  | Outer Eth | Outer IP | Outer UDP| VXLAN hdr  |    Inner Ethernet   |  ... payload  |
  |  14 (+4)  |    20    | 8, dst=  |     8      |  (the tenant frame, |   (L3/L4/app) |
  |           | VTEP IPs |   4789   |  VNI here  |   Dst/Src MAC ...)  |               |
  +-----------+----------+----------+------------+---------------------+---------------+
   \___ outer, routed across the underlay ______/ \___ carried opaquely, unchanged ___/

  VXLAN header (8 bytes):
   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-----------------------------------------------+
  |R R R R I R R R|               Reserved (24 bits)              |
  +-+-+-+-+-+-+-+-+-----------------------------------------------+
  |                VNI (24 bits)                  | Reserved (8)  |
  +-----------------------------------------------+---------------+
   Flags: the I bit = 1 means the VNI field is valid; all R = reserved (0).

So the field order on the wire is: outer MACs → outer IPs (VTEP→VTEP) → UDP:4789 → VNI → the whole original frame. Transit routers only ever see the outer IP/UDP; the tenant frame is opaque.

TermMeaning
VTEPVXLAN Tunnel Endpoint — encaps/decaps frames. On a switch ASIC (hardware) or a hypervisor/host (software).
VNI24-bit segment ID; an L2VNI maps to a bridge domain, an L3VNI to a VRF.
UnderlayThe routed IP fabric (usually a leaf-spine Clos with ECMP) that carries VTEP-to-VTEP traffic.
OverlayThe tenant L2/L3 networks riding on top.

Handling BUM (broadcast, unknown-unicast, multicast)

L2 relies on flooding; over an L3 underlay you need a way to replicate BUM to all VTEPs in a VNI:

Control plane: flood-and-learn vs EVPN

Flood-and-learnBGP EVPN
MAC learningData plane (flood, learn on arrival)Control plane — MP-BGP advertises MAC/IP
VTEP discoveryManual / multicastAutomatic (Type 3 routes)
FloodingLots of BUMReduced — ARP suppression, known unicast
Scale/robustnessLimitedThe standard for production fabrics

MP-BGP EVPN (L2VPN EVPN AFI/SAFI) is the modern VXLAN control plane. Key route types:

For the full field-by-field breakdown of every route type (1–5) and the extended communities they carry, see EVPN — Theory. Also MP-BGP and Life of a Packet — Advanced.

Gateways & anycast

VXLAN vs VLAN

VLANVXLAN
Segment ID12-bit (~4094)24-bit (~16M)
TransportL2 onlyL2 over an L3 (routed) underlay
ReachWithin an L2 domainAnywhere the IP fabric reaches
MultipathingSTP blocks linksL3 ECMP (all links active)
Overhead4-byte tag~50-byte encap (needs jumbo MTU)
Control planeFlood/learn (+STP)Flood/learn or BGP EVPN

Likely interview questions

Related: Protocol Headers (802.1Q/VXLAN) · MP-BGP / EVPN · Life of a Packet — Advanced.