DLL Framing in Computer Networks: Methods, Bit Stuffing and Worked Examples

Learn how the data link layer finds frame boundaries and preserves transparency. Work through corrupted counts, escaped bytes and bit stuffing with exact overhead calculations.

KnowledgeGate Team

Exam prep & CS education

Updated 6 Sep 20265 min read

A receiver gets one continuous bit or byte stream, not visible boxes labelled “frame 1” and “frame 2”. DLL framing creates those boundaries, while transparency stops payload data being mistaken for a delimiter. Solve count, byte-stuffing and bit-stuffing questions by tracking boundaries and reversing the receiver's transformation.

Related reading: data link error control and data link flow control.

What DLL framing solves

The network layer supplies a packet. The data link layer adds control information and exposes a bounded frame. The physical layer carries a continuous signal. Framing means identifying the start and end of each frame. Error detection, retransmission and flow control are separate data-link functions that may accompany it.

Two requirements belong together:

  • Synchronisation tells the receiver where a frame begins and ends.

  • Transparency allows every possible payload value to travel without being mistaken for framing control data.

If a link carries A B C D E F G, where should the receiver split it? No visible gap or useful timing pause can be assumed. Both ends need agreed boundary information.

Use the GATE CS exam category for the broad preparation path. For a structured route, GATE Guidance by Sanchit Sir includes a DLL: Framing unit in its Computer Networks curriculum.

Four framing methods and their trade-offs

Method

Boundary idea

Transparency mechanism

Main weakness

Character count

A length field states the frame size

The receiver counts the stated number of bytes

A damaged count can destroy alignment

Byte stuffing

Reserved byte values mark boundaries

An escape byte prefixes reserved payload bytes

It is byte-oriented and expands reserved data

Bit stuffing

A reserved flag bit pattern marks boundaries

A zero is inserted after five consecutive payload 1 bits

It is bit-oriented and adds data-dependent overhead

Physical-layer coding violations

Special signal symbols mark boundaries

Ordinary data cannot produce the reserved symbols

It needs a compatible line code

A delimiter fails if its value can occur inside the payload. Byte stuffing changes the transmitted byte sequence; bit stuffing changes the transmitted bit sequence. The receiver reverses either change before delivering the payload upward.

Here, character count includes its one-byte count field. The byte-oriented toy protocol uses FLAG = 0x7E and ESC = 0x7D. The bit-oriented protocol uses flag 01111110 and inserts 0 after every five consecutive payload 1 bits.

Character count: one bad count, two lost frames

Each count in this stream includes itself:

0x05 0x41 0x42 0x43 0x44 | 0x04 0x45 0x46 0x47

Count 5 gives frame 1 payload A B C D; count 4 gives frame 2 payload E F G. Before other headers or trailers, frame 1 efficiency is:

payload bytes / total bytes = 4/5 = 80%

Corrupt only the first count from 0x05 to 0x07. The receiver consumes:

0x07 0x41 0x42 0x43 0x44 0x04 0x45

It swallows the next count byte 0x04 and first payload byte 0x45 (E). The next byte, 0x46 (F), becomes hexadecimal count 0x46, decimal 70. Alignment is not automatically recovered.

A length field is compact, but its corruption can damage later frames unless a separate resynchronisation mechanism exists. Character count does not detect the corruption itself.

Byte stuffing worked example

This toy prefix-escape rule does not describe every real protocol:

  • Start and end delimiter: FLAG = 0x7E

  • Escape byte: ESC = 0x7D

  • Payload rule: prefix every literal 0x7E or 0x7D with 0x7D

Start with the four-byte payload:

0x41 0x7E 0x7D 0x42

These are A, a literal flag, a literal escape and B. Prefix the two reserved bytes to get:

0x41 0x7D 0x7E 0x7D 0x7D 0x42

Add boundary flags:

0x7E | 0x41 0x7D 0x7E 0x7D 0x7D 0x42 | 0x7E

The receiver treats 0x7D 0x7E as literal 0x7E and 0x7D 0x7D as literal 0x7D, recovering the four original bytes between the delimiters.

The sizes are 4 payload bytes, 6 stuffed bytes and 8 on-wire bytes. Framing and stuffing add 4 bytes, so efficiency is 4/8 = 50%. It varies with payload length and reserved-value frequency.

Byte stuffing example: a 4-byte payload expands to 6 stuffed bytes, then an 8-byte on-wire frame between two 0x7E flags.

Bit stuffing, bit by bit

With flag 01111110, take 15-bit payload 011111101111110. It has two six-1 runs. Scan only the payload, inserting 0 after the fifth 1 in each run.

Mark the inserted bits:

0 11111 [0 inserted] 1 0 11111 [0 inserted] 1 0

The stuffed payload is exactly 01111101011111010, 17 bits long. Transmit:

01111110 | 01111101011111010 | 01111110

The receiver keeps delimiters outside the scan and removes a 0 after five consecutive payload 1 bits. Removing two zeros recovers 011111101111110.

The arithmetic is:

  • Stuffed bits inserted: 2

  • Flag bits: 8 + 8 = 16

  • Total transmitted length: 8 + 17 + 8 = 33 bits

  • Payload-to-complete-frame efficiency: 15/33 = 45.45%, rounded to two decimals

15/17 measures only stuffing expansion and excludes both flags.

Bit stuffing example: a 15-bit payload becomes 17 stuffed bits, then a 33-bit transmitted frame with 01111110 start and end flags.

Choosing a method and continuing up the stack

Use length information only with dependable boundary validation and recovery. Use byte stuffing for reserved octets, bit stuffing for a reserved bit flag, and coding violations when physical encoding reserves otherwise invalid symbols. Real protocols may combine framing with checks, so the four categories are conceptual tools, not universal one-feature-only designs.

Continue with IP addressing and subnetting, then distance-vector and link-state routing, then TCP versus UDP. Framing moves a network-layer packet across one link; these topics move from addressing and routing towards end-to-end transport.

Quick check: can literal 0x7E survive? Yes, as 0x7D 0x7E. Can six raw 1 bits remain consecutive in the stuffed payload? No, because zero follows the fifth.

How questions and interviews test framing

Common tasks are to generate or reverse stuffing, count inserted bits, calculate efficiency, or diagnose corruption of a count, flag, escape or stuffed bit. Checkpoint: 01111101011111010 -> 011111101111110, with exactly 2 removed bits.

For an implementation interview, use a one-pass state machine with ones = 0. Emit each bit; increment on 1; reset on data 0; when ones == 5, emit extra 0 and reset. Test empty payload, five, six and ten 1 bits, plus data that resembles the flag after stuffing.

Use timed, mixed practice through the GATE Test Series, whose page includes Computer Networks coverage. Verify current syllabus, marks, dates, question counts and paper pattern on the organising institute's official GATE portal.

Framing traps and the short version

Correct four traps:

  • Frame = packet: wrong. Each layer has its own protocol data unit.

  • A delimiter alone guarantees transparency: wrong when the delimiter value can occur in payload data.

  • Stuffing changes the delivered data: wrong. The receiver reverses the transformation.

  • Every zero after five ones is removed: wrong. De-stuffing applies only inside a correctly identified stuffed payload under the agreed rule.

Core framing rules:

  • Framing finds boundaries.

  • Character count carries a length.

  • Byte stuffing escapes reserved bytes.

  • Bit stuffing breaks flag-like runs.

Write the rule, scan left to right, mark insertions or removals, then count flags separately. Redo the 15-bit example, recover 011111101111110, and verify the 33-bit total. Then use GATE Guidance by Sanchit Sir for the broader Computer Networks sequence.