Bit stuffing inserts non-information bits into transmitted data so that a reserved flag cannot appear inside a frame or a serial receiver does not lose timing during a long run of identical bits. The extra bits exist only on the wire: the receiver recognizes and removes them, leaving the original payload unchanged. HDLC uses it for framing, USB for clock recovery, and CAN for synchronization and error detection, and each protocol applies a different rule.
What Bit Stuffing Changes on the Wire
At the data link layer, bit stuffing changes a stream of bits, not the information carried by the application. The sender inserts a bit when a specified pattern occurs. The receiver uses the same pattern rule to de-stuff the stream before delivering the data.
Stuffed bits are not headers, checksums, or control fields. Those fields are part of a frame and carry protocol information. A stuffed bit carries no payload information; it is a temporary change to the transmitted representation. For example, HDLC can carry a payload byte that equals its flag, yet the flag pattern itself never appears in the frame body on the wire.
Why a Serial Link Sometimes Needs Extra Bits
Serial links that use NRZ encoding can recover timing from transitions in the received signal rather than from a separate clock line. With a long sequence of identical bits, there may be no transitions. The receiver’s phase-locked loop can then lose lock and sample later bits at the wrong time.
USB illustrates the problem. Its NRZI encoding makes a 0 produce a transition and a 1 produce no change. After six consecutive 1s, USB inserts a 0 before NRZI encoding. That forced 0 creates a transition, guaranteeing one at least every seven bit times. In HDLC, the same general technique also protects the frame delimiter: the flag 01111110 marks the beginning and end of a frame, so it must not occur in transmitted payload data.
How HDLC Keeps Its Flag Out of the Frame Body
HDLC and SDLC insert a 0 after five consecutive 1s between flags, regardless of what the next actual data bit will be. The result is that six consecutive 1s cannot occur in an ordinary frame body, making 01111110 an unambiguous marker. Flags can also be sent continuously while idle to maintain synchronization.
A bit-stuffing example, step by step
- Start with the payload byte
01111110, which is identical to the HDLC flag. - Count five consecutive 1s and insert a 0.
- Transmit
011111010, conventionally grouped as011111 0 10. - After seeing five 1s followed by 0, the receiver removes that 0 and restores
01111110.
Payload: 01111110
On wire: 011111010
011111 0 10
For the 16-bit sequence 0111111101111110, two runs trigger insertion. Its transmitted form has 18 bits: 011111 0 11011111 0 10. Frame length therefore depends on data content, not just payload length.
HDLC de-stuffing also distinguishes data from control conditions. After five 1s, a following 0 is discarded as stuffed. If the next bit is 1, the receiver checks one more bit: a 0 completes the flag; a 1 produces 01111111, an error. Seven or more consecutive 1s signal an abort, and the frame in progress is discarded.
CAN and USB Use Different Run-Length Rules
Bit stuffing is not a universal algorithm. Applying the HDLC rule to CAN or USB would produce the wrong data stream. CAN counts either polarity; USB specifically counts 1s before NRZI encoding.
| Protocol | Insertion rule | Important boundary |
|---|---|---|
| HDLC | Insert 0 after five consecutive 1s. | Between flag sequences. |
| CAN | Insert the complementary bit after five identical bits. | From Start of Frame through the CRC sequence. |
| USB 1.x/2.0 | Insert 0 after six consecutive 1s. | Before NRZI encoding, from Sync Pattern through transmission. |
In classical CAN, a run of five recessive or five dominant bits gets an opposite stuff bit. The receiver removes the expected complement; six identical bits in the stuffable region are a stuff error. The CRC delimiter, ACK slot, ACK delimiter, and End of Frame have fixed form and are not stuffed. CAN FD changes the rule for the CRC field: fixed stuff bits are inserted before the first CRC bit and after every fourth bit, regardless of bit value. The CAN FD CRC calculation also covers the stuff bits of the preceding fields, and a 3-bit stuff-bit count with a parity bit follows the data field.
USB treats a seventh consecutive 1 as a bit-stuff violation. After NRZI decoding, the receiver identifies the 0 after six 1s and removes it. The resulting transition keeps the receiver synchronized.
How to Calculate Frame Length After Bit Stuffing
Calculate the length in two parts: first count the fields subject to stuffing and apply the protocol’s run rule to their actual or worst-case bit pattern; then add fields that are outside that rule, such as delimiters, CRC fields, and inter-frame spacing where applicable. Divide the final number of bit times by the link rate to obtain the transmission time.
For worst-case planning, an all-1s HDLC payload adds one stuffed 0 for every five data bits, or 20% overhead. USB’s all-1s data adds about 17%. CAN can reach 25% overhead because the complementary stuffed bit itself counts toward the next run; its expansion is not simply one bit per five original bits.
Use worst-case expansion for buffers and timeouts, rather than average traffic. A classical CAN base frame with 8 data bytes and a worst-case bit pattern occupies 135 bit times, including stuffing and inter-frame space; that is 135 µs at 1 Mbit/s. In CAN base frames, data-dependent stuffing can introduce up to 24 bit times of jitter.
Bit Stuffing Versus Byte Stuffing
Bit stuffing works below byte boundaries. Byte stuffing works on complete bytes: an escape byte such as 0x7D is inserted before any payload byte that matches the flag 0x7E or the escape byte itself, and in PPP the escaped byte is also modified so the flag value never appears in the body.
| Method | Unit altered | Stated worst case | Implementation fit |
|---|---|---|---|
| HDLC bit stuffing | Individual bits | 20% overhead | Well suited to serial hardware |
| PPP byte stuffing | Whole bytes | 100% overhead | More natural for byte-oriented software |
PPP over asynchronous serial links uses byte stuffing because inserting individual bits into byte-oriented RS-232 transmission is impractical. The tradeoff is visible in the worst case: every payload byte may need escaping, doubling packet size.
Where Bit Stuffing Is Used and Where It Is Not
HDLC and its variants, including LAPB, LAPD, LAPF, and PPP over synchronous links, use HDLC-style bit stuffing. USB 1.x and USB 2.0 Low Speed and Full Speed use the 0-after-six-1s rule. CAN uses complementary stuffing after five identical bits in automotive, industrial, and aerospace systems.
High-speed serial links such as 10 GbE, PCIe, and SATA do not use bit stuffing. Data-dependent overhead complicates pipelining at those speeds, so they use block codes such as 8b/10b or 64b/66b with fixed overhead instead.
Advantages and Disadvantages of Bit Stuffing
- It bounds runs: predictable transitions support clock recovery on NRZ or NRZI links.
- It protects delimiters: a flag can remain unique inside a bit-oriented protocol.
- It exposes some faults early: a missing expected stuff bit or an overlong run is detectable before CRC evaluation.
- It does not replace a CRC: stuffing alone cannot detect every transmission error or protect payload integrity.
- It adds variable cost: frame length, transmission time, and real-time jitter depend on the data.
Common Bit-Stuffing Misconceptions
- “Stuffed bits are payload.” They are non-information bits removed by the receiver; the original data is recovered unchanged.
- “Every protocol inserts a 0 after five 1s.” HDLC does, but CAN inserts an opposite bit after five identical values and USB inserts 0 after six 1s.
- “Stuffing makes a frame error-proof.” A stuff error is useful evidence of a malformed stream, but CRC-based error detection is still required.
Frequently Asked Questions
What is meant by bit stuffing?
It is the insertion of non-information bits into a transmitted data stream according to a shared protocol rule. The receiver removes those bits to recover the original payload.
Why is bit stuffing used in data framing?
It can keep a reserved delimiter such as the HDLC flag 01111110 from appearing inside frame data, so frame boundaries remain unambiguous.
What is the difference between bit stuffing and byte stuffing?
Bit stuffing inserts individual bits based on a bit pattern. Byte stuffing inserts escape bytes around reserved byte values, which is more convenient on byte-oriented links but can have higher worst-case overhead.
What is the difference between a framing character and bit stuffing?
A framing character or flag is the marker used to delimit a frame. Bit stuffing is the encoding rule that makes sure an equivalent marker pattern does not appear unexpectedly in frame data.
How does the receiver remove stuffed bits?
It counts the same patterns as the sender. For example, an HDLC receiver removes a 0 after five 1s; a CAN receiver removes the complementary bit after five identical bits.
How do you calculate the frame length after bit stuffing?
Apply the protocol’s stuffing rule to the fields it covers, count inserted bits, then add unstuffed framing fields and any required inter-frame space. For timing and buffer design, use the worst-case expansion.

