Data link layer: error detection, medium access control and Ethernet
Framing and bit stuffing, error detection with parity, checksums, Hamming distance and CRC, random access (ALOHA, CSMA/CD) and its formulas, and the Ethernet frame, minimum frame size and learning switches.
The data link layer cuts the bit stream into frames and must mark where each frame starts and ends.
Byte count: a header field gives the frame length. One corrupted count loses synchronisation, so it is rarely used alone.
Byte (character) stuffing: frames start and end with a special FLAG byte. If FLAG or the escape byte ESC appears in the data, the sender inserts an ESC before it; the receiver removes it.
Bit stuffing (HDLC, PPP style): the flag is the bit pattern . Whenever the sender sees five consecutive 1s in the data, it inserts a 0 after them, whether or not the next bit is a 1. The receiver deletes any 0 that follows five 1s. So six 1s in a row can only be a flag.
Example: data (a 0, eleven 1s, a 0) becomes . Counting rule: a run of ones gets stuffed zeros.
Ethernet does not use flags; it uses a preamble of alternating bits for clock synchronisation and a start frame delimiter (SFD), and frames are separated by idle gaps.
Single parity bit: makes the number of 1s even (or odd). It detects any odd number of bit errors and misses every even number.
Two-dimensional parity: a parity bit per row and per column. It can detect and correct any single-bit error (the bad row and column cross at it) and detects all 2- and 3-bit errors, but some 4-bit errors in a rectangle go unseen.
Internet checksum (IP, TCP, UDP): add the data as 16-bit words in one's complement (wrap any carry back into the lowest bit), then complement the sum. The receiver adds everything including the checksum; the result must be all 1s. It is cheap but weaker than CRC.
Hamming distance between two codewords is the number of bit positions in which they differ. For a code with minimum distance :
Goal
Condition
Detect up to errors
Correct up to errors
So detects 4 or corrects 2.
Hamming code (single-error correction): for data bits you need the smallest check bits with . Check bits sit at positions . For , (since while ).
3. Cyclic redundancy check (CRC)
A CRC treats bit strings as polynomials with coefficients mod 2. Sender and receiver agree on a generator of degree (so bits).
Sender: append zeros to the data ; divide by using modulo-2 (XOR) division; the -bit remainder is the CRC. Send data followed by the remainder. The frame is now exactly divisible by .
Receiver: divide the whole received frame by . A remainder of 0 means no error is detected.
In XOR division, at each step look at the leading bit: if it is 1, XOR the generator under it; if 0, just move on. There are no borrows.
What a CRC with generator of degree detects:
all single-bit errors, if has at least two terms;
all odd numbers of errors, if is a factor of ;
all burst errors of length .
An error pattern goes undetected exactly when divides .
Ethernet uses CRC-32 (degree 32), so its CRC field is 4 bytes.
4. Medium access: ALOHA, CSMA and CSMA/CD
When stations share one channel, a MAC protocol decides who sends. Random access protocols let anyone send and handle collisions.
Pure ALOHA: send whenever ready. A frame collides with any frame started up to one frame time before or after it, so the vulnerable time is . With = average frames attempted per frame time, throughput , maximum at .
Slotted ALOHA: send only at slot starts; vulnerable time . , maximum at . With stations each sending in a slot with probability : .
CSMA: listen first; send only if the channel is idle. 1-persistent sends as soon as idle; non-persistent waits a random time if busy; p-persistent (slotted) sends with probability when idle. Collisions still happen because of propagation delay.
CSMA/CD (classic Ethernet): keep listening while sending and stop on a collision. To be sure of seeing a collision before finishing, a frame must last at least one round trip:
After the -th collision a station picks uniformly from with and waits slot times (binary exponential backoff); it gives up after 16 attempts.
Controlled access avoids collisions instead: polling (a master asks each station in turn) and token passing (only the holder of the token may send).
5. Ethernet, MAC addresses and learning switches
Frame format (IEEE 802.3 / Ethernet II), in bytes: preamble 7, SFD 1, destination 6, source 6, type or length 2, data 46 to 1500, CRC 4. The frame size counts destination through CRC: 64 to 1518 bytes. Data shorter than 46 bytes is padded. The largest payload, 1500 bytes, is Ethernet's MTU.
The 64-byte minimum is the CSMA/CD rule: at 10 Mbps, 512 bits take , the slot time that bounds the round trip on a maximum-size network.
MAC addresses are 48 bits, written as six hex bytes. The first 3 bytes identify the maker (OUI). The broadcast address is FF:FF:FF:FF:FF:FF. If the least significant bit of the first byte is 1 the address is multicast.
Classic 10 Mbps Ethernet uses Manchester encoding: every bit has a transition in the middle, so the signal rate is twice the bit rate.
Learning switch (bridge). For each incoming frame it:
learns: records (source MAC → incoming port);
filters: drops the frame if the destination is on the same port it came from;
forwards it on the one known port, or floods it on all other ports if the destination is unknown or broadcast.
Table entries age out. With loops between switches, flooding would circle forever, so switches run the spanning tree protocol, which disables links until the active topology is a tree. Full-duplex switched Ethernet has no collisions, so CSMA/CD is not used there.
Ethernet frame. Preamble and SFD are not counted in the 64 to 1518 byte frame size; the CRC covers destination through data.
Formulas to remember
Error detection by distanceDetects up to errors
Error correction by distanceCorrects up to errors
Hamming check bits data bits, smallest such
Pure ALOHA throughput
Slotted ALOHA throughput
Slotted ALOHA, N stationsMaximised at
CSMA/CD minimum frameEquivalently, maximum cable length
Binary exponential backoffAfter the -th collision; wait slot times
Common mistakes
Forgetting to append zeros before CRC division, or appending zeros for an -bit generator.
Stuffing a 0 only when a sixth 1 follows; the 0 goes in after every five consecutive 1s regardless of the next bit.
Using for pure ALOHA; pure ALOHA has vulnerable time and .
Using for CSMA/CD; the frame must outlast the round trip, .
Counting the preamble in the 64-byte minimum or 1518-byte maximum Ethernet frame size.
Mixing detection and correction: detects 3 errors but corrects only 1.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Computing a CRC
numerical
The data is 101110 and the generator is 1001 (). Find the CRC and the transmitted frame, and check it at the receiver.
Step 1: How many zeros do you append?
Try it on paper first.
Example 2: Minimum frame size for CSMA/CD
numerical
A 10 Mbps CSMA/CD network has a maximum cable length of 2 km and signal speed m/s. Find the minimum frame size.
Step 1: Find the one-way propagation delay.
Try it on paper first.
Example 3: Slotted ALOHA with a few stations
numerical
Four stations share a slotted ALOHA channel. In every slot each station transmits with probability 0.25, independently. Find the fraction of slots that carry a successful frame.
Step 1: When is a slot successful?
Try it on paper first.
Example 4: Bit stuffing
numerical
With flag 01111110, what does the sender transmit for the data 0111111111110, and how many bits are stuffed?
Step 1: Find runs of five 1s.
Try it on paper first.
Previous year questions
19 official GATE CSE questions on this topic, newest first.
10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.