TDEB Top Bar

Trending
Semiconductor Industry News — The Digital Electronics Blog
Follow Us

TDEB Masthead

The Semiconductor Hub

Semiconductors.  Chips and Systems.  Innovation.

Indexed by leading Search Engines, AI and referenced by Engineers worldwide 500+ Articles 10M+ Pageviews 30+ Reports 50+ Citations

HDLC Protocol: Frame Format, Bit Stuffing and Frame Types

The Editor's Desk
by
1
Share Facebook X LinkedIn WhatsApp Email

HDLC (High-level Data Link Control) is a bit-oriented data link layer protocol, standardized by ISO, that carries data in frames marked by the flag pattern 01111110 (0x7E). Each frame holds an address, a control field, optional data and a CRC frame check sequence, and bit stuffing keeps the flag pattern from appearing inside the frame. HDLC and its variants are the basis of LAPB (X.25), LAPD (ISDN), Frame Relay framing and PPP framing.

Key takeaways

  • Frame layout: Flag | Address | Control | Information | FCS | Flag.
  • Bit stuffing: after five consecutive 1s inside a frame, the transmitter inserts a 0, and the receiver removes it.
  • Three frame types, identified by the control field: I-frames (data), S-frames (supervisory, acknowledgement and flow control) and U-frames (unnumbered, link set-up and management).
  • The usual FCS is a 16-bit CRC (polynomial x16 + x12 + x5 + 1), with a 32-bit option.
  • HDLC descends from IBM's SDLC; PPP over serial links uses an HDLC-like framing defined in RFC 1662.

What is HDLC?

HDLC is a bit-oriented, link layer protocol for the transmission of data over synchronous networks. It is an ISO standard, but is a superset of IBM's SDLC (Synchronous Data Link Control) protocol. SDLC was the successful follow-up to the BISYNC communication protocol and was originally introduced with IBM SNA (Systems Network Architecture) products. Another name for HDLC is ADCCP (Advanced Data Communications Control Procedure), an ANSI standard, but HDLC is the widely accepted name for the protocol. There are some incompatibilities between SDLC and HDLC, depending on the vendor.

Two Internet RFCs are related to HDLC. These are RFC 2687 (PPP in a Real-Time Oriented HDLC-like Framing, September 1999) and RFC 1662 (PPP in HDLC-like Framing, July 1994).

Note (checked November 2026): the RFC links now point to the RFC Editor pages for each document. The current ISO standard for HDLC procedures is ISO/IEC 13239:2002, which ISO lists as last reviewed and confirmed in 2007.

How HDLC works, in outline

Think of a serial line as a continuous stream of bits with no natural boundaries. HDLC solves three problems on that stream:

  • Where does a frame start and end? Every frame begins and ends with the same 8-bit flag, 01111110. A receiver hunts for the flag and knows a frame has started.
  • What if the data looks like a flag? The transmitter never lets six 1s in a row appear inside a frame. After any five 1s it slips in an extra 0, and the receiver takes it out again. This is bit stuffing.
  • Did the frame arrive intact, and in order? Each frame carries a CRC check value, and data frames carry sequence numbers so the receiver can acknowledge them or ask for a resend.

The control field tells the receiver what kind of frame it is: a data frame, a supervisory frame that acknowledges or pauses traffic, or an unnumbered frame that sets up or tears down the link.

Why it still matters

HDLC itself is rarely the headline protocol today, but its ideas are everywhere. PPP on serial links uses HDLC-like framing, X.25 and ISDN signaling are built on HDLC variants, and Cisco's HDLC variant is used on router serial links. For a hardware engineer, HDLC is also a classic interview and design exercise: bit stuffing, flag detection and CRC generation are small, well-defined blocks that test serial datapath skills.

Quick answers

Why is HDLC called bit-oriented?

Frames are delimited by a bit pattern, the flag, and transparency is achieved by inserting single bits. The payload does not have to be a whole number of bytes, unlike character-oriented protocols such as BISYNC.

What is the HDLC flag?

The 8-bit pattern 01111110, 0x7E in hexadecimal. It starts and ends every frame.

Why does HDLC insert a 0 after five 1s?

So that six consecutive 1s, and therefore the flag pattern, can never appear inside a frame. The receiver removes the inserted 0s.

What is the difference between HDLC and PPP?

HDLC is a complete data link protocol with sequence numbers, acknowledgements and several modes. PPP borrows HDLC-like framing but normally sends unnumbered frames and adds its own link control and network control protocols.

What is the difference between HDLC and SDLC?

SDLC is IBM's earlier protocol and works mainly in Normal Response Mode. HDLC is the ISO generalization, adding balanced and asynchronous modes and extended sequence numbers. Details differ between vendors.

Deep dive: the numbers and details

This part holds the frame fields, worked bit stuffing examples, a Verilog bit stuffer, the control field layout and the CRC parameters. Skip it if the overview is all you need.

HDLC frame format

FieldSizePurpose
Flag8 bits, 01111110 (0x7E)Marks the start and end of a frame. One flag can close one frame and open the next.
Address8 bits (extendable)Identifies the secondary station on a multipoint link. On point-to-point links it is often a fixed value, for example 0xFF (all stations) in PPP.
Control8 bits (16 bits in extended mode)Frame type, sequence numbers and the poll/final bit.
InformationVariable, may be emptyThe payload, present in I-frames and some U-frames.
FCS16 or 32 bitsCRC over address, control and information fields, used to detect errors.
Flag8 bits, 0x7ECloses the frame.

A sequence of seven or more consecutive 1s is an abort: the receiver discards the frame in progress. Between frames the line carries continuous flags or, in some systems, idle 1s.

Bit stuffing, with worked examples

Because the flag 01111110 contains six 1s in a row, the frame body must never contain six consecutive 1s. The transmitter therefore inserts a 0 after every run of five 1s between the flags, whatever the next bit is. The receiver, on seeing five 1s followed by a 0, deletes the 0. If it sees five 1s followed by a 1, the next bit tells it whether this is a flag (0) or an abort (1).

Data bitsTransmitted bitsInserted 0s
01111110 (a data byte equal to the flag)0111110101
111111111111101111
01111111011111100111110110111110102

Step by step for the third row, 0111111101111110: the first five 1s (bits 2 to 6) are followed by an inserted 0, giving 0111110; the remaining 1, 1, 0 follow; then the next run of five 1s gets another inserted 0. The full result is 011111011011111010, 18 bits from 16. In the worst case, all 1s, the overhead is one extra bit per five data bits, or 20 percent.

PPP over asynchronous links (RFC 1662) cannot insert single bits, so it uses byte stuffing instead: any 0x7E or 0x7D byte inside the frame (and any control character selected by the negotiated async control character map) is sent as 0x7D followed by the original byte XOR 0x20. On synchronous links RFC 1662 uses bit stuffing as in HDLC.

A small Verilog bit stuffer

The module below inserts a 0 after every five consecutive 1s on a serial stream. It drops in_ready for one cycle while it sends the stuffed bit, so the source must hold its bit until in_ready is high. It assumes the downstream logic accepts one bit every cycle that out_valid is high. Flags are sent around the stuffer by the framing logic, since they must not be stuffed.

module hdlc_bit_stuffer (
  input  wire clk,
  input  wire rst_n,
  input  wire in_valid,
  input  wire in_bit,
  output wire in_ready,
  output reg  out_valid,
  output reg  out_bit
);
  reg  [2:0] ones;                 // count of consecutive 1s sent
  wire       stuff = (ones == 3'd5);

  assign in_ready = !stuff;

  always @(posedge clk or negedge rst_n) begin
    if (!rst_n) begin
      ones      <= 3'd0;
      out_valid <= 1'b0;
      out_bit   <= 1'b0;
    end else if (stuff) begin      // insert the 0 after five 1s
      out_valid <= 1'b1;
      out_bit   <= 1'b0;
      ones      <= 3'd0;
    end else if (in_valid) begin
      out_valid <= 1'b1;
      out_bit   <= in_bit;
      ones      <= in_bit ? ones + 3'd1 : 3'd0;
    end else begin
      out_valid <= 1'b0;
    end
  end
endmodule

The receiver does the reverse: it counts 1s, drops the bit that follows five 1s if it is a 0, and treats 01111110 as a flag and seven or more 1s as an abort.

Frame types and the control field

TypeControl field bits (first bits sent)ContentsExamples
I-frame (information)0, then N(S), P/F, N(R)User data plus send and receive sequence numbersData transfer with piggybacked acknowledgement
S-frame (supervisory)1 0, then type, P/F, N(R)Acknowledgement and flow control, no dataRR (receive ready), RNR (receive not ready), REJ (reject), SREJ (selective reject)
U-frame (unnumbered)1 1, then modifier bits and P/FLink set-up, tear-down and other controlSABM, SNRM, DISC, UA, DM, FRMR, UI

With an 8-bit control field the sequence numbers N(S) and N(R) are 3 bits each, so they count modulo 8 and up to 7 frames can be outstanding. The extended 16-bit control field uses 7-bit numbers, modulo 128, for links with long delays such as satellite links. Error recovery uses go-back-N (REJ) or selective repeat (SREJ).

Stations and modes of operation

  • Station types: primary (sends commands), secondary (sends responses) and combined (both).
  • Normal Response Mode (NRM): a secondary may transmit only when polled by the primary. Typical of multipoint links, and the mode SDLC was built around.
  • Asynchronous Response Mode (ARM): a secondary may transmit without being polled, but the primary still manages the link.
  • Asynchronous Balanced Mode (ABM): two combined stations with equal status. This is the mode used by LAPB in X.25 and by LAPD in ISDN.

The frame check sequence

The 16-bit FCS uses the CRC-CCITT polynomial x16 + x12 + x5 + 1. In the form used by HDLC and PPP the register starts at 0xFFFF, bits are processed least significant bit first, and the result is inverted before it is sent. With these settings the CRC of the ASCII string "123456789" is 0x906E, a handy check value when testing an implementation. For how CRCs work in hardware, see our series on cyclic redundancy checking: CRC part 1 and CRC part 2. A short definition of CRC (cyclic redundancy check) is on The Semiconductor Hub glossary.

Where HDLC is used

ProtocolRelation to HDLC
SDLC (IBM SNA)The predecessor; HDLC is a superset
LAPB (X.25)HDLC in Asynchronous Balanced Mode
LAPD (ISDN D channel)HDLC-based, with a two-byte address field
LAPF (Frame Relay)HDLC-style framing with a reduced control set
PPPHDLC-like framing per RFC 1662, usually with address 0xFF and control 0x03 (UI)
Cisco HDLCA vendor variant used on router serial links, with a protocol type field

For a look at a different link layer, see our Ethernet Q&A.

Further reading

The Editor's Desk
About the Author
The Editor's Desk
Share Facebook X LinkedIn WhatsApp Email

Post a Comment

1 Comments

Your comments will be moderated before it appears here.

  1. Amzing Man, you have done a wonderful work !! keep it up!

    ReplyDelete
Post a Comment

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!