Bit and Byte Stuffing
Synchronous versus Asynchronous
Transmissions
• There exists a hierarchy of synchronization
tasks:
– Bit level : recognizing the start and end of each
bit
– Character or byte level : recognizing the start
and end of each character (or small unit of
data)
– Block or message level : recognize the start and
end of each large unit of data (in networks this
is a frame).
The contents of each frame are encapsulated between a
pair of reserved characters or bytes for frame synchronization.
frame
Preamble Postamble
Bit Pattern Bit Pattern
Byte Stuffing
[HDLC Example]
• Also referred to as character stuffing.
• ASCII characters are used as framing delimiters
(e.g. DLE STX and DLE ETX)
• The problem occurs when these character
patterns occur within the “transparent” data.
Solution: sender stuffs an extra DLE into the data
stream just before each occurrence of an
“accidental” DLE in the data stream.
The data link layer on the receiving end unstuffs the
DLE before giving the data to the network layer.
Byte Stuffing
[HDLC Example]
DLE STX Transparent Data DLE ETX
Before
DLE STX A B DLE H W DLE ETX
Stuffed
DLE STX A B DLE DLE H W DLE ETX
Unstuffed
DLE STX A B DLE H W DLE ETX
Bit Stuffing
• Each frame begins and ends with a special bit
pattern called a flag byte [01111110]. {Note this
is 7E in hex}
• Whenever sender data link layer encounters five
consecutive ones in the data stream, it
automatically stuffs a 0 bit into the outgoing
stream.
• When the receiver sees five consecutive incoming
ones followed by a 0 bit, it automatically destuffs
the 0 bit before sending the data to the network
layer.
Bit Stuffing
Input Stream
0110111111100111110111111111100000
Stuffed Stream
01101111101100111110011111011111000000
Stuffed bits
Unstuffed Stream
0110111111100111110111111111100000