Trapti Gupta

Difference between Byte Stuffing and Bit Stuffing

At the receiver end the data bits stream, received from the physical layer is divided into the frames on the data link layer. Data frames can have fixed or variable length sizes. The size of every frame is different in variable framing so bit patterns are used in starting and end of the data frame. So it can be easily differentiated from other data frames. But if the bit pattern occurs in the data frame, then Bit stuffing and Byte stuffing are used to overcome this problem. Byte stuffing also known as character-oriented framing is used for differentiating the occurrence of the flag pattern in the message from the delimiter, a byte is stuffed in the data. In Bit stuffing (bit-oriented framing), an arbitrary length bit pattern is stuffed in the message to differentiate from the delimiter.

What is Bit Stuffing?

Bit stuffing is the method of adding non-information bits into the data frame. So that the message sequence can be broken for the synchronization.

The bit pattern is stuffed in the message to differentiate the data from the delimiter. This is also known as bit-oriented framing.

Frame in a Bit-Oriented Protocol

The message is coded in the form of bits sequence in bit-oriented protocols and this data is represented as the text, audio, video, graphics, etc. in the upper layers. A frame consists of 4 parts which are given below:

  • Frame Header: Frame Header represents the frame’s source and destination address.
  • Payload field: Actual message that is to be delivered is in this field.
  • Trailer: Bits related to error correction and detection are in this field.
  • Flags: A sequence of the bits that represent the frame starting and ending. An 8-bit sequence 01111110 is used by most protocols such as the High-Level Data Link Protocol.

Refer to the below image for the frame in the bit-oriented approach

frame_in_a_bit_oriented_protocol

Bit Stuffing Mechanism

The flag is used as the delimiter in the frames of the data link layer and this flag mainly contains six or more six successive 1’s sequences. In some cases, message also contains the same flag sequence so to differentiate the message content, a single bit is stuffed in the message. When the 0-bit is found in the message which is followed by the 5 successive 1’s, then for differentiating it from the flag an extra 0 bit is added after the five 1’s.

When the receiver receives the data frame sent by the sender then for de-stuffing the message, it removes all the 0s which are found after five consecutive 1s in the data. Then this unstuffed message is transmitted to the upper layers.

Refer to the below image for the bit-stuffing mechanism

bit_stuffing_mechanism

What is Byte Stuffing?

In byte-stuffing, a byte which is known as an Escape character(ESC) is stuffed in the message so that the flag pattern present in the data can be differentiated from the flag representing the starting and ending of the data. This is also known as character-oriented framing.

Frame in a Character–Oriented Framing

In character-oriented protocols, codes like ASCII codes are used for coding messages as 8-bit characters.

A frame consists of the following parts:

  • Frame Header: Frame Header represents the frame’s source and destination address.
  • Payload field: Actual message that is to be delivered is in this field.
  • Trailer: Bits related to error correction and detection are in this field.
  • Flags: The size of the flag is 1 byte (8-bits) and the flag is added at the start and end of the data frame. It is a special character that is dependent on the signals start and end of the frame.

Refer to the below image for the frame in the character-oriented approach

frame_in_a_character–oriented_framing

Byte Stuffing Mechanism

If the message contains a byte that is similar to the flag byte, then there is a requirement of the method so that the receiver recognizes that this is not the end of the frame. The byte-stuffing mechanism is used in the character-oriented approach.

In the byte stuffing mechanism, a special byte which is known as an escape character(ESC) is used for stuffing before every byte in the message which is similar to the flag byte. And if the message contains a sequence that is similar to the Escape characters sequence then another ESC byte is stuffed before that byte of the data.

When the receiver receives the data frame sent by the sender then for de-stuffing the message, it removes all the bytes that are found before the escape character pattern in the data and then de-stuff it by removing the escape character bytes that are found before the flag pattern in the data. Then this unstuffed message is transmitted to the upper layers.

Refer to the below image for the byte-stuffing mechanism

byte_stuffing_mechanism

Difference between Bit Stuffing and Byte Stuffing

Bit stuffingByte stuffing
This is also known as bit-oriented framing.This is also known as character-oriented framing.
The flag pattern of 8-bit “01111110” is mostly used for representing the starting and end of the flag. But data may also contain a bit pattern similar to a flag pattern. So, to overcome this problem, an extra zero is stuffed in the data whenever there is a zero followed by 5 consecutive 1s in the data.Escape character(ESC) of 1-byte which was the predefined pattern of the bit is stuffed in the data frame where there is the same data pattern as the flag pattern.
In this approach single bit is stuffed into the data.In this approach single byte is stuffed in the data.
When the receiver receives he removes the extra bit for de-stuffing the data.When the receiver receives he removes the ESC (Escape character) for de-stuffing of the data.
Disadavantage of bit-stuffing is that code rate becomes unpredictable as it is dependent on the transmitted dataDisadavantage of byte-stuffing is that this is only applied to the 8-bits character and 8-bit character code and is not used by all characters.

Conclusion

  • In variable size framing flag is used to define the starting and end of the flag.
  • But there may be a situation where there is a pattern in the data that is similar to the flag pattern. So to differentiate that pattern of data from delimiter byte-stuffing and bit-stuffing are used.
  • Bit-stuffing is a bit-oriented approach in which an extra bit is stuffed in the data where there is a data pattern similar to the flag pattern.
  • Byte-stuffing is a byte-oriented approach in which an extra byte which is also known as Escape characters(ESC) is stuffed in the data where there is a byte in the data which is similar to a flag byte.

Author