2. Ethernet & Switching
Frames, MAC addresses, and how a switch learns where everyone lives
Picture an open-plan office before anyone had phones on their desks. When you need to tell Priya something, you stand up and shout "Priya, it's Sam: the meeting moved to three!" Everybody in the room hears it. Everybody except Priya ignores it. If two people start shouting at the same moment, both stop, wait a random couple of seconds, and try again.
Now imagine the office hires a receptionist who sits in the middle of the room with a notepad. Every time someone speaks, the receptionist jots down which desk the voice came from. Soon, when someone says "message for Priya", the receptionist doesn't need to shout it to the whole room: they walk it straight to Priya's desk. When a name isn't on the notepad yet, they fall back to shouting.
That is Ethernet, old and new. The shouting room is the original shared-cable Ethernet of the 1970s and 80s. The receptionist is a switch, the box in your wiring cupboard or behind your TV. In the previous article we saw that an Ethernet frame is the outermost envelope around an IP packet, and we decoded our 95-byte example frame header by header. This time we stay at Layer 2 and ask the questions we skipped: what exactly goes on the wire, what is a MAC address made of, and how does a switch know which port to send a frame out of?
The Frame on the Wire
Here is the anatomy of an Ethernet frame as it actually crosses the cable, including the parts that packet capture tools never show you.
Field by field, using the frame from the Layers article, which carried a 77-byte IPv4 packet from your laptop to your router:
| Field | Size | Our frame | What it's for |
|---|---|---|---|
| Preamble | 7 B | 55 55 55 55 55 55 55 |
Alternating 1s and 0s so the receiver can lock on to the bit clock |
| SFD | 1 B | d5 |
Start Frame Delimiter: "the real frame starts now" |
| Destination MAC | 6 B | 02:00:00:cc:dd:02 |
Who this frame is for (the router) |
| Source MAC | 6 B | 02:00:00:aa:bb:01 |
Who sent it (the laptop) |
| EtherType | 2 B | 08 00 |
What's in the payload: IPv4 |
| Payload | 46–1500 B | 77 bytes of IPv4 | The packet being carried |
| Pad | 0–46 B | none | Zero bytes added if the payload is under 46 |
| FCS | 4 B | 21 57 c1 37 |
CRC-32 over destination MAC through pad |
| Interframe gap | 12 B | (silence) | Mandatory idle time before the next frame |
Preamble and SFD: "wake up, here it comes"
A receiver can't read bits until it knows exactly where each bit starts and ends. The
preamble is seven bytes of 0x55. Ethernet transmits each byte
least-significant bit first,
so on the wire 0x55 comes out as 10101010, and seven of them make a 56-bit square
wave that the receiver's clock-recovery circuit can sync to. The SFD, 0xd5, goes out as
10101011: the pattern breaks with two 1s in a row, and the very next bit is the first
bit of the destination address.
On modern fast links the physical layer has its own line coding and the preamble is partly vestigial, but the bytes are still there in the standard and still counted in the wire time.
Two addresses, destination first
Destination comes before source, and that ordering is deliberate. A network card (or a switch) wants to know as early as possible whether a frame is for it. With the destination in the first six bytes, a receiver can decide to ignore a frame, or a switch can start choosing an output port, before the rest has even arrived. We'll dig into what's inside those six bytes in the next section.
EtherType or length?
The two bytes after the source address have a split personality, thanks to Ethernet having two parents. The original DIX Ethernet (named for DEC, Intel and Xerox) used them as a type: "the payload is IPv4". The IEEE 802.3 standard used them as a length: "the payload is this many bytes long", and put the type information inside the payload instead, in an extra LLC header.
The two schemes coexist because the numbers don't overlap. The largest payload is 1500
bytes, and every EtherType ever assigned is 1536 (0x0600) or above, so a receiver just
looks at the value:
Value ≤ 1500 (≤ 0x05DC)
It's a length. This is an 802.3 frame, and the payload starts with an LLC header saying what's inside. Rare today, but not extinct: Spanning Tree BPDUs still use this format.
Value ≥ 1536 (≥ 0x0600)
It's an EtherType. The payload is whatever the type says:
0800 IPv4, 86dd IPv6, 0806 ARP,
8100 a VLAN tag. Nearly every frame you'll ever capture is this kind.
Values from 1501 to 1535 are simply undefined. IEEE folded the type interpretation into 802.3 itself in 1997, so both readings are now officially "Ethernet".
Payload, padding, and the 64-byte minimum
The payload is the packet from the layer above, 46 to 1500 bytes. The upper limit is the 1500-byte MTU we met last time. The lower limit is stranger: if the payload is shorter than 46 bytes, the sender appends zero bytes until it isn't. Why would anybody pay to transmit padding?
Add it up: 6 + 6 + 2 header bytes, 46 payload bytes, 4 FCS bytes = 64 bytes, the minimum Ethernet frame. Our example frame carried a 77-byte packet, so it was 95 bytes and needed no pad. But an ARP request (which you'll meet in the next article) is only 28 bytes, so it gets 18 bytes of zeros tacked on to reach 46.
The 64-byte rule is a fossil from the days when every computer shared one cable, and it only makes sense once you know how they took turns, so we'll return to it after a short history lesson.
FCS: the CRC-32 trailer
The last four bytes are the Frame Check Sequence, a CRC-32 computed over everything from the first byte of the destination MAC to the last byte of padding (not the preamble or SFD). The receiver runs the same calculation; if the result doesn't match, the frame is silently dropped. Ethernet never asks for a resend. Its promise is that a frame failing the check is never handed up, so corruption gets through only in the vanishingly rare case where the damaged bits happen to produce a matching CRC. Recovering the lost data is somebody else's problem (usually TCP's).
The FCS uses the generator polynomial 0x04C11DB7, the same CRC-32 used by zip, gzip and
PNG. The Checksums & CRC article in the Error Correction series shows
how the polynomial division works and why CRC-32 is guaranteed to catch every burst
error of 32 bits or fewer.
The interframe gap
After the FCS, the sender must stay silent for at least 96 bit-times (12 byte-times) before starting the next frame: 9.6 µs at 10 Mb/s, 96 ns at 1 Gb/s. This gives receivers a moment to finish processing one frame and reset for the next.
Frame sizes at a glance
The numbers worth remembering
header payload FCS frame
Minimum frame 14 46 4 64
Our example frame 14 77 4 95
Maximum frame 14 1500 4 1518
Max with 802.1Q tag 18 1500 4 1522
On the wire, add 8 (preamble + SFD) + 12 (gap) = 20 byte-times per frame.
The 802.1Q row is a frame carrying a 4-byte VLAN tag between the source MAC and the EtherType. That tag is how one physical switch can pretend to be several separate ones, and it gets its own article: VLANs.
MAC Addresses
Every Ethernet interface has a 48-bit address, written as six bytes in hex. Your
laptop's is 02:00:00:aa:bb:01. The name comes from the
Media Access Control
sublayer that uses them, though you'll also hear "hardware address", "physical address",
or, in Wi-Fi settings on phones, "Wi-Fi address".
The same address can be written several ways, and you'll see all of them in the wild:
| Style | Example | Where you'll see it |
|---|---|---|
| Colons | 02:00:00:aa:bb:01 |
Linux, macOS, Wireshark |
| Dashes | 02-00-00-AA-BB-01 |
Windows, the IEEE registry |
| Dotted (Cisco) | 0200.00aa.bb01 |
Cisco and other switch CLIs |
| Bare hex | 020000aabb01 |
Config files, databases |
Anatomy of 48 bits
A MAC address splits into two halves, and two of its bits are special:
The OUI. The first three bytes are the Organizationally Unique Identifier. A manufacturer buys one from the IEEE and then numbers its network cards using the remaining 24 bits, which gives it about 16.7 million addresses per OUI. Big vendors own hundreds of OUIs. A few you might recognise from the IEEE registry:
| OUI | Registered to |
|---|---|
00-00-00 |
Xerox (where Ethernet was born) |
00-00-0C |
Cisco Systems |
00-03-93 |
Apple |
00-50-56 |
VMware (virtual machines) |
08-00-27 |
PCS Systemtechnik (VirtualBox's default) |
B8-27-EB |
Raspberry Pi Foundation |
The I/G bit (Individual/Group) is bit 0 of the first byte, its lowest bit. If it's 0,
the address names a single interface: unicast. If it's 1, the address names a group
of interfaces: multicast. An address with every bit set,
ff:ff:ff:ff:ff:ff, is the special group "everybody on this network": broadcast.
The U/L bit (Universal/Local) is bit 1 of the first byte. If it's 0, the address is universally administered: it came from an IEEE-assigned OUI and should be unique in the world. If it's 1, it's locally administered: someone (an operating system, a hypervisor, a network admin) made it up, and only promises to be unique on its own network. The OUI half of a local address doesn't mean anything.
Decoding the first byte
Because both special bits live in the first byte, its second hex digit tells you most of what you need. Let's decode a few:
-
00:03:93:12:34:5600=0000 0000. I/G = 0, U/L = 0: a universal unicast address, a real card made by Apple. This is what a "burned-in" address looks like. -
02:00:00:aa:bb:0102=0000 0010. I/G = 0, U/L = 1: locally administered unicast. This is why this series uses02:...for every example host. No manufacturer can ever have shipped this address, so our examples can't accidentally describe someone's real laptop, just as the203.0.113.0/24block is reserved for documentation IPs. -
01:00:5e:00:00:fb01=0000 0001. I/G = 1, U/L = 0: multicast. This one carries IPv4 multicast to224.0.0.251, the group used by mDNS (how your printer announces itself). -
33:33:00:00:00:0133=0011 0011. I/G = 1, U/L = 1: multicast, locally administered. Every IPv6 multicast maps to a33:33:...address; this one is "all IPv6 nodes". -
ff:ff:ff:ff:ff:ffff=1111 1111. I/G = 1, and so is everything else: broadcast. Every interface on the network accepts it.
The second-hex-digit shortcut
Look at the second character of a MAC address. If it's odd (1, 3, 5, 7, 9, B, D, F), the I/G bit is set: it's multicast or broadcast, and no single device can own it. If it's 2, 6, A or E, it's a locally administered unicast address, very often a randomized one.
Why the first bit on the wire is the I/G bit
Remember that Ethernet sends each byte least-significant bit first. The destination address is the first field after the SFD, and the I/G bit is the lowest bit of its first byte, so the I/G bit is the very first bit of the frame proper. That's not an accident: an early network card could tell whether a frame was unicast or multicast after receiving a single bit. It's also why the IEEE describes these bits in transmission order, which makes the official documents confusing to read if you're used to writing binary with the high bit on the left.
A modern twist: MAC randomization
A universal MAC address is a fantastic tracking cookie. It's unique, it never changes,
and Wi-Fi devices used to broadcast theirs in probe requests to every access point in
range, so shops and airports could count and follow individual phones. Since
2019–2020, Android (from version 10) and iOS (from version 14) use a randomized,
locally administered address by default, typically a different one for each Wi-Fi
network. Windows and many Linux distributions offer the same option. If you look up your
phone's Wi-Fi address you'll likely see something like da:a1:19:3f:52:7e: second digit
a, so U/L = 1.
This has side effects for network admins: "allow only these MAC addresses" lists stop working, and a home router might see one phone as several devices over time. It's a good example of the U/L bit doing real work decades after it was designed.
MAC address
Any common format works: colons, dashes, Cisco dotted (0200.00aa.bb01) or 12 bare hex digits, in either case.
The 48 bits
Verdict
OUI and NIC-specific halves
Written four ways
Shared Cables and Collisions
To understand why switches matter, we need to go back to the shouting room.
Ethernet was invented at Xerox PARC in 1973 by Bob Metcalfe and David Boggs. The DIX consortium published a 10 Mb/s version in 1980, and the IEEE standardized it as 802.3 in 1983. The original medium was a single thick coaxial cable snaking through the building, with every computer tapped into it. Later networks used twisted-pair cable to a hub, but a hub is just that coax cable shrunk into a box: it repeats every bit it hears on one port out of every other port, instantly, without reading anything.
Either way, every station hears every frame, and there is one rule for sharing: CSMA/CD.
-
Carrier sense: listen first
If someone else is transmitting, wait until the cable goes quiet (plus the interframe gap).
-
Multiple access: then talk
Anyone may start transmitting once the cable is idle. There's no central coordinator.
-
Collision detection: listen while talking
Two stations can both hear silence and start at almost the same moment. Their signals overlap and garble each other: a collision. A transmitting station keeps monitoring the cable; if what it hears isn't what it's sending, it stops and sends a 32-bit jam signal so everyone knows the frame is junk.
-
Back off: wait a random time, then retry
After the nth collision on the same frame, a station waits a random number of slot times between 0 and 2n − 1 (capped at 1023 after ten collisions), then tries again. After 16 failed attempts it gives up. This is binary exponential backoff, and it spreads contending stations apart quickly.
The set of stations that can collide with each other is called a collision domain. On a hub, all ports are one collision domain, so adding computers means more collisions and less bandwidth each. Ten machines on a 10 Mb/s hub share 10 Mb/s between them.
Why 64 bytes
Now the minimum frame size makes sense. Collision detection only works if the sender is still transmitting when news of the collision gets back to it. If a short frame finishes before the collision reaches the sender, the sender walks away thinking the frame got through, and nobody will ever retransmit it.
The worst case is two stations at opposite ends of the network. Station A starts transmitting. Just before A's first bit reaches the far end, station B (hearing silence) starts too. The collision happens near B, and the garbled signal has to travel all the way back to A. So A must keep transmitting for at least one full round trip across the network. The standard calls that budget the slot time: 512 bit-times, which is 64 bytes.
That 51.2 µs had to cover signal propagation along the cable both ways, plus delays inside every repeater and transceiver along the path, which is why classic 10 Mb/s Ethernet limited a collision domain to about 2.5 km end to end. Any frame of at least 64 bytes is guaranteed to still be on the wire if a collision happens, and any fragment shorter than 64 bytes that a receiver sees must be collision debris, so it can be thrown away.
When the link got faster
At 100 Mb/s, the same 512 bits take only 5.12 µs, so the maximum diameter of a 100 Mb/s hub network shrank to roughly 200 m. Gigabit half-duplex would have shrunk it to about 20 m, so instead it stretched the slot time to 512 bytes with "carrier extension". Almost nobody used it: by then, everybody had switches.
Enter the Switch
A switch looks like a hub (a box full of Ethernet ports) but behaves completely differently. It receives each frame as a frame, reads the destination MAC, and sends it out only the port where that destination lives. Here's how the two compare:
Hub (Layer 1)
Repeats bits to every port. All ports form one collision domain. Half duplex: a station can send or receive, not both. Everyone shares the bandwidth, and everyone sees everyone's traffic.
Switch (Layer 2)
Forwards frames to the right port. Each port is its own collision domain, and with one device per port running full duplex (separate wire pairs for each direction, standardized in 802.3x in 1997), there's nothing left to collide with. CSMA/CD simply switches off. Each port gets its full speed in both directions at once.
So collisions are history. But one thing about the shouting room survives: a broadcast
frame (ff:ff:ff:ff:ff:ff) still goes out every port, and a switch passes it on to
any other switch connected to it. The set of devices that receive each other's broadcasts
is called a
broadcast domain,
and by default it's your entire switched network, every switch and every port. Routers
stop broadcasts; so do VLANs, which split one switch into several broadcast
domains.
How a Switch Learns
Here is the clever part. Nobody configures a home switch. You plug cables in, and within a second or two it knows which device is on which port. How?
It keeps a MAC address table (often called the CAM table): a list of entries of the form address → port, age. It starts empty and fills it using just two rules, one for each address in the frame:
The two rules of a learning switch
Learn from the source. When a frame arrives on port p from MAC S, then S lives on port p. Write it down (or refresh its age).
Forward by the destination. If the destination MAC is in the table, send the frame out of that one port. If it isn't, or it's a broadcast or multicast, flood it: send a copy out of every port except the one it came in on.
That's it. The switch never sends a "who's there?" message. It just listens. Flooding an unknown destination is safe because the real destination will get a copy, and when it replies, its source address teaches the switch where it is.
A worked example
Let's watch a fresh switch power up. It has six ports. Four devices are plugged in; ports 5 and 6 are empty:
| Port | Device | MAC |
|---|---|---|
| 1 | Laptop | 02:00:00:aa:bb:01 |
| 2 | Printer | 02:00:00:aa:bb:03 |
| 3 | NAS | 02:00:00:aa:bb:04 |
| 4 | Router | 02:00:00:cc:dd:02 |
Now some traffic happens. Watch the table:
-
Laptop → Router (port 1, dst
…cc:dd:02)This is our familiar 95-byte frame. Learn: source
…aa:bb:01is on port 1. Forward: the router's address isn't in the table yet, so flood out ports 2, 3, 4 (and the empty 5 and 6, which have no link, so nothing happens there). The printer and NAS receive it, see the destination isn't theirs, and discard it. The router accepts it.Table:
…aa:bb:01 → 1 -
Router → Laptop (port 4, dst
…aa:bb:01)Learn:
…cc:dd:02is on port 4. Forward:…aa:bb:01is known on port 1, so send it out port 1 only. The printer and NAS never see it.Table:
…aa:bb:01 → 1,…cc:dd:02 → 4 -
Laptop → Router again
Both addresses are known. The laptop's entry has its age reset to zero, and the frame goes out port 4 only. From now on these two can talk without bothering anyone.
-
Printer → broadcast (port 2, dst
ff:ff:ff:ff:ff:ff)Maybe the printer is asking "who has 192.168.1.10?" (that's ARP). Learn:
…aa:bb:03is on port 2. Forward: broadcasts are always flooded, so ports 1, 3, 4 get a copy. Note the switch learned the printer's location even though nobody had sent it anything.Table:
…aa:bb:01 → 1,…cc:dd:02 → 4,…aa:bb:03 → 2 -
NAS → Printer (port 3, dst
…aa:bb:03)Learn:
…aa:bb:04is on port 3. Forward: the printer is known on port 2, so it goes straight there. After five frames, the switch knows all four devices, and only the first and fourth were flooded.Table: all four entries, ports 1 to 4.
Forgetting: aging and moves
A table that only ever grows would eventually be wrong. Devices get unplugged, laptops move between desks, virtual machines migrate between hosts. So every entry has an age, reset whenever the switch sees a frame from that address. An entry that hasn't been refreshed for the aging time is deleted. The IEEE 802.1D default, which most switches and the Linux bridge also use, is 300 seconds (five minutes).
Forgetting is cheap: if the switch deletes an entry for a device that's still there, the next frame to it just gets flooded once, the device replies, and the entry is back.
Moves are handled by the same "learn from the source" rule. Suppose you unplug the laptop from port 1 and plug it into port 5:
-
Before the laptop speaks
The table still says
…aa:bb:01 → 1. A frame from the router to the laptop goes out port 1, where nobody is listening, and is lost. (TCP will retransmit.) -
The laptop sends anything
A frame arrives on port 5 with source
…aa:bb:01. The switch overwrites the entry:…aa:bb:01 → 5. Traffic follows immediately.
In practice the gap is tiny, because operating systems usually announce themselves as soon as a link comes up (a "gratuitous ARP", which the ARP article covers), and the switch also flushes entries for a port whose link goes down.
Filtering
One more case: what if the destination is known, and it's on the same port the frame came in on? That can happen if port 1 leads to a hub or another switch with several devices behind it, and two of them are talking to each other. The frame has already reached its destination on that segment, so the switch simply drops it. Bridges (the switch's two-port ancestor) were invented for exactly this: filtering local traffic so it doesn't cross to the other side.
Pseudocode
table = {} # mac -> (port, last_seen)
function on_frame(frame, in_port, now):
# 1. Learn from the source (unless it's a group address, which can't be a sender)
if not is_group(frame.src):
table[frame.src] = (in_port, now) # insert, refresh, or move
# 2. Forward by the destination
if is_group(frame.dst): # broadcast or multicast (I/G bit = 1)
flood(frame, except = in_port)
else if frame.dst in table:
out_port = table[frame.dst].port
if out_port != in_port:
send(frame, out_port)
# else: filter (destination is on the segment it came from)
else:
flood(frame, except = in_port) # unknown unicast
function age_out(now, aging_time = 300 s):
for mac, (port, last_seen) in table:
if now - last_seen >= aging_time:
delete table[mac]
function is_group(mac):
return (mac[0] & 0x01) == 1 # the I/G bit
Real switches add a lot on top (VLANs, multicast snooping that floods multicast only to interested ports, table size limits), but this is the core of every Ethernet switch.
When the table is full
A switch's CAM table has a fixed size, from a few thousand entries on a cheap switch to hundreds of thousands in a data centre. If an attacker sends frames from millions of fake source addresses, real entries get pushed out, and traffic to those hosts is flooded to every port, including the attacker's. This MAC flooding attack turns a switch back into a hub. Managed switches defend against it with "port security" limits on how many addresses each port may learn.
Send a frame
MAC address table
| MAC address | Port | Age |
|---|
Clock and aging
Move a host
Frame log
Store-and-Forward vs. Cut-Through
There's one more design choice inside a switch: when does it start sending a frame out of the output port?
A store-and-forward switch receives the whole frame into memory, checks the FCS, and only then forwards it. Corrupt frames die at the first switch instead of wasting bandwidth across the network. The cost is latency: the switch can't start sending until the last bit has arrived, so every hop adds one full frame's transmission time.
A cut-through switch starts forwarding as soon as it has read the destination MAC, just 6 bytes after the SFD, so its latency barely depends on frame size. The catch is that by the time the FCS arrives and turns out to be wrong, most of the frame has already gone out the other side. The switch can't recall it; the best it can do is cut the transmission short or mark it bad, and the next switch or the destination host discards it.
| Store-and-forward | Cut-through | |
|---|---|---|
| Starts sending after | Whole frame received | Destination MAC read |
| Latency per hop | One frame time (12.1 µs for 1518 B at 1 Gb/s) | Roughly constant, a few hundred ns or less in fast hardware |
| Corrupt frames | Dropped at this switch | Passed on, dropped downstream |
| Different port speeds | Easy (frame is buffered anyway) | Must fall back to buffering if output is faster or busy |
| Typical use | Almost all office and home switches | Low-latency data centre and trading networks |
There's also a historical middle ground, fragment-free, which waits for the first 64 bytes before forwarding. Remember the slot time? Any collision would have shown up in the first 64 bytes, so this filtered collision fragments on half-duplex networks without buffering whole frames.
Loops: The Switch's One Big Weakness
Flooding is what makes a switch work with zero configuration, but it has a dark side. Suppose you connect two switches with two cables, for redundancy. Now a single broadcast frame enters switch 1, gets flooded out both cables to switch 2, which floods each copy back over the other cable to switch 1, which floods them again...
Ethernet frames have no hop count, unlike IP's TTL. Nothing ever expires them. Within milliseconds the links are saturated by copies of the same broadcast, the MAC tables thrash as the same source address appears on different ports, and the network stops working. This is a broadcast storm, and the fix is a protocol that finds loops and blocks redundant links: Spanning Tree.
Where to Go Next
- ARP: our laptop sent a frame to
02:00:00:cc:dd:02, but it only knew the router's IP address. ARP is the broadcast-and-reply dance that bridges the two. - VLANs: the 4-byte 802.1Q tag that turns one switch into many separate broadcast domains.
- Spanning Tree: how switches agree on a loop-free set of links without anybody configuring them.
- Checksums & CRC (Error Correction): the polynomial maths behind the FCS.
Key Takeaways
- An Ethernet frame is 14 bytes of header (destination MAC, source MAC, EtherType), a 46–1500 byte payload, and a 4-byte CRC-32 FCS: 64 to 1518 bytes, or 1522 with a VLAN tag. On the wire it also has an 8-byte preamble/SFD and a 12-byte gap.
- The two bytes after the source MAC are a type if ≥ 0x0600 and a length if ≤ 1500.
- A MAC address is a 24-bit OUI plus 24 vendor-chosen bits. Bit 0 of the first byte is I/G (unicast vs. multicast), bit 1 is U/L (universal vs. locally administered);
ff:ff:ff:ff:ff:ffis broadcast. - The 64-byte minimum exists so a sender on shared media is still transmitting when news of a collision arrives (one 512-bit slot time).
- A switch gives each port its own collision domain and runs full duplex, but the whole switched LAN is still one broadcast domain.
- Switches learn from source addresses, forward on known destinations, flood unknown and broadcast frames, and forget entries after an aging time (300 s by default).
- Store-and-forward checks the FCS at every hop; cut-through trades that check for lower latency.
The switch learned where the router is, but our laptop had to put the router's MAC in the frame before any of this could happen. Next up: ARP, the protocol that answers "who has 192.168.1.1?"