What is Bit Stuffing? Bit stuffing is like adding extra bits to a data transmission to help the receiver understand when a new piece of data begins and ends. The receiver can then easily spot and take out these extra bits.

Frames & Data Link Layer: In the data link layer of the Open Systems Interconnection model, a continuous flow of bits is split into smaller units called frames. These frames hold details about the sender and recipient to aid in sending the data across.

8-Bit Flag: To mark the beginning and end of each frame, a special 8-bit flag byte is inserted at both ends of the sequence. This prevents the receiver from mistaking the flag for actual data.

Additional Usage: Bit stuffing has additional uses beyond framing. It can adjust bit streams with different rates to match, ensuring buffers or frames are filled uniformly.

To understand more about Bit Stuffing you must first see Bit Oriented Approach.

Bit-Oriented Approach:

A frame is viewed in this approach as a “collection of bits”.

How Bit Stuffing works:

  • In a bit-oriented protocol, the data to send is a series of bits.
  • To distinguish frames, most protocols use a bit pattern of 8-bit length (01111110) as the flag at the beginning and end of each frame.
  • Here also causes the problem of the appearance of the flag in the data part to deal with this an extra bit is added.
  • This method is called bit stuffing. In bit stuffing, if a 0 and five successive 1 bits are encountered, an extra 0 is added.
  • Moreover, The receiver node removes the extra-added zero.

How Byte Stuffing works:

  • The second framing solves the problem of re-synchronization by having each frame start and end with special bytes.
  • A flag byte is used to separate the frame as both the starting and ending delimiter, as shown in the figure.
  • In this way, if the receiver ever loses synchronization, it can just search for the flag byte to find the end of the current frame.
  • Two consecutive flag bytes indicate the end of one frame and the start of the next one.
  • It may easily happen that the flag byte’s bit pattern occurs in the data.
  • Moreover, To solve this problem is to have the sender’s data link layer inserts a special escape byte (ESC) just before each “accidental” flag byte in the data.
  • The data link layer on the receiving end removes the escape byte before the data is given to the network layer.
  • This technique is called byte stuffing or character stuffing.
  • The disadvantage of using this framing method is that it is closely tied to the use of 8-bit characters.
  • Not all character codes use 8-bit characters.
  • e.g. UNICODE uses 16-bit characters

How Data Stuffing is Useful in Transmission?

Why soh is replaced with esc x?

If the receiver can receive two times soh and get confused then it can receive two times esc x similarly. To prevent data being interpreted as control information data stuffing is used.

It may easily happen that the control information (SOT, EOT) pattern occurs in the data. This is called interface with framing.

A way to solve the problem is “Special escape byte insertion just before each ‘accidental’ control information (SOT, EOT) in data. While receiving the data, it removes the escape byte before the data is given to the network layer and is called character stuffing or byte stuffing. Thus, framing delimiters can be distinguished from one in the data by the absence or presence of an escape byte before it.

What happens if an escape byte occurs in the middle of the data?

You need to stuff it with an escape byte. Thus, any single escape byte is part of an escape sequence, whereas in the data a doubled one shows that a single escape occurred naturally.

All cases are the same as the original byte sequence. After De-stuffing byte sequence will be delivered.

What is the bit-oriented protocol?

HDLC -> High-Level Data Link Protocol is known as a bit-oriented protocol.

Frame Format in HDLC (high-level data link protocol)?

Beginning — 8 bits
Header —— 16 bits
Body ———
CRC ———- 16 bits
Ending ——- 8 bits

Why soh is replaced with esc x

If the receiver can receive two times soh and get confused then it can receive two times esc x similarly.