Inferensys

Glossary

Gray Coding

A bit-to-symbol mapping scheme where adjacent constellation points differ by only a single bit, ensuring that the most likely symbol errors caused by noise crossing a decision boundary result in the minimum possible number of bit errors.
Developer demonstrating multi-agent tool use, agent tool selection interface on laptop, casual tech demo moment.
BIT-TO-SYMBOL MAPPING

What is Gray Coding?

A bit-to-symbol mapping scheme where adjacent constellation points differ by only a single bit, ensuring that the most likely symbol errors caused by noise crossing a decision boundary result in the minimum possible number of bit errors.

Gray coding, also known as a reflected binary code, is a bit-to-symbol mapping strategy where adjacent points in a signal constellation diagram differ by exactly one bit. This geometric property ensures that when noise causes a received IQ sample to cross a decision boundary into a neighboring Voronoi region, the resulting symbol error produces only a single bit error rather than a multi-bit burst.

This technique is a standard feature in high-order Quadrature Amplitude Modulation (QAM) and Phase Shift Keying (PSK) schemes, directly improving the effective Bit Error Rate (BER) by approximately a factor of log2(M) compared to uncoded mapping. In likelihood-based modulation classifiers and blind receivers, knowledge of the Gray coding structure is often leveraged during symbol mapping reconstruction to resolve phase ambiguity after constellation recovery.

ERROR MINIMIZATION

Key Characteristics of Gray Coding

Gray coding is a bit-to-symbol mapping scheme where adjacent constellation points differ by only a single bit, ensuring that the most likely symbol errors caused by noise crossing a decision boundary result in the minimum possible number of bit errors.

01

The Single-Bit Adjacency Rule

The defining property of Gray coding is that any two constellation points sharing a Voronoi region boundary differ in exactly one bit position. This is not a natural binary sequence but a re-mapped ordering. For example, in standard binary, the transition from 3 (011) to 4 (100) flips three bits, but in Gray code, the sequence is 3 (010) to 4 (110), flipping only the most significant bit. This geometric constraint ensures that when additive white Gaussian noise (AWGN) pushes a received symbol across a decision boundary into an adjacent region, only a single bit error occurs.

02

Bit Error Rate (BER) Optimization

In high signal-to-noise ratio (SNR) regimes, symbol errors are dominated by nearest-neighbor misclassifications. Gray coding directly minimizes the Bit Error Rate (BER) by ensuring each dominant symbol error event causes only one bit flip. The theoretical approximation for Gray-coded M-ary modulation is:

  • BER ≈ Symbol Error Rate / log2(M) This relationship holds because each symbol carries log2(M) bits, and a single symbol error corrupts exactly one bit. Without Gray coding, a single symbol error could corrupt multiple bits, degrading BER performance by up to a factor of log2(M).
03

Hamming Distance of One

The Hamming distance between the bit labels of any two adjacent constellation points is exactly 1. This is the fundamental algebraic property that distinguishes Gray coding from arbitrary symbol mappings. Key implications:

  • The mapping is an isometry between the geometric adjacency graph of the constellation and the hypercube graph of the binary labels.
  • For Quadrature Amplitude Modulation (QAM) constellations, perfect Gray coding exists only when the constellation forms a rectangular grid where each dimension's pulse amplitude modulation (PAM) levels can be independently Gray-coded.
  • For non-rectangular constellations like Amplitude Phase Shift Keying (APSK) or cross-QAM, true Gray coding may not exist, requiring approximate or quasi-Gray mappings.
04

Construction via Reflected Binary Code

Gray code for one-dimensional PAM, which extends to two-dimensional QAM, is generated using the reflected binary code algorithm:

  • Start with a 1-bit code: [0, 1]
  • To generate n+1 bits, reflect the n-bit code (reverse the list) and prefix the original half with 0 and the reflected half with 1.
  • Example: 2-bit code = [00, 01, 11, 10]; 3-bit code = [000, 001, 011, 010, 110, 111, 101, 100]. For M-QAM, the in-phase and quadrature components are independently mapped using this PAM Gray code, producing a two-dimensional labeling where both horizontal and vertical neighbors differ by one bit.
05

Impact on Soft-Decision Decoding

Gray coding significantly improves the performance of soft-decision forward error correction (FEC) decoders, such as low-density parity-check (LDPC) and turbo codes. The mechanism:

  • Soft demappers compute log-likelihood ratios (LLRs) for each bit based on the received symbol's position relative to all constellation points.
  • Under Gray mapping, the LLR for a given bit depends primarily on the nearest decision boundary for that bit position, simplifying computation and reducing correlation between bit LLRs.
  • This near-independence of bit LLRs aligns with the assumption of most binary FEC decoders, preventing the iterative decoding process from being misled by correlated bit error patterns that occur with non-Gray mappings.
06

Limitations and Quasi-Gray Mappings

Perfect Gray coding is not universally achievable:

  • Cross-QAM constellations (e.g., 32-QAM, 128-QAM) have non-rectangular shapes where corner points have fewer than four neighbors, breaking the perfect grid adjacency required for true Gray coding.
  • APSK constellations with multiple concentric rings create adjacency patterns where a point may have more neighbors than available single-bit-difference labels.
  • In these cases, quasi-Gray mapping algorithms minimize the average Hamming distance between adjacent points using search heuristics or integer programming. The result is a mapping where most, but not all, adjacent pairs differ by one bit, with the remaining pairs differing by two bits.
SYMBOL MAPPING COMPARISON

Gray Coding vs. Natural Binary Coding

Comparison of bit-to-symbol mapping schemes for minimizing bit errors in digital modulation constellations.

FeatureGray CodingNatural Binary CodingAnti-Gray Coding

Adjacent symbol bit difference

1 bit

Variable (1 to k bits)

Maximum (k bits)

Most likely symbol error result

Single bit error

Multiple bit errors

All bits in error

BER approximation for high SNR

SER / k

≈ SER × (k+1) / 2k

≈ SER

Hamming distance between neighbors

1

1 to k

k

Mapping complexity

Reflective binary algorithm

Sequential binary count

Inverse Gray algorithm

Typical use case

QAM, PSK, APSK

Legacy systems, unipolar

Theoretical worst-case

Error floor improvement over natural binary

Baseline (optimal)

3-4 dB worse at 10⁻⁶ BER

6 dB worse at 10⁻⁶ BER

Decoding dependency

None (independent bits)

Adjacent bit dependency

Full symbol dependency

GRAY CODING IN DIGITAL MODULATION

Frequently Asked Questions

Explore the fundamental principles of Gray coding, a bit-to-symbol mapping scheme that minimizes bit errors in noisy communication channels by ensuring adjacent constellation points differ by only a single bit.

Gray coding is a bit-to-symbol mapping scheme where adjacent constellation points in the IQ plane differ by exactly one bit. Named after Frank Gray, who patented the code in 1953, its core mechanism ensures that when noise causes a symbol error—pushing a received point across a decision boundary into a neighboring Voronoi region—the resulting bit error is minimized to a single flipped bit rather than multiple simultaneous errors. For example, in a standard 16-QAM constellation with natural binary mapping, moving from symbol 0111 to 1000 would flip all four bits. With Gray coding, the same spatial transition might only flip one bit, dramatically reducing the bit error rate (BER) for the same signal-to-noise ratio. This property makes Gray coding the de facto standard in virtually all modern digital communication systems, including LTE, 5G NR, WiFi, and satellite links.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.