Link layer services and error detection
The link layer moves a datagram across one link: from a host to a switch, between two routers, or from a laptop to an access point. Everything above it thinks about end-to-end paths. This layer only cares about the next neighbor, and it fails in its own ways: bad cables, mismatched settings, noisy radio, overflowing queues.
This page covers the services every link-layer protocol offers and how corrupted frames are detected. Multiple access protocols covers how nodes share a medium. ARP and switching covers addressing and forwarding inside a LAN.
Services
Section titled “Services”| Service | What it does | Where you see it |
|---|---|---|
| Framing | Wraps the network-layer datagram in a frame with a header (addresses, type) and usually a trailer (error check) | Ethernet frame, Wi-Fi frame |
| Link access | Rules for when a node may transmit. Trivial on a point-to-point link, a real protocol on a shared one | Ethernet switch port vs Wi-Fi channel |
| Reliable delivery | Acknowledgments and retransmissions on the link itself | Wi-Fi and cellular. Not Ethernet |
| Error detection | Extra bits let the receiver notice flipped bits and drop the frame | The Ethernet FCS, the Wi-Fi FCS |
| Error correction | Enough redundancy to repair some errors without a resend | Radio and fiber links, storage media |
Reliable delivery at the link layer looks redundant, since TCP already retransmits. It pays off when the link itself is lossy. A Wi-Fi frame lost to interference is cheaper to resend over the one hop than to detect through a TCP timeout across the whole path. On Ethernet, bit errors are rare, so the extra machinery is skipped and a damaged frame is silently dropped.
The services vary by protocol. Ethernet is connectionless and unreliable. Wi-Fi acknowledges every unicast frame. Choose your expectations from the protocol, not from the layer.
What runs where
Section titled “What runs where”Most of the link layer runs in the network adapter (NIC), and the rest runs in the operating system’s driver.
| Done in NIC hardware | Done in the driver and kernel |
|---|---|
| Building the frame, adding preamble and trailer | Choosing the next hop and the destination MAC (see ARP) |
| Computing and checking the CRC | Configuring the adapter, bringing the link up |
| Dropping frames not addressed to this adapter | Handling interrupts when a frame arrives |
| Carrier sense, backoff, and acknowledgments, depending on the medium | Passing the extracted datagram up to the IP layer |
Hardware address filtering has a practical effect. A NIC discards frames for other stations before they reach the CPU, which is why a busy shared segment does not slow every host. Putting an interface in promiscuous mode turns the filter off, which is what tcpdump does.
Modern NICs also take over more of the work. These are offloads:
# Which offloads are active on this interfaceethtool -k eth0 | grep -E 'checksum|segmentation|receive-offload'# rx-checksumming: on# tx-checksumming: on# tcp-segmentation-offload: on# generic-receive-offload: onOffloads matter when you read captures. A capture taken on the sending host can show a TCP checksum as bad or incorrect on outgoing packets, because the NIC fills it in after the capture point. That is normal. A capture on the receiving side of the wire shows the real value.
Error detection
Section titled “Error detection”Electrical noise and signal loss can flip bits in transit. The sender adds redundant bits, and the receiver recomputes them. A mismatch means the frame is dropped. More redundancy buys better detection.
Parity
Section titled “Parity”Single-bit parity adds one bit so that the count of 1s is even (or odd). It detects any odd number of flipped bits and misses every even number. On real links errors arrive in bursts, so a single parity bit misses roughly half of them.
Two-dimensional parity arranges the bits in a grid and adds a parity bit for each row and column. One flipped bit shows up in exactly one row and one column, which locates it and lets the receiver correct it. Any two flipped bits are detected, though not corrected.
Correcting errors without a resend is forward error correction (FEC). It matters where a resend is expensive: real-time audio and video, and links with long propagation delay such as deep-space and satellite paths. Wireless standards and optical transceivers use much stronger codes than parity, but the idea is the same.
Internet checksum
Section titled “Internet checksum”The checksum used by IP, TCP, and UDP treats the data as 16-bit integers, adds them, and stores the one’s complement of the sum. The receiver adds everything including the checksum field and expects all 1 bits. It is cheap to compute in software and weak against some error patterns, which is acceptable because the link layer has already applied a stronger check below it.
Cyclic redundancy check
Section titled “Cyclic redundancy check”A CRC treats the frame as a long binary number and divides it by an agreed generator value, using arithmetic without carries (which makes the division an XOR operation). The remainder is appended as the check value. The receiver divides the whole frame and expects a remainder of zero.
Ethernet and Wi-Fi use a 32-bit CRC. Its guarantees are strong:
- Every burst of up to 32 bad bits in a row is detected.
- Every error of 1, 2, or 3 flipped bits is detected in frames of Ethernet size.
- Longer bursts are missed with a probability of about 1 in 4 billion.
The division is awkward in software and trivial in hardware, which is why the link layer does it in the NIC and the upper layers use the cheaper checksum. A step-by-step division with a small generator is in the CRC and multiple access math deep dive.
| Method | Overhead | Detects | Where used |
|---|---|---|---|
| Single parity | 1 bit | Odd numbers of errors | Serial links, memory |
| Two-dimensional parity | Row and column bits | Corrects 1 bit, detects 2 | Teaching, simple codes |
| Internet checksum | 16 bits | Most random errors | IP header, TCP, UDP |
| CRC-32 | 32 bits | All bursts up to 32 bits, all 1 to 3 bit errors | Ethernet, Wi-Fi |
The transport layer also has its own check (UDP header and checksum), so a corrupted payload can be caught at several levels. End-to-end checks remain necessary because a switch or router can corrupt a frame inside its own memory after the link-layer check has passed.
Reading the counters
Section titled “Reading the counters”A frame that fails the CRC is dropped without a message. The only trace is a counter.
# Per-interface totalsip -s link show eth0# RX: bytes packets errors dropped missed mcast# TX: bytes packets errors dropped carrier collsns
# Detail breakdown (names vary by driver)ethtool -S eth0 | grep -iE 'crc|frame|align|len|drop|miss|collision'# rx_crc_errors: 0# rx_length_errors: 0| Counter that rises | Usual meaning |
|---|---|
| CRC or FCS errors | Corrupted bits on the wire. Bad cable, dirty or failing optic, an unsupported cable length, electrical interference, or a duplex mismatch |
| Frame or alignment errors | Often a duplex mismatch or a faulty NIC |
| Length errors or giant frames | A neighbor sending frames larger than the receiver’s MTU |
| Missed or dropped (not errors) | The NIC or the kernel ran out of buffer, which is a capacity problem rather than a cable problem |
| Collisions, late collisions | Half-duplex operation, or a duplex mismatch. Should be zero on switched full-duplex links |
Corruption on a healthy wire is rare, so any steady count of CRC errors is worth chasing. Wireless links are the opposite. Loss is routine there, and the link layer hides it with acknowledgments, retransmissions, and lower data rates.