Data link layer — framing, error detection (CRC computation), MAC
1. Framing
WHY: The receiver gets a continuous stream ...10110101.... Without markers it can't tell one frame from the next. We need delimiters — but delimiters can also accidentally appear inside the data, so we need an escaping trick.
Methods
(a) Byte/character count — first field says "next bytes are my payload."
- Problem: if the count field itself is corrupted, the receiver loses sync forever.
(b) Byte stuffing (flag bytes) — put a special FLAG byte at start & end (e.g. 0x7E). If FLAG or the escape byte ESC appears in data, prefix it with ESC.
(c) Bit stuffing — frame is delimited by the flag pattern 01111110. To avoid this pattern in data, the sender inserts a 0 after every 5 consecutive 1s in the data.
2. Error Detection — CRC
WHAT is GF(2) arithmetic? Coefficients are bits. Addition = subtraction = XOR (no carries!). . So polynomial long division uses XOR instead of subtraction.
Derivation from scratch — WHY the remainder makes it divisible
Let:
- = message polynomial, degree (message has bits).
- = generator, degree (so bits).
Step 1 — make room. Multiply message by , i.e. append zeros: Why? This shifts the message left, reserving low-order slots for the check bits.
Step 2 — divide. Over GF(2): is the CRC remainder ( bits, the FCS = Frame Check Sequence).
Step 3 — transmit. Send: Why is this divisible? Because over GF(2) addition = subtraction: since (XOR). So is an exact multiple of .
Worked example (full long division)
Message , generator (so ).
Why append 3 zeros? 3 check bits → dividend = 1101000.
1101000 ÷ 1011 (XOR division)
1101000
1011
----
0110000
1011
----
01110 0
1011
----
01010
1011
----
0001 → remainder R = 001
Step-by-step (Why each step?): we XOR whenever the leading bit is 1, shift, repeat until we run out of bits. Leading 0 ⇒ bring next bit down (XOR with 000).
Transmit .
Receiver check: divide 1101001 by 1011 → remainder 000 ⇒ accept. If any bit flips, remainder ≠ 0 (for errors can catch).

What errors does CRC catch? (WHY choose good )
An error pattern is ; received = . Error is undetected iff is divisible by . So we pick to make that rare:
- All single-bit errors (): caught if has terms.
- All odd numbers of bit errors: caught if has factor .
- All burst errors of length : caught (a burst is with ; and ).
3. MAC — Medium Access Control
Two flavours:
(a) CSMA/CD (wired Ethernet): Carrier Sense (listen before talking), Multiple Access, Collision Detection (keep listening while sending; if you hear garble ≠ your bits → collision). On collision: jam + binary exponential backoff (wait random time in slots after the -th collision).
(b) CSMA/CA (Wi-Fi): can't reliably detect collisions on radio, so avoid them — wait random backoff before sending, use ACKs, optional RTS/CTS.
Active Recall
Recall Why does appending the CRC remainder make the frame divisible by
? Because in GF(2), and are both XOR. ; since , we get , an exact multiple.
Recall In CSMA/CD why must
? The sender needs to still be transmitting when the worst-case collision signal (round trip ) returns, so it can detect it.
Recall Bit stuffing rule?
Insert a 0 after every five consecutive 1s in the data, so the flag 01111110 can't appear in payload.
Recall (Feynman, explain to a 12-year-old)
Imagine mailing a long sentence with no spaces. Framing = adding clear START/END marks so your friend knows where each word is. CRC = adding a little "magic number" at the end; your friend redoes the math — if it doesn't match, a letter got smudged in the mail. MAC = the rule "only one person talks at a time" so everyone in a noisy room can be understood.
What are the three jobs of the data link layer?
What is bit stuffing's rule?
In CRC, what is and how many zeros do you append to the message?
Why is the transmitted CRC frame divisible by ?
What arithmetic does CRC division use?
CRC error E(x) goes undetected when?
Which errors does a generator with factor catch?
Why does CSMA/CD need a minimum frame size?
What does CSMA/CD do after a collision?
Why CSMA/CA instead of CD in Wi-Fi?
How many bits is a MAC address and is it hierarchical?
Does CRC correct errors?
CRC: message 1101, G=1011, find FCS.
Connections
- Physical Layer — provides the raw bit pipe framing sits on.
- Polynomials over GF(2) — math foundation of CRC.
- Hamming Code — error correction vs CRC's detection.
- Ethernet — uses CSMA/CD, 64-byte min frame, MAC addresses.
- Network Layer (IP) — hierarchical addressing contrasted with flat MAC.
- Stop-and-Wait & Sliding Window — reliability built atop framing + error detection.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, data link layer ka kaam hai physical layer ki "dumb bit pipe" ko useful banana. Teen kaam: framing (bits ke stream mein frame kahan start/end hota hai mark karna), error detection (koi bit flip to nahi hua noise se), aur MAC (jab ek hi wire pe bahut saare nodes hain, to kaun bolega kab). Framing ke liye flags use karte hain, par flag pattern data ke andar bhi aa sakta hai — isliye bit stuffing karte hain: har paanch consecutive 1s ke baad ek 0 ghusa do, taaki real flag 01111110 kabhi payload mein na aaye.
CRC sabse important hai. Idea simple: message ko ek polynomial samjho (GF(2) mein, yaani addition/subtraction dono XOR). Ek fixed generator choose karo jiska degree hai. Message ke peeche zeros lagao (matlab se multiply), phir se XOR-division karo, jo remainder aaye usko zeros ki jagah laga do. Ab pura frame se exactly divisible ho jaata hai — kyunki GF(2) mein . Receiver bas divide karta hai: remainder 0 to OK, warna error pakka. Yaad rakho — CRC sirf detect karta hai, correct nahi.
MAC mein, wired Ethernet CSMA/CD use karta hai: pehle suno (carrier sense), phir bolo, aur bolte waqt bhi suno — agar collision sune to ruko aur random backoff. Yahin se minimum frame size ka concept aata hai: sender ko itni der transmit karna padega ki worst-case collision ki khabar round-trip mein wapas aa jaaye, isliye . Wi-Fi mein collision detect karna mushkil hai, isliye CSMA/CA — collision avoid karo with backoff aur ACKs. MAC address 48-bit hota hai, flat (IP jaisa hierarchical nahi), local delivery ke liye.