A network switch with ethernet cables connected.

The Network Sorter: Understanding The Layer 2 Switch

NETWORKINGHARDWAREMAC ADDRESS

11/12/20255 min read

A network switch with ethernet cables connected.
A network switch with ethernet cables connected.

The Network Smart Sorter: Understanding the Layer 2 Switch

If the router is the traffic controller of the internet working with IP addresses at Layer 3, the switch is the smart sorter within your local network working with MAC addresses at Layer 2. It's the device that makes local area networks (LANs) fast, efficient, and reliable.

Unlike its older, not very intelligent cousin, the hub, a switch doesn't just blindly repeat data; it intelligently directs it only to the intended recipient. Understanding this device is essential for anyone starting their networking journey.

Get excited. It's time to talk Layer 2 switches.

1. What is a Layer 2 Switch and What is its Purpose?

A network switch is a device that connects multiple computers, servers, and other network devices within a single Local Area Network (LAN). It operates primarily at Layer 2 (the Data Link layer) of the OSI model.

Primarily Used For:

  • Connecting Devices: Switches provide physical ports (commonly ethernet or RJ45 connections) to connect every device in your office or home with a physical cable, creating a communication backbone.

  • Segmenting Traffic: By directing data only to the destination device, switches prevent unnecessary traffic from slowing down other devices on the network.

  • Scalability: Switches allow you to easily add more devices to your network without needing to overhaul the entire infrastructure.

2. How a Switch Works: Data Units and Addresses

The Data Unit: The Frame

At Layer 2, data is packaged into a unit called a Frame. The frame contains not only the data payload but also crucial header information, including the source and destination MAC addresses.

The Identifier: The MAC Address

The switch relies entirely on the MAC (Media Access Control) address to make forwarding decisions.

  • What it is: A MAC address is a physical, hard-coded 48-bit address assigned by the manufacturer to every network interface card (NIC). It is globally unique.

  • Format: It is typically written as six pairs of hexadecimal digits separated by colons or hyphens (e.g., 00:1A:2B:3C:4D:5E).

  • Role: While the IP address (Layer 3) tells the router where the network is, the MAC address (Layer 2) tells the switch which specific device on the local segment the data should go to.

  • Analogy: Think of the IP address (Layer 3) as the street while the MAC address (Layer 2) is the specific house or building number on that street.

The Switch's Map: The MAC Address Table

A switch keeps a map of its local network called the MAC Address Table (also referred to as the Content Addressable Memory, or CAM Table).

This table is the switch's internal brain, storing two key pieces of information:

  1. The MAC Address of a device.

  2. The corresponding Port Number on the switch where that device is connected.

3. How a Switch Learns Where to Send Data

A switch operates using a simple, three-step logic process for every incoming frame: Learn, Forward/Filter, Flood.

Step 1: Learn (Source Address)

When a frame arrives on a port, the switch immediately examines the frame's source MAC address.

  • It records this MAC address and the port it came in on (e.g., "MAC A is on Port 1").

  • It adds this entry to its MAC Address Table. This is how the switch learns where a device is on the network.

Step 2: Forward or Filter (Destination Address)

The switch then looks at the frame's destination MAC address and checks its MAC Address Table:

  • Filter (Local): If the destination MAC address is found on the same port where the frame arrived (i.e., the sender and receiver are connected to the same port), the switch drops the frame (filters it).

  • Forward (Unicast): If the destination MAC address is found on a different port, the switch forwards the frame only to that single port. This is called Unicast communication.

Step 3: Flood (Unknown Address)

If the switch does not find the destination MAC address in its table, it must find the device:

  • The switch floods the frame out of all ports, except the port it arrived on.

  • When the destination device responds, the switch completes the learning process (Step 1) and updates its table, so future frames can be directly forwarded.

4. Collision Domains and Switches

A major advantage of the switch over the older hub is how it handles collision domains.

A collision domain is a network segment where data signals can collide. When two devices in the same collision domain transmit data simultaneously, the data becomes corrupted, and both devices must retransmit.

  • Hubs: A hub is a single electrical segment, meaning the entire network connected to it is one large collision domain. If 10 devices are connected, they all compete, severely limiting speed and efficiency of the network.

  • Switches: A switch creates a separate collision domain on every single port. When you connect a PC to Port 1, that PC has its own dedicated, collision-free segment. Meaning there are no other devices connected to Port 1 on the switch to send data signals that could collide with the data signals sent by PC 1.

This segmentation ensures that a switch can effectively handle simultaneous traffic flow between multiple pairs of devices, operating in full-duplex mode (sending and receiving at the same time).

5. Managed vs. Unmanaged Switches

When researching switches online you'll probably notice that most SOHO (Small Office Home Office) switches are labeled either as a Managed Switch or an Unmanaged Switch. There are crucial differences between these two devices even though they look very similar in most cases.

Unmanaged Switches:

  • "Plug-and-Play": These are the simplest switches, requiring no setup. You plug them in, and they start working using the auto-learning process described above.

  • Use: Small offices, home networks, or simple workgroups where basic connectivity is the only requirement.

  • Cost: Generally inexpensive.

Managed Switches:

  • Configurable: These switches offer an administrative interface (via web browser, SSH, or console cable) that allows administrators to configure, manage, and monitor the network.

  • Advanced Features: They support crucial network functions like VLANs (Virtual Local Area Networks), Quality of Service (QoS) for prioritizing traffic (like VoIP), security features, and port mirroring. Providing you with a lot more control when compared to an unmanaged switch.

  • Use: Large businesses, data centers, and networks requiring segmentation and centralized control.

  • Cost: More expensive than their unmanaged counterparts, due to its advanced features.

6. Switch vs. Hub: A Historical Comparison

To truly appreciate the switch, it's helpful to see how it differs from the original Layer 1 device, the hub.

7. How to Connect a Switch

Connecting a switch is straightforward, especially if it is unmanaged.

  1. Power: Plug the switch into an electrical outlet.

  2. Uplink (Connection to the Router): Take an Ethernet cable and connect one end to the specified port on the switch and the other end to a LAN port on your router. This is the uplink that provides internet access to the switch.

  3. Client Devices: Connect all your computers, servers, printers, and other wired devices directly to the remaining available ports on the switch using standard Ethernet cables.

The switch will immediately begin its learning process (Think Back to Step 1), and within seconds, all your connected devices will be able to communicate with each other and access the internet via the router.

Glossary of Switching Terms

Value Delivered Straight To Your Inbox

Save yourself the headache of searching. Subscribe to stay updated with our latest content, industry news, and helpful resources.