Sub topic 1
Where MAC addresses live: LANs and the link layer
A MAC address only makes sense once you know where it operates. It does not identify a device across the internet. It identifies a network interface on one local network segment. This chapter sets up that scope: what a LAN is, what the link layer does, and why the rest of the tutorial treats MAC addresses as a local, hop-by-hop concern.
Prerequisites
This chapter assumes you already know the following:
- A network connects devices so they can exchange data, and an IP address identifies a host on that network.
- You can read hexadecimal and binary numbers, for example that
0xffis11111111. - You can open a terminal and run commands. The examples use Linux
ipcommands, but the ideas apply to every operating system.
You do not need to know how a MAC address is built or how switches work. Later chapters cover both.
What a LAN is
A local area network (LAN) is a group of devices that can reach each other directly, without a router in between. A home network, an office floor, and a server rack are all typical LANs. The devices on a LAN connect through the same switches or the same Wi-Fi access points.
The technical definition that matters for MAC addresses is the broadcast domain. A broadcast domain is the set of devices that all receive a frame when one of them sends it to the special "everyone" address. If your laptop sends a broadcast and a phone on the same Wi-Fi network receives it, they share a broadcast domain. A server in another building behind a router does not receive it.
Routers are the boundary. A router connects separate LANs and does not forward broadcasts between them. This is why one LAN is also called one layer 2 network, and why the rest of the internet is reached through a router and not directly.
Layers and the link layer
Network software is organized into layers. Each layer solves one problem and relies on the layer below it. This tutorial uses the four-layer TCP/IP model, with the OSI layer numbers noted because switch and router documentation uses them often.
| TCP/IP layer | OSI layer | Example protocols | Addressing used |
|---|---|---|---|
| Application | 5 to 7 | HTTP, DNS, SSH | Names and URLs |
| Transport | 4 | TCP, UDP | Port numbers |
| Internet | 3 | IP, ICMP | IP addresses |
| Link | 1 and 2 | Ethernet, Wi-Fi | MAC addresses |
The link layer moves data between two devices that are directly connected, such as two machines on the same switch or the same Wi-Fi network. It handles three jobs:
- It defines how bits are carried over a physical medium (copper, fiber, radio). This is the physical part, OSI layer 1.
- It packages data into frames, each with a header that says who sent it and who should receive it. This is OSI layer 2, the data link layer.
- It decides how devices share the medium, so that two senders do not corrupt each other's signal.
MAC addresses belong to the second job. A MAC address (Media Access Control address) is the address written into the frame header so that a receiver on the same link can tell whether a frame is meant for it.
Why two kinds of address
It is fair to ask why IP addresses are not enough. The two address types answer different questions.
- An IP address says which host the data is ultimately for. It is hierarchical, so routers can summarize whole ranges of addresses, and it can be reassigned when a device moves.
- A MAC address says which interface on this link should accept this frame. It is flat. It carries no information about where the device is, so a switch cannot summarize it. It is also set by the manufacturer or the operating system, not by the network.
These two address types depend on each other. IP delivers a packet across many links. On each link, the packet is wrapped in a frame addressed by MAC. Neither can do the whole job alone.
Where a MAC address sits in a transmission
When your laptop sends a web request, the data is wrapped step by step. The application data is placed in a TCP segment, which is placed in an IP packet, which is placed in an Ethernet frame. The frame header holds the MAC addresses. The IP header inside it holds the IP addresses.
The receiver reverses the process. Its network interface first checks the destination MAC in the frame header. If the frame is not addressed to that interface, a broadcast, or a multicast group the interface has joined, the hardware discards it. The operating system never sees it. This is the first filter in the stack, and it happens before any IP processing.
Frames stay on one link
A frame travels across exactly one link. A router that receives a frame strips off the link layer header, reads the IP packet inside, decides where it goes next, and builds a new frame for the next link. The IP addresses stay the same through this process, and the MAC addresses are replaced. Chapter "Why MAC addresses change at every router hop" walks through the details. For now, remember the rule:
- IP addresses describe the end-to-end journey.
- MAC addresses describe a single hop.
The diagram below shows two LANs joined by a router. Frames never cross the router. Each LAN is its own broadcast domain.
Ethernet and Wi-Fi share the same address format
Wired Ethernet (IEEE 802.3) and Wi-Fi (IEEE 802.11) are different link layer technologies with different headers and different ways of sharing the medium. Both use the same 48-bit MAC address format, which is defined by the IEEE 802 family of standards. This is why a laptop's Wi-Fi interface and Ethernet port each have their own MAC address, and why a bridge between a Wi-Fi network and a wired network can pass traffic along without redesigning addressing.
Note that each interface has its own address, not each device. A laptop with a wired port, a Wi-Fi radio, and a Bluetooth chip has three. A virtual machine or a container usually gets a virtual interface with its own generated MAC address as well.
Devices at the link layer
Different devices operate at different layers, and this determines how they treat MAC addresses.
| Device | Works with | Behavior |
|---|---|---|
| Hub (obsolete) | Electrical signals | Repeats every signal out of every other port. It does not read MAC addresses. |
| Switch | MAC addresses | Learns which MAC address is behind each port and forwards frames only where needed. |
| Wi-Fi access point | MAC addresses | Bridges wireless clients onto the wired LAN. |
| Router | IP addresses | Connects separate LANs. It reads MAC addresses only to receive frames and to address the next frame. |
A hub makes the whole LAN a single shared channel, so every device sees every frame. A switch is the reason modern LANs scale: it sends a frame only toward its destination when it knows where that is. How a switch learns this is covered in a later chapter.
Segmenting a LAN with VLANs
A single physical switch does not have to be a single broadcast domain. A virtual LAN (VLAN) splits one switch into several logical LANs. Frames in VLAN 10 are never delivered to ports in VLAN 20, even though both use the same hardware. Two devices in different VLANs need a router to talk to each other, exactly as if they were on different physical switches.
This matters for diagnosis. If two devices can't reach each other even though they are plugged into the same switch, they may be in different VLANs, which means different broadcast domains. In that case no MAC-level communication between them is possible.
Seeing the link layer on your machine
You can see the link layer directly. On Linux, ip link show lists the interfaces, and the link/ether field is the MAC address of each one.
# Show the MAC address (link/ether) of every interface
ip link show
# Show the IPv4/IPv6 neighbor table (IP to MAC mappings)
ip neigh showThe output looks like this on a typical machine (addresses will differ):
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 02:00:5e:10:00:01 brd ff:ff:ff:ff:ff:ffTwo details are worth noticing now. The flag BROADCAST means this interface supports sending to the all-devices address, and brd ff:ff:ff:ff:ff:ff shows that address. The mtu 1500 value is the largest payload a frame on this link can carry. Both come from the link layer, not from IP.
ip neigh show lists the neighbors your machine has recently talked to on the LAN. Each entry pairs an IP address with the MAC address learned for it. Entries exist only for machines on your own LAN. You will not see entries for distant web servers, because you never send frames directly to them. Later chapters explain how this table is filled.
Common misunderstandings
- "A MAC address identifies a device on the internet." It does not. Remote servers never see your MAC address, because it is removed at the first router.
- "Each computer has one MAC address." Each network interface has one, and a computer usually has several, including virtual ones.
- "A switch reads IP addresses." A basic switch reads only the frame header. Switches that also route are layer 3 switches, and they combine both functions.
- "The MAC address cannot change." The manufacturer assigns a default, but the operating system can use a different one. A later chapter covers randomization and spoofing.
Summary of the model
A LAN is a broadcast domain, a set of devices that can reach each other with frames and no router. The link layer defines the frame and its addressing, and the MAC address is that address. Frames cross one link at a time, so MAC addresses are local and IP addresses are end to end. The remaining chapters build on this: the structure of the address, how switches use it, and how ARP maps IP addresses to it.
Exercise
Your laptop (192.168.1.20) pings a web server on the internet. You run ip neigh show right afterward. Would you expect to see an entry for the web server's IP address? Explain, and say which MAC address your laptop put in the destination field of the frame.
Show answer
No. The web server is not on your LAN, so your laptop never sends it a frame directly. The neighbor table only holds devices on the same link. The laptop sends the frame to its default gateway (the router), so the destination MAC in the frame is the router's MAC address. The IP packet inside still carries the web server's IP address as the destination. The neighbor table will contain an entry for the router's IP address instead.
Exercise
Two computers are plugged into the same physical switch but cannot exchange any frames. Give one link layer reason this can happen, and name the concept that explains it.
Show answer
The two ports may be assigned to different VLANs. A VLAN splits one switch into separate logical LANs, so each VLAN is its own broadcast domain and frames are not delivered between them. The computers would need a router (or a layer 3 switch) to communicate.