Networking
Layers of Abstraction
The OSI model is a stack of abstractions. At the bottom, everything is voltage changes on a wire—bits. Each layer above solves a different problem without worrying about the layers below.
Layer 1 (Physical) deals with raw bits—voltage levels, cable specs, timing. Layer 2 (Data Link) adds structure: how do we group bits into meaningful chunks? How do we address devices on a local network? How do we detect transmission errors?
The answer is frames.
Ethernet Frame
A frame is the data link layer's unit of transmission. It wraps raw data with addressing, type information, and error checking. The bits still travel as voltage on the wire—but now they have structure.
Think of it like an envelope. The payload is your letter. The MAC addresses are the "to" and "from" fields. The FCS is a seal that proves nothing was tampered with in transit.
Ethernet Frame Structure
Click on a segment to learn more
Breaking it down
A repeating pattern of 10101010. The receiver's NIC uses this to synchronize its clock with the incoming signal. Without it, the receiver wouldn't know where one bit ends and the next begins.
Start Frame Delimiter. The pattern 10101011. That final 11 breaks the pattern and signals: "the real frame starts now."
Where this frame is going. Switches read this to decide which port to forward to. FF:FF:FF:FF:FF:FF means broadcast—send to everyone.
Where this frame came from. Switches also use this to build their MAC address tables.
What's inside the payload? Without this field, the receiver wouldn't know how to interpret the data.
The actual data—usually an IP packet. Minimum 46 bytes (padded with zeros if smaller). Maximum 1500 bytes (MTU). Larger data must be fragmented at a higher layer.
Frame Check Sequence. A CRC-32 checksum over the entire frame. The receiver recalculates it—if it doesn't match, the frame is silently dropped. No retransmission at this layer; that's TCP's job.
Ethernet is best-effort. Frames can be dropped, arrive out of order, or get corrupted. The data link layer doesn't care—it just moves frames between directly connected devices. Reliability comes from higher layers.
Unicast, Broadcast, Multicast
Not all frames are addressed the same way. The destination MAC determines who should process the frame.
One-to-one. Frame addressed to a specific device's MAC address. Only that device processes it; others ignore it.
e.g., 00:1A:2B:3C:4D:5EOne-to-all. Frame sent to every device on the local network. Used when you don't know the destination MAC (like ARP requests).
FF:FF:FF:FF:FF:FFOne-to-many. Frame sent to a group of devices that have subscribed to a multicast address. Used for streaming, routing protocols.
01:00:5E:xx:xx:xx (IPv4 multicast range)How do NICs know whether to process a frame? They check the destination MAC. If it matches their own address, is broadcast, or matches a multicast group they've joined—they process it. Otherwise, they drop it silently.
Collision Domains
Early Ethernet used a shared medium—one wire, many devices. If two devices transmitted simultaneously, signals collided and corrupted each other. The set of devices that can collide is called a collision domain.
CSMA/CD
How did devices handle collisions? Carrier Sense Multiple Access with Collision Detection:
This is essentially a state machine. Each device transitions between states based on what it observes on the wire.
Here's what happens when multiple devices share a hub—each trying to greet everyone else:
8 Devices on a Hub
Each device sends "Hello" to all others (56 messages)
All 8 devices start simultaneously, each trying to greet every other device. Watch how collisions force random backoffs, eventually letting everyone speak.
Modern networks: Full-duplex switched Ethernet has eliminated collisions. Each device has a dedicated path to the switch. CSMA/CD is largely historical—but understanding it explains why Ethernet frames have minimum sizes and why the preamble exists.
Why 64 bytes minimum?
For collision detection to work, the sender must still be transmitting when the collision signal returns. If the frame is too short, the sender finishes before hearing the collision—and thinks it succeeded.
512 bits = 64 bytes. Any frame shorter than 64 bytes gets padded.Why does the preamble exist?
Ethernet is asynchronous—the receiver's clock isn't synced with the sender's. The preamble gives the receiver time to lock onto the signal before real data arrives.
10101010 pattern to lock onto the signal frequency. By the time real data arrives, the clock is synced.Error Detection with CRC
Remember the FCS field in the Ethernet frame? It contains a CRC-32 checksum. But why CRC instead of a simple sum of bytes?
The Problem with Simple Checksums
A simple checksum just adds up all the bytes. If the sum matches, the data is probably intact. But there's a fatal flaw: errors can cancel out.
How CRC Works
CRC treats the entire frame as a giant binary number and divides it by a special polynomial using XOR operations. The remainder becomes the checksum.
Why Polynomial Division?
The mathematical properties of polynomial division guarantee detection of:
Ethernet's CRC-32
Ethernet uses the polynomial 0x04C11DB7, producing a 32-bit checksum. This detects any burst error up to 32 consecutive bits—more than enough for typical electrical noise on a cable.
Despite the math looking expensive, CRC is blazingly fast:
The XOR operations parallelize perfectly in hardware. A 1500-byte frame's CRC takes nanoseconds—the math never becomes the bottleneck.
MAC Addresses
Every network interface has a MAC address—a 48-bit (6 octet) identifier that's supposed to be globally unique. This is what goes in the Source and Destination fields of every Ethernet frame.
Structure
A MAC address is split into two halves:
MAC Address Structure
Special Bits
The first octet contains two special bits that change how the address behaves:
1 = Multicast (group of devices)
1 = Set by software (VM, container)
Special Addresses
FF:FF:FF:FF:FF:FFBroadcast — all devices must process01:00:5E:xx:xx:xxIPv4 multicast range33:33:xx:xx:xx:xxIPv6 multicast rangeBridging to Layer 3: ARP
MAC addresses work at Layer 2, but applications use IP addresses (Layer 3). ARP (Address Resolution Protocol) bridges this gap:
192.168.1.50 but doesn't know its MAC address.FF:FF:FF:FF:FF:FF)Security note: ARP has no authentication. Anyone can claim to own any IP address, enabling ARP spoofing attacks. This is why public Wi-Fi is risky without VPN/HTTPS.