Layer 2 Switch: How It Forwards Ethernet Traffic
In this article
A layer 2 switch is a network device that forwards Ethernet frames based on the destination MAC address. You connect devices—computers, printers, IP cameras, other switches—to its ports, and it learns which MAC addresses are on each port, then sends each frame only to the port where the destination device lives. This is the core of a modern wired LAN, replacing the old hub that repeated every frame to every port.
How a Layer 2 Switch Differs from a Hub or Router
A hub is a physical-layer device: it repeats every signal to every port. A switch works at the data-link layer (layer 2) and uses MAC addresses. A router works at the network layer (layer 3) and uses IP addresses. The switch does not look at IP addresses; it only cares about MAC addresses. This is why a switch can forward traffic faster and more securely than a hub—it does not broadcast everything.
Some switches are called “layer 3 switches” because they can also route IP traffic. But a pure layer 2 switch only forwards Ethernet frames.
How the MAC Table Is Built and Maintained
When a frame arrives, the switch reads the source MAC address. It adds or updates an entry in the table: MAC address → port. This is called “learning.” The table has an aging timer; if no frame from that MAC arrives within the timeout (often 300 seconds), the entry is removed. This allows devices to move to different ports without manual configuration.
If a frame arrives with a destination MAC that is not in the table, the switch floods it to all ports except the ingress port. The intended device will receive it and reply, at which point the switch learns its location. This is how the table builds itself automatically.
Common Problems and Misconceptions
- Broadcast storms: A switch floods broadcast frames (destination FF:FF:FF:FF:FF:FF) to all ports. If many devices send broadcasts, the network can become congested. This is normal behavior, not a fault.
- MAC table overflow: If the table fills up, the switch may start flooding all frames, degrading performance. This can be caused by a malicious attack or by a network with too many unique MAC addresses.
- Loops: If you connect two switches with two cables, a loop is created. Frames can circulate forever, causing a broadcast storm. The Spanning Tree Protocol (STP) prevents this by blocking redundant paths.
- VLANs: A layer 2 switch can be configured with Virtual LANs (VLANs) to separate traffic logically. Frames are tagged with a VLAN ID (IEEE 802.1Q) and only forwarded within the same VLAN.
How to Choose a Layer 2 Switch
Key factors to consider:
- Number of ports: Common sizes are 5, 8, 16, 24, or 48 ports. Count your devices and add some spare.
- Port speed: Gigabit (1000 Mbps) is standard for desktop use. 10-Gigabit is for high-bandwidth servers or backbone links.
- Managed vs. unmanaged: Unmanaged switches are plug-and-play with no configuration. Managed switches allow VLANs, QoS, port mirroring, and STP control. For home or small office, unmanaged is often enough.
- PoE (Power over Ethernet): If you have IP cameras or VoIP phones, PoE delivers power over the same cable. Check the total power budget.
- Form factor: Desktop (small, fanless) or rack-mountable for a server room.
Safety and Best Practices
Layer 2 switches are low-voltage devices, but basic safety applies:
- Use the supplied power adapter; do not overload power strips.
- Keep the switch in a well-ventilated area to prevent overheating.
- Do not block vents or stack devices without clearance.
- For managed switches, change default passwords and disable unused ports to prevent unauthorized access.
- Use STP (Spanning Tree Protocol) on managed switches to prevent loops.
Frequently Asked Questions
What is the difference between a layer 2 switch and a layer 3 switch?
A layer 2 switch forwards frames based on MAC addresses and operates within a single broadcast domain. A layer 3 switch can also route packets based on IP addresses, allowing it to connect different VLANs or subnets without an external router.
Can I use a layer 2 switch to connect to the internet?
Yes, but the switch itself does not provide internet access. You need a router or modem/router that performs network address translation (NAT) and connects to your ISP. The switch simply extends your LAN.
How many devices can I connect to a switch?
You can connect as many devices as you have ports, but the total number of unique MAC addresses is limited by the switch’s MAC table size. For most home switches, that’s thousands, so it’s rarely a limitation.
Why is my switch flooding all ports?
Flooding occurs when the destination MAC is unknown or when it’s a broadcast/multicast frame. If it happens constantly, check for a network loop (use STP), a MAC table overflow, or a malfunctioning device sending many frames with unknown destinations.
Do I need a managed switch for home use?
Usually not. Unmanaged switches are cheaper, simpler, and work fine for typical home networks. Managed switches are useful if you want VLANs, traffic prioritization, or remote monitoring.