Skip to content
GATEiit

GATE CSE · Computer Networks

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.

Before you start

This topic comes before: IPv4: fragmentation, CIDR notation and network address translation (NAT), TCP: flow control and congestion control; socket API

Concept notes

1. Framing

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 01111110. 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 0111111111110 (a 0, eleven 1s, a 0) becomes 011111011111010. Counting rule: a run of n ones gets ⌊n/5⌋ 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.

2. Error detection: parity, checksum, Hamming distance

  • 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 dmin:

Goal Condition
Detect up to s errors dmin≥s+1
Correct up to t errors dmin≥2t+1

So dmin=5 detects 4 or corrects 2.

Hamming code (single-error correction): for m data bits you need the smallest r check bits with 2r≥m+r+1. Check bits sit at positions 1,2,4,8,…. For m=7, r=4 (since 16≥12 while 8<11).

3. Cyclic redundancy check (CRC)

A CRC treats bit strings as polynomials with coefficients mod 2. Sender and receiver agree on a generator G(x) of degree r (so r+1 bits).

Sender: append r zeros to the data M; divide by G using modulo-2 (XOR) division; the r-bit remainder is the CRC. Send data followed by the remainder. The frame is now exactly divisible by G.

Receiver: divide the whole received frame by G. 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 r detects:

  • all single-bit errors, if G has at least two terms;
  • all odd numbers of errors, if (x+1) is a factor of G;
  • all burst errors of length ≤r.

An error pattern E(x) goes undetected exactly when G(x) divides E(x).

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 2Tfr. With G = average frames attempted per frame time, throughput S=Ge−2G, maximum 12e≈0.184 at G=0.5.

Slotted ALOHA: send only at slot starts; vulnerable time Tfr. S=Ge−G, maximum 1e≈0.368 at G=1. With N stations each sending in a slot with probability p: S=Np(1−p)N−1.

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 p 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:

Tt≥2Tp⇒Lmin=2TpR.

After the n-th collision a station picks K uniformly from {0,1,…,2m−1} with m=min⁡(n,10) and waits K 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 51.2 μs, 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:

  1. learns: records (source MAC → incoming port);
  2. filters: drops the frame if the destination is on the same port it came from;
  3. 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 formatPreamble7 BSFD1 BDest MAC6 BSrc MAC6 BType/Len2 BData + pad46 to 1500 BCRC4 Bframe size: 64 to 1518 bytessynchronisation, not counted
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 s errors
dmin≥s+1
Error correction by distanceCorrects up to t errors
dmin≥2t+1
Hamming check bitsm data bits, smallest such r
2r≥m+r+1
Pure ALOHA throughput
S=Ge−2G,Smax=12e≈0.184
Slotted ALOHA throughput
S=Ge−G,Smax=1e≈0.368
Slotted ALOHA, N stationsMaximised at p=1/N
S=Np(1−p)N−1
CSMA/CD minimum frameEquivalently, maximum cable length d=L v2R
Lmin=2 Tp R
Binary exponential backoffAfter the n-th collision; wait K slot times
K∈{0,1,…,2min⁡(n,10)−1}

Common mistakes

  • Forgetting to append r zeros before CRC division, or appending r+1 zeros for an (r+1)-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 Ge−G for pure ALOHA; pure ALOHA has vulnerable time 2Tfr and S=Ge−2G.
  • Using Tt≥Tp for CSMA/CD; the frame must outlast the round trip, Tt≥2Tp.
  • Counting the preamble in the 64-byte minimum or 1518-byte maximum Ethernet frame size.
  • Mixing detection and correction: dmin=4 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 (x3+1). Find the CRC and the transmitted frame, and check it at the receiver.

  1. 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 2×108 m/s. Find the minimum frame size.

  1. 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.

  1. 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?

  1. 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.

Practise these 19 PYQs →

Topic test

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.