Layer 2

On this page 7

Layer 2 is the data link layer of the OSI reference model, responsible for delivering frames between devices on the same local network segment using hardware addresses. In networking, and in Ethernet and switching in particular, Layer 2 is where Ethernet frames, MAC addresses, switches and VLANs operate: a switch forwards traffic by reading the destination MAC address, without looking at IP addresses.

Layer 2 sits between the physical layer, which moves bits over copper, fiber or radio, and Layer 3, which routes packets between networks. Its scope ends at the broadcast domain: every device that receives a broadcast frame belongs to the same Layer 2 network, and reaching anything beyond it requires a router or Layer 3 switch.

What Layer 2 does in an Ethernet network

The data link layer performs framing, addressing and error detection. It wraps each Layer 3 packet in a frame with source and destination MAC addresses, a type field and a frame check sequence (FCS), a 32-bit CRC that lets the receiver discard corrupted frames. Ethernet detects errors but does not retransmit; recovery is left to higher layers such as TCP.

The IEEE divides the layer into two sublayers: Logical Link Control (LLC), defined in IEEE 802.2, and Media Access Control (MAC), defined per technology such as IEEE 802.3 for Ethernet and IEEE 802.11 for wireless LANs. The table below shows the main fields of an Ethernet frame.

FieldSizePurpose
Destination MAC6 bytesReceiving interface or group
Source MAC6 bytesSending interface
802.1Q tag (optional)4 bytesVLAN ID and priority
EtherType2 bytesPayload protocol, for example 0x0800 for IPv4
Payload46 to 1500 bytes standardLayer 3 packet; jumbo frames up to about 9000 bytes
Frame check sequence4 bytesCRC for error detection
Main fields of an Ethernet II frame

How Layer 2 switching forwards frames

A switch builds a MAC address table, also called a CAM table, by noting the source address of each incoming frame and the port it arrived on. For each frame it then decides between forwarding, filtering and flooding. Entries age out after a timer, commonly 300 seconds, so the table follows devices that move.

Destination typeSwitch actionResult
Known unicast MACForward to the learned port onlyEfficient, private delivery
Unknown unicast MACFlood to all ports in the VLANReaches the device until it is learned
Broadcast FF:FF:FF:FF:FF:FFFlood to all ports in the VLANUsed by ARP and DHCP
MulticastFlood, or forward selectively with IGMP snoopingGroup traffic such as video
Destination on the arrival portFilter, do not forwardPrevents needless traffic
Switch forwarding decisions

Because frames carry no time-to-live field, a physical loop between switches would circulate broadcasts indefinitely and cause a broadcast storm. The Spanning Tree Protocol family (IEEE 802.1D, Rapid STP in 802.1w and MSTP) prevents this by blocking redundant links until they are needed.

Layer 2 compared with Layer 3

The most common design question is where Layer 2 should end and Layer 3 should begin. The differences below explain why modern networks keep Layer 2 domains small and route between them.

AspectLayer 2Layer 3
Address usedMAC address, flat 48 bitsIP address, hierarchical
DeviceSwitch or bridgeRouter or Layer 3 switch
ScopeOne broadcast domain or VLANBetween networks
Loop protectionSpanning tree, no TTL in framesTTL or hop limit in packets
Path useBlocked redundant linksEqual-cost multipath possible
Failure impactStorm can affect whole domainContained to routing scope
Layer 2 and Layer 3 side by side

Layer 3 switches blur the boundary by performing both functions in hardware: switching within a VLAN and routing between VLANs at line rate.

Layer 2 features used in practice

Managed switches add Layer 2 features that segment, protect and scale the network. VLANs (IEEE 802.1Q) split one physical switch into several broadcast domains, and trunk ports carry many VLANs with tags.

FeatureWhat it doesWhen to use it
VLAN taggingSeparates traffic into logical networksUsers, voice, guests and servers
Link aggregation (LACP)Bundles links into one logical linkMore bandwidth and redundancy
Rapid spanning treeBlocks loops and recovers in secondsAny network with redundant links
Port securityLimits MAC addresses per portPublic or shared access ports
DHCP snooping and ARP inspectionBlocks rogue servers and ARP spoofingAccess layer of enterprise networks
802.1X port authenticationRequires devices to authenticateControlled office access
Common Layer 2 features and their purpose

Risks and common mistakes

Layer 2 problems tend to spread widely because everything in a broadcast domain shares fate. Most incidents come from loops, oversized domains and missing access-layer protection.

  • Disabling spanning tree to simplify configuration leaves the network one patch cable away from a storm.
  • Very large VLANs spanning many buildings increase broadcast load and widen the impact of failures.
  • MAC flooding attacks overflow the address table and turn a switch into a hub unless port security is enabled.
  • Native VLAN mismatches on trunks leak traffic between VLANs and enable VLAN hopping.
  • MTU mismatches with jumbo frames cause silent drops of large frames only.

The simple explanation

Think of a single office floor. Everyone sits in the same open space, and internal mail is delivered by name tag on each desk, without the postal system. Layer 2 is that internal delivery, where every device on the local network has a fixed name tag, its MAC address.

A switch acts like the floor’s mail clerk. It learns which desk each name tag belongs to and delivers each letter only there. When a letter must go to another building, it is handed to a router, which works at the next level up, Layer 3.

How it is used in practice

A manufacturing company runs one flat Layer 2 network across three halls, with about 900 devices in a single VLAN. One morning a technician connects a spare cable between two wall ports, and because spanning tree had been disabled years earlier, a broadcast storm stops production lines for 40 minutes.

The network team redesigns the plant. Each hall receives its own VLANs for machines, offices and cameras, Rapid Spanning Tree with BPDU guard protects access ports, and a Layer 3 switch routes between VLANs. Uplinks use LACP bundles for redundancy. A later test loop is shut down within a second on a single port, and no other hall notices the event.