Computer Network 📂 Data Link Layer · 1 of 2 63 min read

Data Link Layer — Framing, Error Control & Flow Control Explained with Real Cases

A hands-on tutorial on the Data Link Layer covering framing (byte & bit stuffing), error detection and correction (parity, CRC, Hamming code), and flow control (Stop-and-Wait, Go-Back-N, Selective Repeat). Includes animated SVG diagrams that work in both light and dark themes, worked examples, an Ethernet frame anatomy, and three real newspaper-style cases: Voyager 1 (CNN 2024), the 1986 internet collapse, and CRC errors in modern data centres.

Section 01

The Story That Explains the Data Link Layer

The Postal Sorting Office Between Two Neighbours
Imagine two friends, Alice and Bob, live on the same street. Alice writes a long letter and hands it to the local post office. Bob receives it — but the postie has done a lot of work in between: cut the letter into envelopes of a manageable size, sealed each envelope so nothing spills out, stuck a tamper-proof sticker on the back so Bob knows if it was opened, and refused to hand Bob envelope #7 until he confirmed envelope #6 was safely in his hands.

That single street with those two neighbours is exactly what the Data Link Layer does between two directly-connected machines: it takes a raw stream of bits, packages them into frames, protects them with error-checking codes, and paces the delivery so nobody gets overwhelmed.

The layer above (Network Layer, IP) worries about the whole city. The Data Link Layer worries only about this one street.

In the OSI model, the Data Link Layer (Layer 2) sits directly above the raw Physical Layer. It transforms the unreliable, noisy stream of bits offered by the wire, fibre or radio wave into an orderly, error-checked, flow-controlled channel that upper layers can trust.

🌐
The Core Insight

Physical wires drop bits, flip bits, and send bits faster than the receiver can accept them. The Data Link Layer's job is to hide all of that from the layers above — so IP can pretend it's talking on a clean, reliable link between two neighbours.


Section 02

The Three Jobs of the Data Link Layer

📦
Framing
Where does a frame start & end?
Break the raw bit stream into discrete frames with clear boundaries so the receiver knows exactly where one message ends and the next begins.
🛡️
Error Control
Detect & correct bit flips
Add redundancy (parity, CRC, Hamming code) so the receiver can spot corrupted frames — and in some cases fix them without needing a resend.
🚦
Flow Control
Don't drown the receiver
Pace the sender so a fast transmitter doesn't overwhelm a slow receiver. Protocols like Stop-and-Wait and Sliding Window handle this.

Section 03

Framing — Turning Bits into Frames

The physical layer just sees 1s and 0s. If a NIC receives 0110100101100101 where does the frame boundary lie? Framing gives us the answer.

📌 Four Framing Techniques
1
Character Count — first byte says "this frame is N bytes long". Fragile: if the count byte flips, the entire stream falls out of sync.
2
Byte Stuffing — special FLAG bytes mark start/end. If FLAG appears in the payload, an ESC byte is inserted. Used by PPP.
3
Bit Stuffing — flag bit pattern 01111110 marks the frame. Whenever five 1s appear in the payload, a stuffed 0 is inserted. Used by HDLC.
4
Physical Layer Coding Violation — reserved illegal signal patterns (used in Manchester encoding) mark the frame boundaries.

🎬 Animated Diagram — Bit Stuffing in Action

Watch the transmitter scan for five consecutive 1s and stuff a 0:

SENDER INPUT (raw bits) STUFFED OUTPUT (on the wire) 0 1 1 1 1 1 1 0 5 consecutive 1s detected! insert 0 0 1 1 1 1 1 0 1 0 stuffed bit RULE: After every 5 consecutive 1s in the payload, insert a 0. RESULT: The flag 01111110 can never appear inside a frame body. Receiver removes stuffed 0s.
💡
Why HDLC Won

Bit stuffing is encoding-agnostic — it works whether the payload is text, video, or encrypted data. Byte stuffing (PPP) is simpler but wastes bandwidth when the escape byte is common. HDLC-style bit stuffing remains the standard for synchronous links (SONET, Frame Relay, ISDN).


Section 04

The Ethernet Frame — A Real-World Example

Every packet on your home Wi-Fi or office LAN is wrapped in an Ethernet frame. Here is its anatomy:

Field Size Purpose
Preamble7 bytesAlternating 10101010 — lets the receiver clock synchronise.
SFD (Start Frame Delimiter)1 byte10101011 — the last bit flips to signal "frame starts now".
Destination MAC6 bytesPhysical address of the receiver's NIC.
Source MAC6 bytesPhysical address of the sender's NIC.
Type / Length2 bytes0x0800 = IPv4, 0x86DD = IPv6, 0x0806 = ARP.
Payload46 – 1500 bytesThe actual IP packet.
FCS (CRC-32)4 bytesThe error-detection field — a 32-bit CRC over the whole frame.
🔍
Where the CRC Lives

The last 4 bytes of every Ethernet frame — the Frame Check Sequence (FCS) — is a 32-bit CRC. If the CRC on arrival doesn't match, the NIC silently drops the frame. This happens billions of times a second across the internet, invisibly.


Section 05

Error Detection & Correction — The Landscape

Wires drop bits, cosmic rays flip bits, electromagnetic interference scrambles bits. The Data Link Layer adds redundancy so the receiver can either detect or correct the damage.

🛡️ Error Detection
Parity Bit
Checksum
CRC (Cyclic Redundancy Check)
Retransmission needed on failure
🧰 Error Correction
Hamming Code
Reed-Solomon
Turbo & LDPC codes
Fixes the error in place — no resend

Section 06

Parity Check — The Simplest Idea

Append one extra bit to every data word so that the total number of 1s is even (even parity) or odd (odd parity). If a single bit flips in flight, the parity is wrong and the receiver knows something is broken.

🎬 Animated Diagram — Even Parity Detects a Bit Flip

SENDER Data: 1011010 (four 1s = even) Parity bit added: 0 Transmitted: 10110100 1 0 1 1 0 1 0 0 parity Noisy Channel ~ bit flip ~ RECEIVER Received: 10010100 Count of 1s: 3 (ODD!) Expected: EVEN → ERROR! 1 0 0 1 0 1 0 0 flipped! DIAGNOSIS → The receiver counts 3 ones. Even parity expected an EVEN count. ACTION → Discard the frame. Request retransmission via NACK or timeout. Limitation: If TWO bits flip, parity still looks correct. Parity only catches odd numbers of errors.
⚠️
The Fatal Flaw of Single-Bit Parity

Parity only detects an odd number of bit errors. If two bits flip in the same word, the parity looks correct and the error slips through undetected. On modern noisy links you need something stronger — enter CRC.

Two-Dimensional Parity — A Small Upgrade

Arrange the bits in a rectangle, compute parity per row and per column. A single bit-flip changes exactly one row-parity and one column-parity — pinpointing the corrupt bit at their intersection. This detects many more errors and can even correct single-bit flips.


Section 07

CRC — Cyclic Redundancy Check

CRC is the workhorse of modern networking. Every Ethernet frame, every Wi-Fi frame, every hard-disk sector, every ZIP file, every QR code — all protected by a CRC. The idea sounds mathematical but the intuition is simple.

The Magic Divisor
Treat your message as a giant binary number. Pick a special agreed-upon divisor polynomial (both sender and receiver know it). Divide the message by the divisor and append the remainder to the message. Now the transmitted number is perfectly divisible by the divisor.

The receiver divides again. Remainder = 0 → frame is intact. Any non-zero remainder → corruption detected. Even one flipped bit will almost certainly leave a non-zero remainder, so the error is caught.

Worked Example — CRC with Generator Polynomial 1101

🔢 Step-by-Step CRC Calculation
Step 1
Data to send: 101100. Generator polynomial: 1101 (degree 3).
Step 2
Append 3 zeros (degree of divisor) to the data → 101100 000.
Step 3
Perform binary division (XOR at each step) of 101100000 ÷ 1101.
Step 4
The remainder is the CRC. Suppose it comes out to 001.
Step 5
Transmitted frame = data + CRC = 101100 001.
Step 6
Receiver divides 101100001 ÷ 1101. Remainder = 0 → frame OK. Otherwise → discard.

🎬 Animated Diagram — CRC Journey

SENDER Data: 101100 Divide by 1101 CRC = 001 101100 | 001 data | crc travelling over the wire RECEIVER Received: 101100001 Divide by 1101 Remainder = 0 ✓ Frame Accepted If remainder was non-zero, frame would be silently dropped
🏆
Why CRC Dominates

CRC-32 (used in Ethernet) detects all single-bit errors, all double-bit errors within 2^31 bits, all odd-numbered errors, and all burst errors up to 32 bits. False-positive rate: less than 1 in 4 billion frames. And it can be computed in hardware at line rate (100 Gbps and beyond).


Section 08

Hamming Code — Error Correction Without Retransmission

CRC tells you a frame is broken but not where. If the round-trip is short (Ethernet), you just resend. But if you're a NASA probe 24 billion kilometres away, a resend takes 40+ hours. You need to correct the error on the spot. Enter Hamming code — invented by Richard Hamming in 1950 while working at Bell Labs.

The Idea in One Line

Sprinkle parity bits at power-of-2 positions (1, 2, 4, 8, …) so that each data bit is covered by a unique combination of parity checks. When a bit flips, the failing parity checks form a binary address that points directly at the guilty bit.

🔫 Hamming(7,4) — Encoding 4 Data Bits into 7 Transmitted Bits
Layout
Positions 1, 2, 4 → parity bits (p1, p2, p4). Positions 3, 5, 6, 7 → data bits (d1, d2, d3, d4).
p1
Covers positions with bit 0 set in the position index: 1, 3, 5, 7 → p1 = d1 ⊕ d2 ⊕ d4
p2
Covers positions with bit 1 set: 2, 3, 6, 7 → p2 = d1 ⊕ d3 ⊕ d4
p4
Covers positions with bit 2 set: 4, 5, 6, 7 → p4 = d2 ⊕ d3 ⊕ d4
Fix
If p1, p2, p4 checks fail → binary 111 = position 7. Flip bit 7 back. Done.

🎬 Animated Diagram — Hamming Code Locating & Fixing an Error

POS: 1 2 3 4 5 6 7 SENT: 0 1 1 0 0 1 1 p1 p2 d1 p4 d2 d3 d4 RCVD: 0 1 1 0 1 1 1 BIT FLIP! SYNDROME CHECK p1 check (pos 1,3,5,7) → FAIL p2 check (pos 2,3,6,7) → PASS p4 check (pos 4,5,6,7) → FAIL Syndrome = 1012 = 5 FIXED: 0 1 1 0 0 1 1 corrected in place! Zero retransmissions. Zero round-trip time. Message delivered intact.
🚀
Real-World Deep Space Application

NASA's Voyager and Mars missions rely on error-correcting codes (extended Golay code, then Reed-Solomon, and later concatenated / turbo codes) that are the intellectual descendants of Hamming's work. Voyager 1's 1989 pictures of Neptune's moon Triton, taken 5 billion km away, would have been unreadable noise without an elaborate error-correcting scheme built into its communication system.


Section 09

Flow Control — Pacing the Conversation

Suppose a 10 Gbps server is streaming data to a Raspberry Pi with only a small buffer. Without any pacing, the Pi's buffer overflows in milliseconds and every frame afterwards is lost. Flow control lets the receiver tell the sender: "slow down, I need a moment."

🔄
Flow Control vs Error Control vs Congestion Control

Flow control = end-to-end: sender vs receiver capacity.
Error control = detecting and repairing damage per frame.
Congestion control = network-wide: too much traffic in the pipes.
The Data Link Layer handles the first two. Congestion control is the Transport Layer's job (TCP).


Section 10

Stop-and-Wait — The Simplest Protocol

Send one frame. Wait for its acknowledgement (ACK). Only then send the next frame. If the ACK doesn't arrive within a timeout, resend. This is Stop-and-Wait: correct, dead simple, and painfully slow.

🎬 Animated Diagram — Stop-and-Wait Timeline

SENDER RECEIVER Frame 0 ACK 0 Frame 1 WAITING THROUGHPUT PROBLEM → If frame transmission takes 1 ms and round-trip is 100 ms, the link is IDLE 99% of the time. On a satellite link (RTT ~500 ms) Stop-and-Wait wastes almost the entire pipe.
🕔
The Bandwidth-Delay Product Trap

Efficiency of Stop-and-Wait = 1 / (1 + 2a) where a = propagation delay / transmission time. On a 100 Mbps link with 20 ms one-way delay, a is huge — efficiency drops below 1%. You need to keep multiple frames in flight at once. That's the sliding window.


Section 11

Sliding Window — Multiple Frames in Flight

Give the sender a "window" of, say, N frame numbers it may send without waiting for ACK. Each ACK slides the window forward, freeing a new slot. If the window is well-tuned to the bandwidth-delay product, the pipe stays completely full.

01
Window of Size N
Sender may transmit frames 0, 1, 2, …, N-1 back-to-back without stopping. The window represents "frames in flight, awaiting ACK".
02
Cumulative or Selective ACKs
Receiver acknowledges frames as they arrive. Two flavours: cumulative ACK n means "everything up to n-1 is safely received", or selective ACK for individual frames.
03
Window Slides on ACK
Every ACK frees a slot on the left edge and adds a new sendable slot on the right edge. As long as ACKs arrive, the sender never blocks.

🎬 Animated Diagram — Sliding Windows in Action (Sender & Receiver View)

This is the classic side-by-side timeline. Watch the sender's window on the left and the receiver's window on the right. Time flows downward. The S pointer marks the next frame the sender will transmit. Each ACK slides both windows forward — and when Frame 2 goes missing, only Frame 2 is resent while Frame 3 stays safely buffered at the receiver.

Sender Receiver 012 3012 S 012 3012 Frame 0 012 3012 S 012 3012 Frame 1 012 3012 S ACK 2 012 3012 S Frame 2 Lost 012 3012 S 012 3012 buffered Frame 3 NAK 2 012 3012 S 012 3012 both delivered Frame 2 Resent Time
💡
Reading the Windows

The 7-slot bar isn't 7 real frames — it's a modulo sequence-space. With sequence numbers 0,1,2,3,0,1,2… the sender and receiver only need to agree on which 2 (window size) are currently "in play". Slots outside the highlight aren't allowed to be sent or accepted. Once the window slides, the old slots become reusable — that's the sequence-number wrap-around that keeps the field small on the wire.


Section 12

Go-Back-N — Simple but Wasteful on Errors

On error, the sender rewinds to the lost frame and resends everything from that point onward, even frames the receiver has already accepted. The receiver discards any out-of-order frames — it only accepts frames strictly in sequence.

🎬 Animated Diagram — Go-Back-N Recovery

SENDER RECEIVER Frame 0 ✓ Frame 1 ✗ LOST Frame 2 (discarded — out of order) Frame 3 (discarded) TIMEOUT Frame 1 RESEND Frame 2 RESEND Frame 3 RESEND WASTE → Frames 2 and 3 already reached the receiver — but they were discarded and now retransmitted.
Why Go-Back-N Anyway?

Because the receiver is stateless — it doesn't need to buffer out-of-order frames. Cheap RAM, simple firmware. Good for low-error-rate wired links where the "waste" almost never happens. Poor for lossy wireless where retransmitting healthy frames is a huge cost.


Section 13

Selective Repeat — Smart but Complex

The receiver buffers out-of-order frames. On error, the sender resends only the lost frame. The receiver stitches everything back into order once the missing piece arrives. Higher throughput on lossy links, at the cost of memory and complexity on both sides.

🎬 Animated Diagram — Selective Repeat Recovery

SENDER RECEIVER Frame 0 ✓ (buffered slot 0) Frame 1 ✗ LOST Frame 2 ✓ (buffered slot 2) Frame 3 ✓ (buffered slot 3) NAK 1 (please resend just frame 1) Frame 1 RESEND (only this one!) ACK 3 (0,1,2,3 all delivered in order) EFFICIENCY → Only ONE retransmission — frames 2 and 3 never left the receiver's buffer. Wi-Fi, LTE, 5G and modern TCP all use selective-repeat ideas.

Section 14

Stop-and-Wait vs Go-Back-N vs Selective Repeat

Property Stop-and-Wait Go-Back-N Selective Repeat
Sender window 1 N N
Receiver window 1 1 N
Out-of-order frames Discarded Buffered
ACK style Per frame Cumulative Selective (NAK / SACK)
On error, resend 1 frame All in-flight Only the lost frame
Complexity Trivial Moderate High
Best used on Very short links, learning Clean wired links Wi-Fi, LTE, 5G, satellite

Section 15

Real-World Cases — When Data Link Layer Made the News

🛸
Voyager 1 — CNN, April 2024
In November 2023 Voyager 1's flight-data system started transmitting a repeating gibberish pattern from 24 billion km away. NASA JPL engineers traced the fault to a failing memory chip and, over five months, remotely rewrote the 46-year-old software around the bad chip. Reliable data returned on 20 April 2024 — proof that layered communication design with strong error-correcting codes keeps signals meaningful even at interstellar distances.
error correction, deep-space telemetry
🔌
The Great Internet Slowdown — October 1986
Lawrence Berkeley Lab and UC Berkeley are 400 yards apart. In October 1986 the link between them collapsed from 32 Kbps to 40 bps — a factor-of-1000 drop. Van Jacobson and Michael Karels traced it to naive retransmission behaviour flooding a congested link. Their fix — the sliding-window-based congestion control still used in TCP today — saved the young internet from collapse. A stark reminder: flow control isn't optional.
flow control, sliding window
🏗️
CRC Errors Bringing Down Data Centres
Cisco's Nexus documentation and independent blogs (ipSpace, FMADIO) document real data-centre outages caused by a single faulty SFP transceiver corrupting every Ethernet frame's FCS. Cut-through switches propagated the damage across the fabric with "stomped" CRCs. One bad cable, thousands of failed frames per second, cascading tenant impact — until the CRC counter on one port revealed the culprit.
CRC / FCS, framing, Ethernet
📚
Why These Stories Matter

Every one of these incidents is a Data Link Layer concept meeting the messy real world. Hamming/error-correcting codes save Voyager. Sliding-window flow control saves the internet. CRC catches quiet cable failures before they corrupt customer data. The theory in your textbook is not academic — it is on-call, 24/7, in every switch and radio.


Section 16

Golden Rules

🏆 Data Link Layer — Non-Negotiable Rules
1
Always frame explicitly. Never rely on timing gaps to signal frame boundaries. Bit-stuffing (HDLC) or byte-stuffing (PPP) or a physical-layer delimiter — pick one and be strict.
2
Never trust a wire. Every serious link protocol appends a CRC — Ethernet uses CRC-32, HDLC uses CRC-16, satellite links often use CRC-32C. Parity alone is not enough for anything but the tiniest word.
3
Match retransmission strategy to link quality. Clean fibre → Go-Back-N is fine. Wi-Fi in a crowded office, LTE cell edge, or LEO satellite → use Selective Repeat / block ACKs.
4
Correct when the round-trip is expensive. If a resend costs milliseconds you can afford ARQ. If a resend costs hours (deep space) or is impossible (broadcast video), pay the bandwidth for a forward-error-correction code like Hamming, Reed-Solomon, LDPC or turbo.
5
Size your window to the bandwidth-delay product. A 1 Gbps link with 20 ms one-way delay needs at least 1 Gbps × 40 ms = 5 MB of unacknowledged data in flight. Smaller windows leave the pipe half-empty.
6
Monitor CRC and framing counters in production. Rising FCS-error counts on a switch port almost always mean a physical-layer fault — bad SFP, damaged cable, duplex mismatch. Catch it before the users do.
7
Remember the layer boundary. The Data Link Layer only guarantees hop-to-hop delivery. End-to-end reliability across many hops is the Transport Layer's job (TCP). Don't ask the DLL to solve problems it wasn't built for.