codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🌐

Computer Networks

26 chapters

1Network Topologies & LAN/WAN2Network Devices (Hub, Switch, Router)3OSI Reference Model4OSI Model & TCP/IP Suite5TCP/IP Protocol Suite6Switching Techniques (Circuit, Packet)7Data Link: Framing & Error Detection8Error Correction (Hamming Code)9Flow Control (Stop-and-Wait, Sliding Window)10MAC: CSMA/CD & CSMA/CA11Network Layer & Routing12IP Addressing (IPv4, IPv6)13Subnetting & CIDR14Routing Algorithms (Distance Vector, Link State)15ARP, ICMP, and NAT16DHCP Protocol17Transport Layer Services18Transport Layer: UDP19Transport Layer: TCP & 3-Way Handshake20TCP Congestion Control21Application Layer: DNS & HTTP22Application Layer: SMTP & FTP23Socket Programming Basics24Wireless Networks & Wi-Fi Standards25VLANs & Spanning Tree Protocol26Network Security & Cryptography
SubjectsComputer Networks

Data Link: Framing & Error Detection

Updated 2026-04-30
3 min read

Data Link: Framing & Error Detection

The Data Link Layer (Layer 2) is responsible for the transfer of data between two nodes on the same physical network segment. While the Network Layer deals with routing packets across the globe, the Data Link layer only cares about getting the data to the next immediate device (like from your laptop to your home router).

To achieve this, it must solve two major problems: how to divide the raw stream of 0s and 1s into meaningful blocks (Framing), and how to ensure those blocks weren't corrupted by electrical noise during transmission (Error Detection).

1. Framing

The Physical layer translates bits into signals and sends them over the wire. However, the receiver just sees a continuous stream of signals. It needs to know exactly where one message starts and where it ends.

The Data Link layer breaks the bit stream into discrete blocks called Frames. A frame consists of a Header (containing MAC addresses), the Payload (the IP Packet), and a Trailer (used for error detection).

Framing Methods

  1. Character Count: The header specifies the exact number of characters (bytes) in the frame. If the count gets corrupted, the receiver loses synchronization entirely.
  2. Flag Bytes with Byte Stuffing: A special "Flag" byte (e.g., 01111110) is used to mark the beginning and end of a frame.
    • Problem: What if the actual payload data contains the Flag byte by coincidence? The receiver would mistakenly think the frame has ended.
    • Solution (Byte Stuffing): The sender inserts a special "Escape" byte immediately before any accidental Flag byte in the payload. The receiver strips out the Escape bytes.
  3. Bit Stuffing: Similar to byte stuffing, but operates at the bit level. If the flag is 01111110 (six consecutive 1s), the sender guarantees that six 1s will never appear in the payload by automatically inserting a 0 after any sequence of five consecutive 1s in the data. The receiver automatically deletes any 0 that follows five 1s.

2. Error Detection

Electrical interference, cosmic rays, or bad cables can easily flip a 0 to a 1 while the data is traveling over the wire. The Data Link layer uses mathematical techniques stored in the Frame Trailer to detect these errors.

1. Parity Check

The simplest error-detecting code. A single parity bit is added to the end of a block of data.

  • Even Parity: The bit is set to 1 or 0 to ensure the total number of 1s in the block is an even number.
  • Flaw: If two bits flip simultaneously (a burst error), the parity remains the same, and the error goes completely undetected.

2. Checksum

Used heavily by upper layers (TCP/IP). The data is divided into equal-sized segments (e.g., 16 bits). These segments are added together using one's complement arithmetic, and the sum is inverted to create the Checksum. The receiver performs the same addition; if the result is not all 1s, an error occurred.

3. Cyclic Redundancy Check (CRC)

The most powerful and widely used technique at the Data Link layer (used in Ethernet and Wi-Fi).

  • It is based on polynomial division. The data bit string is treated as a massive polynomial.
  • The sender divides this polynomial by a predetermined "Generator Polynomial" using modulo-2 arithmetic.
  • The remainder of this division is the CRC. It is appended to the frame.
  • The receiver divides the incoming frame (data + CRC) by the exact same Generator Polynomial. If the remainder is 0, the data is perfectly intact. If the remainder is non-zero, the frame is corrupted and is instantly discarded.


PreviousSwitching Techniques (Circuit, Packet)NextError Correction (Hamming Code)

Recommended Gear

Switching Techniques (Circuit, Packet)Error Correction (Hamming Code)