Layer 2 Switching: Meaning and Detailed Operation of Ethernet Switches

Layer 2 Switching: Meaning and Detailed Operation of Ethernet Switches

Verified Sources
Nov 4, 2026

A Layer 2 switch is an Ethernet switching device that makes forwarding decisions based on MAC addresses and typically supports features such as VLANs and Spanning Tree Protocol.

In contrast to Layer 3 routing, a Layer 2 switch does not route between IP networks; instead, it forwards Ethernet frames within the same Layer 2 domain (or within the same VLAN).

Core ideas

  1. Learning: The switch learns which MAC address is reachable via which switch port by examining incoming frames.
  2. Forwarding: For a frame’s destination MAC, the switch forwards out only the correct port if it knows the destination.
  3. Flooding: If the destination MAC is unknown, it floods the frame to all ports in the relevant VLAN (except the ingress port).
  4. Loop avoidance: If multiple paths exist at Layer 2, switching can create broadcast storms; STP blocks redundant paths.

[CalloutBlock]
type: "tip"
title: "Pro Tip: Think “MAC learning + selective forwarding”"
content: "Layer 2 switching is best understood as: learn source MACs, then forward destination MACs using a MAC address table, with flooding as the fallback for unknown destinations."

Layer 2 Switches: MAC Address Learning and Forwarding (intro)

Data structures inside a Layer 2 switch

A Layer 2 switch maintains a MAC address table (also called the forwarding table), which maps:

  • MAC address → egress port (and often VLAN ID as an additional key)

MAC address table entries are created dynamically from observed source MAC addresses on received frames, and they are typically removed using aging to prevent stale mappings.

MAC table learning rule (high level)

When a frame arrives:

  • The switch reads the source MAC
  • The switch records: “source MAC is reachable via the ingress port” (for that VLAN)
  • It then uses the destination MAC to decide forwarding

[CalloutBlock]
type: "warning"
title: "Warning: Learning occurs per VLAN (in VLAN-aware switches)"
content: "With 802.1Q VLANs, the same MAC may appear in different VLANs; a VLAN-aware switch keeps separate forwarding context (often effectively separate MAC tables per VLAN)."

How a Layer 2 switch forwards an Ethernet frame (detailed flow)

  1. 1
    Step 1

    The switch receives an Ethernet frame on one port (say, Port A). It does not need to interpret IP; it works at Layer 2 using MAC addresses.

  2. 2
    Step 2

    The switch examines the frame header fields for source MAC and destination MAC. If VLAN is present, the switch also identifies the VLAN context (via 802.1Q tag or default VLAN behavior).

  3. 3
    Step 3

    The switch updates its MAC address table with: (VLAN, source MAC) → ingress port. If an entry exists, it refreshes/updates it.

  4. 4
    Step 4

    The switch checks whether the destination MAC exists in the MAC table for the same VLAN.

  5. 5
    Step 5

    The switch forwards the frame only out the mapped egress port for that destination MAC.

  6. 6
    Step 6

    The switch floods the frame to all ports in that VLAN except the ingress port (so it reaches the unknown destination without sending back where it came from).

  7. 7
    Step 7

    Entries that haven’t been refreshed for a configured time are removed, preventing incorrect forwarding if hosts move.

Broadcasts, multicasts, and flooding behavior

A switch’s behavior differs depending on the destination MAC category:

1) Unicast destination MAC (normal case)

  • Known in MAC table → single-port forwarding
  • Unknown in MAC table → flooding within VLAN

2) Broadcast destination MAC (all hosts)

  • Broadcast is typically flooded to all ports in the VLAN (except ingress), because every host may need the frame.

3) Multicast destination MAC

  • Many switches implement multicast handling using techniques like IGMP snooping, but the basic principle is: multicast delivery is constrained to interested ports rather than universal flooding (implementation detail depends on features).

Handling Layer 2 loops and STP

If two switches are connected with redundant physical links, Layer 2 forwarding can create loops, causing:

  • repeated frame circulation,
  • increasing duplicates,
  • eventual network congestion (broadcast storms).

Spanning Tree Protocol (STP) builds a loop-free logical topology by designating a root bridge and selecting active links, while blocking others.

[CalloutBlock]
type: "warning"
title: "Warning: Without loop prevention, switching can amplify traffic indefinitely"
content: "A Layer 2 loop can repeatedly forward broadcasts and unknown unicasts, causing severe congestion. STP (or variants) mitigates this by blocking redundant paths."

VLANs and 802.1Q tagging

VLANs let an organization segment a switched network into multiple broadcast domains, even though the same physical switch fabric is used.

802.1Q VLAN tagging works by:

  • tagging frames with a VLAN ID
  • ensuring switches forward frames only within the same VLAN (with VLAN-aware MAC table lookups)

Practical consequences

  • Broadcasts/unknown unicasts are flooded only within the VLAN.
  • MAC table learning occurs per VLAN context.
  • Hosts on different VLANs are still isolated at Layer 2; IP communication requires routing (Layer 3).

Layer 2 switching vs Layer 3 switching (routing)

A Layer 2 switch forwards based on MAC addresses and does not examine IP destination addresses for routing decisions.

A Layer 3 switch/router uses IP headers, and requires routing tables and often ARP/ND for link-layer resolution.

FeatureLayer 2 SwitchLayer 3 Switch/Router
Forwarding basisDestination MACDestination IP
MaintainsMAC forwarding tableRouting table + ARP/neighbor tables
ScopeWithin VLANs / L2 domainBetween IP networks/subnets
Typical protocol roleSTP, VLANsOSPF/EIGRP/BGP (or static), routing
Broadcast domainVLAN-limitedNot limited by VLAN alone; routing defines boundaries

Forwarding decision speed vs decision layer (conceptual comparison)

This is a conceptual view: Layer 2 switching typically relies on MAC lookup; Layer 3 requires IP/routing evaluation.

From Ethernet frames to a stable forwarding topology

Ingress processing

Frame arrival

Switch reads source/destination MAC (and VLAN context)."

MAC table update

Learning phase

Creates/refreshes (VLAN, MAC) → port mapping."

Selective forwarding or flooding

Forwarding phase

Known unicast → one port; unknown/broadcast → flood within VLAN."

STP converges (if configured)

Topology stabilization

Prevents loops by blocking redundant links."

Common edge cases and deeper points

Layer 2 Switching Quick Self-Test

1 / 4
Question · Term

What does a Layer 2 switch use to decide where to send a frame?

Click to reveal
Answer · Definition

It primarily uses the destination MAC address and consults the MAC address table (often keyed by VLAN as well).

Knowledge Check

Question 1 of 3
Q1Single choice

Which field is the primary basis for forwarding decisions in a Layer 2 Ethernet switch?