
Understanding LAN from a Front-End Developer’s Perspective: MAC Addresses, Ethernet Frames, and Switches
As front-end developers, we interact with networks every day.
Loading web pages, requesting APIs, fetching images, and establishing WebSocket connections—all of these rely on networks.
But most of the time, we deal with relatively high-level concepts:
HTTP requests
API responses
Status codes
Headers
Cookies
Cross-origin restrictions
CachingThese are certainly important.
But to truly understand how networks work, we can’t stay only at the HTTP layer.
Because a network request doesn’t “fly” directly from the browser to the server. It goes through many layers of processing, and one of the most fundamental among them is:
LAN communication.
In this article, we won’t talk about the internet or the complete process of a browser request.
We’ll focus on a smaller question:
In the same local area network, how does one device send data to another device?
This is the first building block for understanding computer networks.
Forget about the complex internet for now.
Let’s start with the network in your home.
You might have these devices at home:
Smartphone
Computer
Tablet
TV
Game console
RouterThey’re all connected to the same Wi-Fi.
In this situation, all these devices are on a small-scale network.
This network is called:
LAN, Local Area Network.
Simply put:
A local area network is a network within a limited area.
For example:
Home Wi-Fi network
Office internal network
School computer lab network
Company floor networkThese can all be considered LANs.
The problem a LAN solves is straightforward:
Within a limited area, how do devices find and deliver data to each other.
Suppose your computer and smartphone are connected to the same Wi-Fi.
Your computer wants to send some data to your phone:
helloThe question arises:
How does the computer know which device is the smartphone?
It can’t say:
Send to that black phoneMachines won’t understand that.
It also can’t say:
Send to my phoneNetwork devices won’t understand that either.
So, in a network, devices need a machine-readable identifier.
At the LAN layer, this identifier is:
The MAC address.
First, remember this:
A MAC address is the identity of a network interface card (NIC) within a LAN.
Every device that can connect to a network usually has a NIC.
For example:
- A computer’s Wi-Fi adapter
- A computer’s Ethernet adapter
- A smartphone’s Wi-Fi module
- A router’s network interface
- A server’s NIC
Each of these NICs has its own MAC address.
A MAC address typically looks like this:
A4:5E:60:C1:2B:9FOther examples:
38:F9:D3:7A:11:20
E8:9F:80:AA:34:01
CC:2D:E0:12:88:ABSo, within a LAN, a device can refer to another device like this:
I want to send data to the device with MAC address 38:F9:D3:7A:11:20That’s much more precise than “send to that smartphone.”
There’s a point that’s easy to misunderstand:
A MAC address is not a device name, it’s the address of a network interface card.
One computer might have multiple NICs:
Ethernet NIC
Wi-Fi NIC
Bluetooth NIC
Virtual NICSo it might also have multiple MAC addresses.
For example, your laptop:
Wi-Fi MAC: A4:5E:60:C1:2B:9F
Ethernet MAC: 10:7B:44:91:AA:02
Virtual NIC MAC: 02:42:AC:11:00:02So, more accurately:
A MAC address identifies a specific network interface, not the abstract “this computer.”
But for now, as a beginner, you can roughly think of it as:
The identifier of a networked device in a LANLater, when we talk about multiple NICs, virtual NICs, and container networks, we’ll refine this concept.
Suppose a computer wants to send to a smartphone:
helloIt can’t just throw hello into the network.
Because the LAN may have more than one device:
Computer
Smartphone
Tablet
TV
RouterIf it only sends:
helloOther devices won’t know:
Who is this hello for?
Who sent it?
Is the data corrupted?
What type of data is this?So, real LAN communication doesn’t send data naked.
It wraps the data.
In Ethernet, this wrapper is called:
An Ethernet frame.
You can think of it as:
A package in the LAN.
An Ethernet frame is the basic format for transmitting data in a LAN.
A simplified Ethernet frame can be thought of as:
Ethernet Frame [
Destination MAC Address
Source MAC Address
Type
Data Payload
Error Checking Information
]For example, if a computer wants to send hello to a smartphone, it might wrap it as:
Destination MAC: 38:F9:D3:7A:11:20
Source MAC: A4:5E:60:C1:2B:9F
Type: IPv4
Data: hello-related data
Error Checking: Used to detect transmission errorsDon’t worry about each field of a real Ethernet frame for now.
Just grasp the core idea:
In a LAN, what’s transmitted is not just raw data; it’s a data frame that includes addressing information.
In other words, a device doesn’t send:
helloInstead, it sends:
Who is this for?
Who sent it?
What type is it?
What’s the actual data?
Was it corrupted during transmission?All this information together makes a frame.
The destination MAC’s role is simple:
Tell the LAN who should receive this frame.
For example:
Destination MAC: 38:F9:D3:7A:11:20Means:
This frame is for the device with MAC address 38:F9:D3:7A:11:20.If the smartphone’s MAC address happens to be:
38:F9:D3:7A:11:20Then the smartphone will know:
This is for me; I’ll process it.Other devices that see the frame will realize:
The destination MAC isn’t me; drop it.So, the destination MAC solves:
Whom this data frame should be delivered to.
The source MAC’s role is:
Tell the recipient who sent this frame.
For example:
Source MAC: A4:5E:60:C1:2B:9FMeans:
This frame was sent by the device with MAC address A4:5E:60:C1:2B:9F.The source MAC has at least two important roles.
Computer to smartphone:
Destination MAC: smartphone
Source MAC: computer
Data: helloWhen the smartphone replies, it can swap them:
Destination MAC: computer
Source MAC: smartphone
Data: hiWithout the source MAC, the smartphone wouldn’t know who sent the hello, and wouldn’t know whom to reply to.
When a switch receives a frame, it observes its source MAC.
For example, a frame arrives at switch port 1:
Source MAC: A4:5E:60:C1:2B:9F
Arrival port: 1The switch can learn:
Device A4:5E:60:C1:2B:9F is on port 1This mechanism will be detailed later.
So, the source MAC is not just “marking the sender”; it also helps the switch build a forwarding table.
Now let’s set Wi-Fi aside for a moment and look at a wired LAN.
Suppose several computers are connected to a switch:
Computer A ──┐
Computer B ──┼── Switch
Computer C ──┘A switch’s role is:
Connect multiple devices in the same LAN and forward Ethernet frames based on MAC addresses.
For example, Computer A wants to send data to Computer C.
It sends an Ethernet frame:
Destination MAC: Computer C’s MAC
Source MAC: Computer A’s MAC
Data: helloWhen the switch receives this frame, it checks:
Whose destination MAC is this?
Which port is this MAC address on?If the switch knows Computer C is on port 3, it will only forward the frame to port 3.
It won’t send the frame to all devices.
That’s the basic job of a switch:
Based on the destination MAC, forward the frame to the correct port.
This is very important.
A switch operates at a lower layer.
It doesn’t care if you’re visiting:
example.com
qq.com
bilibili.com
github.comNor does it care if you’re transmitting:
HTML
CSS
JavaScript
JSON
Images
VideosTo the switch, it mainly sees:
Whose destination MAC is this?
Whose source MAC is this?
Which port should this frame go out of?So remember this:
Switches don’t understand application-layer semantics; they forward Ethernet frames based solely on MAC addresses.
This is somewhat similar to layering in front-end development.
For example, a low-level HTTP library doesn’t care about page UI; it’s only responsible for sending requests.
Similarly, a switch:
Doesn’t care about upper-layer applications; it’s only responsible for forwarding data frames within the LAN.A switch doesn’t initially know where all devices are.
It learns.
Suppose there are three computers:
Computer A connected to switch port 1
Computer B connected to switch port 2
Computer C connected to switch port 3At first, the switch might know nothing.
Now, Computer A sends a frame.
This frame enters the switch on port 1:
Source MAC: AA:AA:AA:AA:AA:AA
Destination MAC: CC:CC:CC:CC:CC:CC
Entry port: 1When the switch sees the source MAC, it remembers:
AA:AA:AA:AA:AA:AA is on port 1Then, Computer C replies with a frame.
This frame enters the switch on port 3:
Source MAC: CC:CC:CC:CC:CC:CC
Destination MAC: AA:AA:AA:AA:AA:AA
Entry port: 3The switch learns:
CC:CC:CC:CC:CC:CC is on port 3Gradually, the switch builds an internal table:
MAC Address Port
AA:AA:AA:AA:AA:AA 1
BB:BB:BB:BB:BB:BB 2
CC:CC:CC:CC:CC:CC 3This table is usually called:
MAC address table.
Or:
Forwarding table.
So, the switch doesn’t know device locations because you told it; it’s because:
It automatically learns by observing the source MAC address of each frame.
We can simplify the switch’s frame-handling process into three steps.
Step 1: Look at the source MAC, learn which port it came from
Step 2: Look at the destination MAC, decide where to forward it
Step 3: If the destination MAC is unknown, broadcastLet’s break it down.
The switch receives a frame:
Source MAC: AA:AA:AA:AA:AA:AA
Entry port: 1So it remembers:
AA:AA:AA:AA:AA:AA is on port 1This is called learning.
Then the switch looks at the destination MAC:
Destination MAC: CC:CC:CC:CC:CC:CCIf the MAC address table says:
CC:CC:CC:CC:CC:CC is on port 3The switch forwards the frame to port 3.
If the switch doesn’t find the destination MAC, it doesn’t know where to send the frame.
In that case, it broadcasts.
Broadcasting means:
Send the frame to all ports except the one that received it.
For example:
Computer A is looking for Computer C
The switch doesn’t know which port C is on
So the switch sends the frame to B, C, DThen:
C sees the destination MAC is itself, so it accepts
B and D see the destination MAC is not them, so they drop itWhen Computer C replies, the switch can learn from Computer C’s source MAC:
Computer C is on port 3After that, when sending to Computer C, it doesn’t need to broadcast anymore.
Broadcasting is common in LANs.
When devices don’t know certain information, they may need to broadcast.
For example:
Who has this IP?
Who can answer me?
Where is the device with this address?Broadcasting is simple and straightforward.
If you don’t know where the target is, just ask everyone.
But broadcasting has a cost.
Because broadcasting makes multiple devices in the LAN receive the data, even though most devices will eventually drop it.
If there’s too much broadcasting, the whole LAN becomes noisy.
Imagine someone in an office shouting:
Who is Zhang San?
Who is Li Si?
Who’s responsible for this?
Who knows that?Shouting occasionally is fine.
But if everyone keeps shouting, the office becomes chaotic.
So broadcasting is an important mechanism in LAN communication, but it shouldn’t be overused.
Devices in your home are usually connected to a “router.”
But strictly speaking, a home router is usually not a single-function device.
It often integrates multiple functions:
Routing functions
Switching functions
Wireless AP functions
DHCP functions
NAT functions
Firewall functionsIn this article, we’ll only care about two concepts:
Switch: connects devices in the same LAN
Wireless AP: allows wireless devices to join the LANIf your computer and smartphone are connected to the same Wi-Fi, they’re actually joining the same LAN through a wireless access point.
Within the LAN, devices still rely on similar Layer 2 communication mechanisms:
MAC addresses
Data frames
Forwarding
BroadcastingSo, even though a home device looks like a single box, it actually plays many network roles.
As a beginner, you can think of it this way:
A home router is not just a router; it usually also acts as a LAN switch and a wireless access point.
When learning networking, many people confuse MAC addresses and IP addresses.
In this article, we won’t talk about IP addresses in detail.
Let’s just make a preliminary distinction:
MAC address: Used within a LAN to deliver data frames
IP address: Used to locate the destination across different networksOr more roughly:
MAC address: Whom to deliver to on this small segment
IP address: Where the final destination isFor example, when you visit a website from home.
From a broader network perspective, the destination might be a remote server’s IP.
But on the small segment of your home LAN, the computer usually first sends data to the router.
At that moment, what’s actually used in the LAN is:
The router’s MAC addressNot the remote server’s MAC address.
But we’ll stop here for now.
In the next article about ARP, we’ll formally answer this question:
If I only know an IP address, how do I know the corresponding MAC address?
In this article, you only need to remember the main thread of LAN communication.
A LAN is a network within a limited area.
For example:
Home Wi-Fi
Office network
School computer lab networkIt solves the problem of devices communicating within a limited area.
A MAC address is the identifier of a network interface card in a LAN.
In a LAN, devices need MAC addresses to know whom to send data to.
An Ethernet frame is the basic package for transmitting data in a LAN.
It contains at least these key pieces of information:
Destination MAC
Source MAC
Data payload
Error checking informationDevices don’t send raw data; they send data frames.
A switch forwards Ethernet frames based on MAC addresses.
It looks at the destination MAC and decides which port to send the frame out of.
A switch learns which port a device is on by observing source MAC addresses.
For example:
Source MAC AA comes in on port 1The switch remembers:
AA is on port 1Broadcast.
It sends the frame to all ports except the one that received it.
The target device receives and processes it; other devices see it’s not for them and drop it.
This article can be summarized in one sentence:
In a LAN, devices identify each other by MAC addresses, data is wrapped in Ethernet frames, and switches forward frames to the correct port based on a MAC address table.
Compressed further:
MAC addresses identify devices
Ethernet frames wrap data
Switches forward frames
MAC address tables record device locations
Broadcasting handles “temporarily not knowing where the destination is”Now we know:
LAN communication requires a destination MAC addressBut a new problem arises.
In reality, we often know the IP address first, not the MAC address.
For example:
192.168.1.23So the question is:
If I only know the other device’s IP address, how do I know its MAC address?
This leads to a very important protocol in LANs:
ARPThe next article can continue with:
What is ARP
Why ARP requests are broadcast
What is an ARP reply
What is ARP cache
Why we look up the gateway’s MAC when accessing the internetThis article is enough for now.
Its goal isn’t to explain the entire network request process, but to clarify the three most fundamental things in a LAN:
MAC addresses
Ethernet frames
Switch forwarding