Skip to main content
KetQat

Appearance

Topic · introductory

Classical Error-Correcting Codes

Linear codes as subspaces described by generator and parity-check matrices, their distance and duals, the main families (Hamming, Reed–Muller, Reed–Solomon, BCH, LDPC), and the bounds every code obeys, with an eye to what quantum code constructions take from them.

ExpositionMachine-checkedUpdated 2026-12-01 · last verified 2026-12-01

AI-assisted text, machine-checked, not yet reviewed by a person. Citations resolve and an automated pass compared the statements with the cited sources. That is not peer review; check the sources for anything you depend on.

Overview

A classical error-correcting code adds structured redundancy to data so that a limited number of corrupted symbols can be detected or repaired. Almost all codes used in practice, and all the codes quantum error correction borrows, are linear: the set of codewords is a subspace of Fqn\F_q^n, and membership is tested by a set of linear parity checks. This page collects the definitions, the standard families and the bounds on code parameters. It is written for readers heading towards quantum codes, where a classical code reappears twice: its parity checks become stabilizer generators, and its dual decides whether those generators commute.

The probabilistic side of the subject, channels, capacity and the cost of decoding, is treated in Coding Theory. The field arithmetic behind the algebraic families is in Finite Fields and Coding Algebra.

Intuition

Spread the messages out. If any two codewords differ in at least dd positions, then changing fewer than dd positions of a codeword never produces another codeword, so the change is noticed; and changing fewer than d/2d/2 positions leaves the word closer to the original codeword than to any other, so the change can be undone.

For a linear code this geometry becomes linear algebra. The receiver computes the syndrome of the received word, the vector of parity-check values. The syndrome is zero on codewords, so it depends only on the error, not on the message: it names the coset of the code in which the received word lies. Decoding is the choice of the most plausible error in that coset. Quantum error correction keeps this picture intact. A syndrome that reveals the error and nothing about the encoded data is what allows a quantum state to be corrected without being measured.

Two design philosophies run through the subject. Algebraic codes (Hamming, Reed–Solomon, BCH, Reed–Muller) have checks chosen so that the distance can be proved and decoding done by solving equations. Sparse-graph codes (LDPC) have checks that each touch few bits, chosen so that a simple iterative decoder works well on typical errors, with no attempt to maximise the distance.

Prerequisites

Linear algebra over a field: subspaces, rank, kernels, and the fact that these behave over F2\F_2 as they do over R\R, with the one exception that a nonzero vector can be orthogonal to itself. Reed–Solomon and BCH codes need finite fields beyond F2\F_2. The repetition code lesson is a gentle first example of a code, a syndrome and a decoder.

Mathematical Definitions

DefinitionLinear codeEstablished definition

Let Fq\F_q be the finite field with qq elements. For x,y∈Fqnx, y \in \F_q^n the Hamming weight wt⁡(x)\operatorname{wt}(x) is the number of nonzero coordinates of xx, and the Hamming distance is d(x,y)=wt⁡(x−y)d(x, y) = \operatorname{wt}(x - y), the number of coordinates in which xx and yy differ.

A linear code of length nn and dimension kk over Fq\F_q is a kk-dimensional subspace C⊆FqnC \subseteq \F_q^n. Its elements are codewords, its rate is R=k/nR = k/n, and its minimum distance is

d  =  min⁡c,c′∈Cc≠c′d(c,c′)  =  min⁡c∈C∖{0}wt⁡(c),d \;=\; \min_{\substack{c, c' \in C \\ c \ne c'}} d(c, c') \;=\; \min_{c \in C \setminus \{0\}} \operatorname{wt}(c) ,

the two expressions agreeing because c−c′∈Cc - c' \in C. Such a code is called an [n,k,d]q[n, k, d]_q code; the subscript is dropped when q=2q = 2.

  • A generator matrix is a k×nk \times n matrix GG whose rows form a basis of CC, so that C={ uG:u∈Fqk }C = \{\, uG : u \in \F_q^k \,\}.
  • A parity-check matrix is a matrix HH with nn columns such that C={ c∈Fqn:HcT=0 }C = \{\, c \in \F_q^n : H c^{T} = 0 \,\}. It has rank n−kn - k; it may have more than n−kn - k rows, the extra ones being redundant checks.
  • The syndrome of a word y∈Fqny \in \F_q^n is s(y)=HyTs(y) = H y^{T}. It vanishes exactly on CC and is constant on each coset y+Cy + C.

The two descriptions are related by GHT=0G H^{T} = 0. A code that is not required to be a subspace, with MM codewords and minimum distance dd, is written (n,M,d)q(n, M, d)_q.

DefinitionDual code and self-orthogonalityEstablished definition

Equip Fqn\F_q^n with the bilinear form x⋅y=∑i=1nxiyix \cdot y = \sum_{i=1}^{n} x_i y_i. The dual of a linear code C⊆FqnC \subseteq \F_q^n is

C⊥  =  { x∈Fqn  :  x⋅c=0 for all c∈C }.C^{\perp} \;=\; \{\, x \in \F_q^n \;:\; x \cdot c = 0 \ \text{for all } c \in C \,\} .

If CC has dimension kk then C⊥C^{\perp} is a linear code of dimension n−kn - k, and (C⊥)⊥=C(C^{\perp})^{\perp} = C. A generator matrix of CC is a parity-check matrix of C⊥C^{\perp}, and the other way round.

The form is not positive definite: over F2\F_2, x⋅x=wt⁡(x) mod 2x \cdot x = \operatorname{wt}(x) \bmod 2, so every word of even weight is orthogonal to itself. A code and its dual can therefore intersect, and can even contain one another:

  • CC is self-orthogonal (or weakly self-dual) if C⊆C⊥C \subseteq C^{\perp};
  • CC is dual-containing if C⊥⊆CC^{\perp} \subseteq C;
  • CC is self-dual if C=C⊥C = C^{\perp}, which forces n=2kn = 2k.

CC is dual-containing exactly when C⊥C^{\perp} is self-orthogonal. In terms of a parity-check matrix HH of CC, the code is dual-containing if and only if HHT=0H H^{T} = 0. The relation dim⁡C+dim⁡C⊥=n\dim C + \dim C^{\perp} = n holds in every case, whether or not the two codes intersect.

Families

DefinitionHamming codeEstablished definition

Let r≥2r \ge 2 and n=2r−1n = 2^r - 1. The binary Hamming code of order rr is the linear code ker⁡Hr⊆F2n\ker H_r \subseteq \F_2^n, where HrH_r is an r×nr \times n matrix whose columns are the nn nonzero vectors of F2r\F_2^r, each once. Different orderings of the columns give codes that differ by a permutation of coordinates.

Its parameters are [ 2r−1,  2r−1−r,  3 ][\,2^r - 1,\; 2^r - 1 - r,\; 3\,]. The distance is 3 because the columns of HrH_r are nonzero and distinct, so no two are dependent, while any two columns sum to a third. A single error in position ii has syndrome equal to the ii-th column, which identifies ii. The code meets the Hamming bound with equality and is therefore perfect. It was introduced by Hamming.

For r=3r = 3, with columns in the order of the binary numerals of 1,…,71, \dots, 7,

H3=(000111101100111010101),H_3 = \begin{pmatrix} 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 & 1 & 0 & 1 \end{pmatrix},

a [7,4,3][7, 4, 3] code.

The dual of the Hamming code is the simplex code [ 2r−1,  r,  2r−1 ][\,2^r - 1,\; r,\; 2^{r-1}\,], generated by HrH_r; all its nonzero words have weight 2r−12^{r-1}. For r≥3r \ge 3 the simplex code is contained in the Hamming code, that is, the Hamming code is dual-containing: any two rows of HrH_r, equal or not, have an even number of common ones. Adding an overall parity bit gives the extended Hamming code [ 2r,  2r−1−r,  4 ][\,2^r,\; 2^r - 1 - r,\; 4\,].

DefinitionReed–Muller codeEstablished definition

Let m≥1m \ge 1 and 0≤r≤m0 \le r \le m. A Boolean polynomial in variables v1,…,vmv_1, \dots, v_m is an F2\F_2-linear combination of the monomials ∏i∈Svi\prod_{i \in S} v_i, S⊆{1,…,m}S \subseteq \{1, \dots, m\}; its degree is the largest ∣S∣\abs{S} that occurs. The Reed–Muller code of order rr is

RM(r,m)  =  { (f(v))v∈F2m  :  f a Boolean polynomial, deg⁡f≤r }  ⊆  F2 2m,\mathrm{RM}(r, m) \;=\; \bigl\{\, \bigl(f(v)\bigr)_{v \in \F_2^m} \;:\; f \text{ a Boolean polynomial},\ \deg f \le r \,\bigr\} \;\subseteq\; \F_2^{\,2^m} ,

the set of truth tables of such polynomials, with coordinates indexed by the 2m2^m points of F2m\F_2^m. It is a binary linear code with

n=2m,k=∑i=0r(mi),d=2 m−r.n = 2^m, \qquad k = \sum_{i=0}^{r} \binom{m}{i}, \qquad d = 2^{\,m-r} .

The codes are nested, RM(r,m)⊆RM(r+1,m)\mathrm{RM}(r, m) \subseteq \mathrm{RM}(r+1, m), and for 0≤r≤m−10 \le r \le m - 1 the dual is

RM(r,m)⊥  =  RM(m−r−1, m).\mathrm{RM}(r, m)^{\perp} \;=\; \mathrm{RM}(m - r - 1,\, m) .

Special cases: RM(0,m)\mathrm{RM}(0, m) is the repetition code, RM(m−1,m)\mathrm{RM}(m - 1, m) the even-weight code, RM(m,m)\mathrm{RM}(m, m) the whole space, and RM(m−2,m)\mathrm{RM}(m - 2, m) the extended Hamming code [2m,2m−m−1,4][2^m, 2^m - m - 1, 4]. The code RM(1,3)\mathrm{RM}(1, 3) is the self-dual [8,4,4][8, 4, 4] code.

The codes were introduced by Muller, with a decoding procedure by Reed; proofs of the parameters and of the duality are in Huffman and Pless. The nesting and duality relations make them a standard source of classical codes for CSS constructions, and the divisibility of their codeword weights by powers of two is what lies behind transversal non-Clifford gates in codes built from them (see logical gates).

DefinitionReed–Solomon codeEstablished definition

Let Fq\F_q be a finite field, let α1,…,αn∈Fq\alpha_1, \dots, \alpha_n \in \F_q be distinct (so n≤qn \le q) and let 1≤k≤n1 \le k \le n. The Reed–Solomon code with these evaluation points and dimension kk is

RSk  =  { (f(α1),…,f(αn))  :  f∈Fq[x], deg⁡f<k }  ⊆  Fqn.\mathrm{RS}_k \;=\; \bigl\{\, \bigl(f(\alpha_1), \dots, f(\alpha_n)\bigr) \;:\; f \in \F_q[x],\ \deg f < k \,\bigr\} \;\subseteq\; \F_q^n .

It is a linear code with parameters [ n,  k,  n−k+1 ]q[\,n,\; k,\; n - k + 1\,]_q. A nonzero polynomial of degree less than kk has at most k−1k - 1 roots, so the evaluation map is injective (the dimension is kk) and every nonzero codeword has at least n−(k−1)n - (k - 1) nonzero coordinates; the Singleton bound shows the distance is no larger. The code is therefore maximum distance separable. The construction is due to Reed and Solomon.

Two special cases are common.

  • All field elements, n=qn = q. Then the dual is again a Reed–Solomon code on the same points, RSk⊥=RS q−k\mathrm{RS}_k^{\perp} = \mathrm{RS}_{\,q-k}, because ∑a∈Fqaj=0\sum_{a \in \F_q} a^{j} = 0 for 0≤j≤q−20 \le j \le q - 2.
  • All nonzero elements, n=q−1n = q - 1, ordered as powers 1,β,…,βn−11, \beta, \dots, \beta^{n-1} of a primitive element β\beta. The code is then cyclic, and is the BCH code over Fq\F_q whose defining roots are β,β2,…,βn−k\beta, \beta^2, \dots, \beta^{n-k}.

The length is limited by the field size. Long binary codes are obtained from Reed–Solomon codes over F2m\F_{2^m} by writing each symbol as mm bits, at the price of a guarantee on symbol errors rather than bit errors.

DefinitionBCH codeEstablished definition

Let qq be a prime power and nn a positive integer coprime to qq. Let mm be the multiplicative order of qq modulo nn, so that Fqm\F_{q^m} contains a primitive nn-th root of unity α\alpha. Fix integers b≥0b \ge 0 and 2≤δ≤n2 \le \delta \le n.

The BCH code over Fq\F_q of length nn and designed distance δ\delta is the cyclic code

C  =  { c(x)∈Fq[x]/(xn−1)  :  c(αb)=c(αb+1)=⋯=c(αb+δ−2)=0 }.C \;=\; \bigl\{\, c(x) \in \F_q[x]/(x^n - 1) \;:\; c(\alpha^{b}) = c(\alpha^{b+1}) = \dots = c(\alpha^{b+\delta-2}) = 0 \,\bigr\} .

Its generator polynomial is the least common multiple of the minimal polynomials over Fq\F_q of αb,…,αb+δ−2\alpha^{b}, \dots, \alpha^{b+\delta-2}. The code is narrow-sense if b=1b = 1 and primitive if n=qm−1n = q^m - 1.

By the BCH bound the minimum distance is at least δ\delta; it can be larger. Each minimal polynomial has degree at most mm, so the dimension is at least n−m(δ−1)n - m(\delta - 1). For binary narrow-sense codes α2j\alpha^{2j} is a root whenever αj\alpha^{j} is, which improves this to k≥n−m tk \ge n - m\,t for designed distance δ=2t+1\delta = 2t + 1.

Examples: the binary primitive narrow-sense BCH code with δ=3\delta = 3 is the Hamming code of length 2m−12^m - 1; with n=15n = 15 and δ=5\delta = 5 one obtains a [15,7,5][15, 7, 5] code. For m=1m = 1, n=q−1n = q - 1, the minimal polynomials are linear and the BCH codes are the cyclic Reed–Solomon codes.

The binary codes were found by Bose and Ray-Chaudhuri and, independently, by Hocquenghem; see Huffman and Pless for the general theory and for algebraic decoding.

DefinitionLDPC code and Tanner graphEstablished definition

Let HH be an m×nm \times n parity-check matrix of a binary linear code. Its Tanner graph is the bipartite graph with variable nodes 1,…,n1, \dots, n (the columns, one per code bit), check nodes 1,…,m1, \dots, m (the rows), and an edge between check jj and variable ii exactly when Hji=1H_{ji} = 1. A word is a codeword if and only if, at every check node, the bits on the neighbouring variable nodes sum to zero.

A family of codes with parity-check matrices H(n)H^{(n)} of growing length nn is a low-density parity-check (LDPC) family if there is a constant ww, independent of nn, such that every row and every column of every H(n)H^{(n)} has at most ww ones; equivalently, the Tanner graphs have bounded degree. The family is (dv,dc)(d_v, d_c)-regular if every variable node has degree dvd_v and every check node degree dcd_c. Counting edges gives n dv=m dcn\, d_v = m\, d_c, so the rate is at least the design rate 1−dv/dc1 - d_v/d_c, with equality when the rows of HH are independent.

Sparsity is a property of the matrix HH, not of the code: the same code has many parity-check matrices, most of them dense, and the performance of iterative decoders depends on which one is used. "LDPC" is meaningful only for a family, since any single matrix has bounded weights.

LDPC codes were introduced by Gallager together with iterative decoding; the graph description is due to Tanner. A modern account is Richardson and Urbanke. The quantum counterpart, where two sparse check matrices must also be orthogonal, is the subject of quantum LDPC codes.

BCH codes are cyclic codes: codes invariant under a cyclic shift of the coordinates, which are the ideals of a polynomial ring and are described on the finite-fields page.

Theorems

TheoremMinimum distance and the errors a linear code handlesEstablished result

Let CC be an [n,k,d]q[n, k, d]_q linear code with parity-check matrix HH.

  1. Syndromes label cosets. For a codeword cc and an error ee, s(c+e)=s(e)s(c + e) = s(e). Two errors e,e′e, e' have the same syndrome if and only if e−e′∈Ce - e' \in C.
  2. Distance from the check matrix. dd is the smallest number of columns of HH that are linearly dependent.
  3. Detection. Every nonzero error of weight at most d−1d - 1 has a nonzero syndrome, and some error of weight dd has syndrome zero.
  4. Correction. The errors of weight at most tt have pairwise distinct syndromes, and so can all be corrected, if and only if 2t≤d−12t \le d - 1.
  5. Erasures. If at most d−1d - 1 coordinates of a codeword are erased, the codeword is determined by the remaining coordinates; some set of dd erased coordinates does not have this property.
Holds when
  • C⊆FqnC \subseteq \F_q^n is a linear code with parity-check matrix HH and minimum distance dd.
  • Errors are additive, y=c+ey = c + e, and an erasure is the loss of a coordinate whose position is known.
Proof · Proof that the minimum distance governs detection, correction and erasure recovery

1. The map s(y)=HyTs(y) = H y^{T} is linear with kernel CC. Hence s(c+e)=s(c)+s(e)=s(e)s(c + e) = s(c) + s(e) = s(e), and s(e)=s(e′)s(e) = s(e') if and only if s(e−e′)=0s(e - e') = 0, that is, e−e′∈Ce - e' \in C.

2. Write h1,…,hnh_1, \dots, h_n for the columns of HH. A word cc lies in CC exactly when ∑icihi=0\sum_i c_i h_i = 0, which is a linear dependence among the columns indexed by the support of cc. A nonzero codeword of weight ww therefore exhibits ww dependent columns, and a dependence among ww columns with all coefficients nonzero is a codeword of weight ww. The smallest such ww is on one side the minimum weight dd and on the other the smallest number of dependent columns.

3. An error e≠0e \neq 0 has s(e)=0s(e) = 0 if and only if e∈Ce \in C, and nonzero codewords have weight at least dd, with equality for some codeword.

4. Suppose 2t≤d−12t \le d - 1 and let e≠e′e \ne e' have weight at most tt. Then 0<wt⁡(e−e′)≤2t<d0 < \operatorname{wt}(e - e') \le 2t < d, so e−e′∉Ce - e' \notin C and by item 1 the syndromes differ. A decoder that maps each syndrome to the unique error of weight at most tt producing it, and subtracts that error, recovers cc. Conversely, if 2t≥d2t \ge d, take a codeword cc of weight dd and split its support into a set of size ⌈d/2⌉\lceil d/2 \rceil and a set of size ⌊d/2⌋\lfloor d/2 \rfloor, both at most tt. Let ee agree with cc on the first set and vanish elsewhere, and put e′=e−ce' = e - c. Both have weight at most tt, they are distinct, and e−e′=c∈Ce - e' = c \in C, so they share a syndrome and cannot both be corrected.

5. Let EE be the set of erased positions, ∣E∣≤d−1\abs{E} \le d - 1. If two codewords c,c′c, c' agree outside EE, then c−c′c - c' is a codeword supported inside EE, of weight at most d−1d - 1, hence zero. So the unerased coordinates determine the codeword. If EE is the support of a codeword cc of weight dd, then 00 and cc agree outside EE and cannot be told apart.

The remaining results constrain which triples [n,k,d][n, k, d] are possible. Two are upper bounds on the size of a code and one is a guarantee that good codes exist.

EquationSingleton boundEstablished result
d  ≤  n−k+1d \;\le\; n - k + 1

Equivalently ∣C∣≤q n−d+1\abs{C} \le q^{\,n - d + 1}. The bound is named after Singleton. A code attaining it is maximum distance separable (MDS): any kk coordinates of a codeword determine the rest. Reed–Solomon codes are MDS for every admissible length and dimension. Over F2\F_2 the only MDS codes are the trivial ones: the repetition codes [n,1,n][n, 1, n], the single-parity-check codes [n,n−1,2][n, n - 1, 2] and the full space [n,n,1][n, n, 1].

The bound does not depend on the alphabet size, which makes it weak for small qq and long codes; there the Hamming bound is stronger. Its quantum counterpart, the quantum Singleton bound, reads n−k≥2(d−1)n - k \ge 2(d - 1), with twice the redundancy.

Holds when
  • Any code C⊆AnC \subseteq A^n over an alphabet AA of size qq with minimum distance dd; linearity is not needed. Here k=log⁡q∣C∣k = \log_q \abs{C}, which is the dimension when CC is linear.
Proof · Proof of the Singleton bound

Let C⊆AnC \subseteq A^n have minimum distance dd, with ∣A∣=q\abs{A} = q. Delete the last d−1d - 1 coordinates of every codeword; this defines a map π:C→A n−d+1\pi : C \to A^{\,n - d + 1}. If π(c)=π(c′)\pi(c) = \pi(c') then cc and c′c' can differ only in the deleted coordinates, so d(c,c′)≤d−1d(c, c') \le d - 1, which forces c=c′c = c'. Thus π\pi is injective and

∣C∣  ≤  ∣A n−d+1∣  =  q n−d+1.\abs{C} \;\le\; \abs{A^{\,n-d+1}} \;=\; q^{\,n - d + 1} .

With ∣C∣=qk\abs{C} = q^k this is k≤n−d+1k \le n - d + 1.

The same argument applied to any d−1d - 1 coordinates shows that in a code meeting the bound the projection onto every set of n−d+1=kn - d + 1 = k coordinates is a bijection, which is the "separable" property of MDS codes.

EquationHamming boundEstablished result
∣C∣ ∑i=0t(ni) (q−1)i  ≤  q n,t=⌊d−12⌋\lvert C\rvert \,\sum_{i=0}^{t} \binom{n}{i}\,(q-1)^{i} \;\le\; q^{\,n}, \qquad t = \left\lfloor \tfrac{d-1}{2} \right\rfloor

The sum counts the words within Hamming distance tt of a fixed word. For a binary linear code the bound reads ∑i=0t(ni)≤2 n−k\sum_{i=0}^{t} \binom{n}{i} \le 2^{\,n-k}: there must be at least as many syndromes as errors to be told apart. It goes back to Hamming.

A code meeting the bound with equality is perfect: every word lies within distance tt of exactly one codeword. The Hamming codes are perfect with t=1t = 1, since 2 2r−1−r (1+(2r−1))=2 2r−12^{\,2^r - 1 - r}\,(1 + (2^r - 1)) = 2^{\,2^r - 1}.

Unlike its quantum analogue, the quantum Hamming bound, which in general is proved only for non-degenerate codes, this bound holds for every classical code.

Holds when
  • Any code C⊆AnC \subseteq A^n over an alphabet of size qq with minimum distance dd; linearity is not needed. For a linear [n,k,d]q[n, k, d]_q code, ∣C∣=qk\abs{C} = q^k.
Proof · Proof of the Hamming bound

For c∈Anc \in A^n let Bt(c)={ y∈An:d(y,c)≤t }B_t(c) = \{\, y \in A^n : d(y, c) \le t \,\}. A word at distance exactly ii from cc is obtained by choosing ii positions and, in each, one of the q−1q - 1 other symbols, so

∣Bt(c)∣  =  ∑i=0t(ni) (q−1)i.\abs{B_t(c)} \;=\; \sum_{i=0}^{t} \binom{n}{i}\,(q-1)^{i} .

Let c≠c′c \ne c' be codewords and suppose y∈Bt(c)∩Bt(c′)y \in B_t(c) \cap B_t(c'). The Hamming distance is a metric, so d(c,c′)≤d(c,y)+d(y,c′)≤2t≤d−1d(c, c') \le d(c, y) + d(y, c') \le 2t \le d - 1, contradicting the minimum distance. The balls around the ∣C∣\abs{C} codewords are therefore pairwise disjoint subsets of AnA^n, and

∣C∣⋅∑i=0t(ni) (q−1)i  ≤  q n.\abs{C} \cdot \sum_{i=0}^{t} \binom{n}{i}\,(q-1)^{i} \;\le\; q^{\,n} .

Equality holds exactly when the balls cover AnA^n.

EquationGilbert–Varshamov boundEstablished result
∑i=0d−2(n−1i) (q−1)i  <  q n−k    ⟹    an [n, ≥k, ≥d]q linear code exists\sum_{i=0}^{d-2} \binom{n-1}{i}\,(q-1)^{i} \;<\; q^{\,n-k} \;\;\Longrightarrow\;\; \text{an } [n,\, \ge k,\, \ge d]_q \text{ linear code exists}

The displayed form, for linear codes, is the refinement due to Varshamov of the counting argument of Gilbert; Gilbert's own version states that a code with at least qn/∑i=0d−1(ni)(q−1)iq^n / \sum_{i=0}^{d-1} \binom{n}{i} (q-1)^i codewords and distance dd exists. Both are treated in Huffman and Pless.

Asymptotic form. Let h(x)=−xlog⁡2x−(1−x)log⁡2(1−x)h(x) = -x \log_2 x - (1-x) \log_2 (1-x) be the binary entropy. For every 0≤δ<1/20 \le \delta < 1/2 and every ϵ>0\epsilon > 0 there are binary linear codes of arbitrarily large length with relative distance d/n≥δd/n \ge \delta and rate

R  ≥  1−h(δ)−ϵ.R \;\ge\; 1 - h(\delta) - \epsilon .

This follows from the finite bound and the estimate ∑i≤δn(ni)≤2 nh(δ)\sum_{i \le \delta n} \binom{n}{i} \le 2^{\,n h(\delta)} for δ≤1/2\delta \le 1/2.

Example. For n=15n = 15, d=5d = 5, q=2q = 2 the left side is 1+14+91+364=470<291 + 14 + 91 + 364 = 470 < 2^{9}, so a binary [15,6][15, 6] code with distance at least 5 exists. The bound is not tight here: the binary BCH code of length 15 and designed distance 5 has dimension 7.

The same counting idea, applied to isotropic subspaces instead of parity-check columns, gives the quantum Gilbert–Varshamov bound.

Holds when
  • qq is a prime power, n≥2n \ge 2, 1≤k≤n−11 \le k \le n - 1 and d≥2d \ge 2.
  • This is a sufficient condition for existence; codes with better parameters than it guarantees do exist.
Proof · Proof of the Gilbert–Varshamov bound for linear codes

Put r=n−kr = n - k. We construct column vectors h1,…,hn∈Fq rh_1, \dots, h_n \in \F_q^{\,r} such that every d−1d - 1 of them are linearly independent.

Take h1≠0h_1 \neq 0. Suppose h1,…,hjh_1, \dots, h_j have been chosen, 1≤j≤n−11 \le j \le n - 1, with every d−1d - 1 of them linearly independent. A vector vv is a forbidden choice for hj+1h_{j+1} if it is a linear combination of at most d−2d - 2 of the chosen columns, since exactly then vv together with those columns would form a dependent set of at most d−1d - 1 columns. The number of linear combinations of exactly ii columns with nonzero coefficients is at most (ji)(q−1)i\binom{j}{i} (q-1)^i, so the number of forbidden vectors, including 00, is at most

∑i=0d−2(ji) (q−1)i  ≤  ∑i=0d−2(n−1i) (q−1)i  <  q r.\sum_{i=0}^{d-2} \binom{j}{i}\,(q-1)^{i} \;\le\; \sum_{i=0}^{d-2} \binom{n-1}{i}\,(q-1)^{i} \;<\; q^{\,r} .

Hence some vector of Fq r\F_q^{\,r} is not forbidden; choose it as hj+1h_{j+1}. Every d−1d - 1 of h1,…,hj+1h_1, \dots, h_{j+1} are then linearly independent: a dependent set not containing hj+1h_{j+1} is excluded by the induction hypothesis, and one containing it would express hj+1h_{j+1}, or a dependence among earlier columns, through at most d−2d - 2 earlier columns.

After nn steps let HH be the r×nr \times n matrix with columns h1,…,hnh_1, \dots, h_n and C=ker⁡HC = \ker H. No d−1d - 1 columns of HH are dependent, so by the characterisation of the minimum distance CC has distance at least dd. Its dimension is n−rank⁡H≥n−r=kn - \operatorname{rank} H \ge n - r = k.

Between the Gilbert–Varshamov guarantee and the upper bounds lies a gap. For binary codes of relative distance δ\delta the achievable rate is at least 1−h(δ)1 - h(\delta), and at most 1−h(δ/2)1 - h(\delta/2) by the Hamming bound; sharper upper bounds are known, but the exact trade-off between rate and relative distance for long binary codes is not.

EquationMacWilliams identityEstablished result
WC⊥(x,y)  =  1∣C∣  WC(x+(q−1) y,  x−y)W_{C^{\perp}}(x, y) \;=\; \frac{1}{\lvert C\rvert}\; W_{C}\bigl(x + (q-1)\,y,\; x - y\bigr)

The identity is due to MacWilliams. For binary codes it reads WC⊥(x,y)=∣C∣−1 WC(x+y, x−y)W_{C^{\perp}}(x, y) = \abs{C}^{-1}\, W_C(x + y,\, x - y).

Example. The [7,4,3][7, 4, 3] Hamming code has WC=x7+7x4y3+7x3y4+y7W_C = x^7 + 7x^4y^3 + 7x^3y^4 + y^7. Substituting,

116[(x+y)7+7(x+y)4(x−y)3+7(x+y)3(x−y)4+(x−y)7]  =  x7+7x3y4,\tfrac{1}{16}\Bigl[(x+y)^7 + 7(x+y)^4(x-y)^3 + 7(x+y)^3(x-y)^4 + (x-y)^7\Bigr] \;=\; x^7 + 7x^3y^4 ,

the weight enumerator of the [7,3,4][7, 3, 4] simplex code: its seven nonzero words all have weight 4.

Uses. Because the coefficients of WC⊥W_{C^\perp} are counts, they are nonnegative; imposing this on a hypothetical weight distribution gives linear constraints that rule out codes, the basis of linear-programming bounds. Inequivalent codes can share a weight enumerator, so the identity relates weight distributions, not codes. Shor and Laflamme found an analogous pair of enumerators and identity for quantum codes.

Holds when
  • C⊆FqnC \subseteq \F_q^n is a linear code and C⊥C^{\perp} its dual for the form x⋅y=∑ixiyix \cdot y = \sum_i x_i y_i.
  • WC(x,y)=∑c∈Cx n−wt⁡(c) ywt⁡(c)=∑w=0nAw x n−wywW_C(x, y) = \sum_{c \in C} x^{\,n - \operatorname{wt}(c)}\, y^{\operatorname{wt}(c)} = \sum_{w=0}^{n} A_w\, x^{\,n-w} y^{w}, where AwA_w is the number of codewords of weight ww.
Proof · Proof of the MacWilliams identity for binary codes

Let C⊆F2nC \subseteq \F_2^n be linear.

Step 1: a sum over CC of signs. For u∈F2nu \in \F_2^n,

∑c∈C(−1)u⋅c  =  {∣C∣u∈C⊥,0u∉C⊥.\sum_{c \in C} (-1)^{u \cdot c} \;=\; \begin{cases} \abs{C} & u \in C^{\perp}, \\ 0 & u \notin C^{\perp}. \end{cases}

If u∈C⊥u \in C^\perp every term is 11. Otherwise pick c0∈Cc_0 \in C with u⋅c0=1u \cdot c_0 = 1; the substitution c↦c+c0c \mapsto c + c_0 permutes CC and multiplies the sum by −1-1, so the sum is zero.

Step 2: transform of the weight function. Fix numbers x,yx, y and let f(u)=x n−wt⁡(u) ywt⁡(u)=∏i=1nf1(ui)f(u) = x^{\,n - \operatorname{wt}(u)}\, y^{\operatorname{wt}(u)} = \prod_{i=1}^n f_1(u_i) with f1(0)=xf_1(0) = x, f1(1)=yf_1(1) = y. For v∈F2nv \in \F_2^n define f^(v)=∑u∈F2n(−1)u⋅vf(u)\hat f(v) = \sum_{u \in \F_2^n} (-1)^{u \cdot v} f(u). The sum factorises over coordinates:

f^(v)  =  ∏i=1n(x+(−1)vi y)  =  (x+y) n−wt⁡(v) (x−y)wt⁡(v).\hat f(v) \;=\; \prod_{i=1}^{n} \Bigl( x + (-1)^{v_i}\, y \Bigr) \;=\; (x + y)^{\,n - \operatorname{wt}(v)}\,(x - y)^{\operatorname{wt}(v)} .

Step 3: combine. Summing f^\hat f over the code and exchanging the order of summation,

∑c∈Cf^(c)  =  ∑u∈F2nf(u)∑c∈C(−1)u⋅c  =  ∣C∣∑u∈C⊥f(u),\sum_{c \in C} \hat f(c) \;=\; \sum_{u \in \F_2^n} f(u) \sum_{c \in C} (-1)^{u \cdot c} \;=\; \abs{C} \sum_{u \in C^{\perp}} f(u) ,

by Step 1. The left side is WC(x+y, x−y)W_C(x + y,\, x - y) by Step 2 and the right side is ∣C∣ WC⊥(x,y)\abs{C}\, W_{C^{\perp}}(x, y). Since this holds for all numbers x,yx, y, it is an identity of polynomials.

Worked Examples

The [7, 4, 3] Hamming code

Take the parity-check matrix H3H_3 displayed in the definition of the Hamming code. Its columns are the binary numerals of 1,…,71, \dots, 7.

A codeword. c=1110000c = 1110000 satisfies all three checks: the first row of H3H_3 has zeros in positions 1 to 3, the second gives c2+c3=0c_2 + c_3 = 0 and the third c1+c3=0c_1 + c_3 = 0.

Decoding. Suppose y=1110010y = 1110010 is received. Its syndrome is

H3 yT=(y4+y5+y6+y7y2+y3+y6+y7y1+y3+y5+y7)=(110),H_3\, y^{T} = \begin{pmatrix} y_4 + y_5 + y_6 + y_7 \\ y_2 + y_3 + y_6 + y_7 \\ y_1 + y_3 + y_5 + y_7 \end{pmatrix} = \begin{pmatrix} 1 \\ 1 \\ 0 \end{pmatrix} ,

the binary numeral of 6. The only single-bit error with this syndrome is a flip of bit 6, and flipping it back returns cc. The eight syndromes correspond to "no error" and the seven single-bit errors, which is the statement that the code is perfect: 24(1+7)=272^4 (1 + 7) = 2^7.

Two errors are miscorrected. If bits 6 and 7 are both flipped the syndrome is 110+111=001110 + 111 = 001, the decoder flips bit 1, and the result is a codeword at distance 3 from cc. A distance-3 code used for correction cannot also detect double errors.

The dual and the weight enumerators. The rows of H3H_3 generate the [7,3,4][7, 3, 4] simplex code. Each row has weight 4 and any two rows share two ones, so H3H3T=0H_3 H_3^{T} = 0: the simplex code lies inside the Hamming code. Listing the 16 codewords of the Hamming code gives one of weight 0, seven of weight 3, seven of weight 4 and one of weight 7; the MacWilliams identity turns this distribution into "one word of weight 0, seven of weight 4" for the dual, as computed in the record above.

Why this matters for quantum codes. The containment C⊥⊆CC^{\perp} \subseteq C is exactly the hypothesis of the CSS construction with the same code used for bit flips and phase flips; applied to this code it yields the Steane code.

Checking the bounds on small parameters

For a binary code with n=7n = 7 and d=3d = 3: the Singleton bound gives k≤5k \le 5, the Hamming bound gives 2k≤27/82^k \le 2^7/8, so k≤4k \le 4, and the Gilbert–Varshamov condition (60)+(61)=7<27−k\binom{6}{0} + \binom{6}{1} = 7 < 2^{7-k} holds for k≤4k \le 4. Here all three agree with the truth, k=4k = 4. For n=15n = 15, d=5d = 5 the Gilbert–Varshamov bound guarantees k=6k = 6 while the BCH code achieves k=7k = 7 and the Hamming bound allows k≤8k \le 8, since 1+15+105=121≤215−k1 + 15 + 105 = 121 \le 2^{15-k} requires k≤8k \le 8.

Algorithms and Implementations

Syndrome decoding. For short codes, store for each syndrome a lowest-weight error producing it (a coset leader) and subtract it. The table has q n−kq^{\,n-k} entries, which limits the method to small redundancy.

Algebraic decoding. Reed–Solomon and BCH codes can be decoded up to half their designed distance in time polynomial in nn by solving a system of equations for the error positions; see Huffman and Pless.

Iterative decoding on the Tanner graph. For an LDPC code the decoder passes messages along the edges of the Tanner graph. On an erasure channel the rule is simple: a check all of whose neighbours but one are known determines the missing one; repeat until no such check remains. This succeeds unless the erased positions contain a nonempty set of variable nodes such that every check adjacent to the set has at least two neighbours in it (a stopping set), which is a property of the matrix HH and not only of the code. For channels with bit flips the messages are probabilities, updated by belief propagation; the computation is exact when the graph is a tree and a heuristic when it has cycles. Gallager introduced both the codes and the decoders, and Richardson and Urbanke give the modern analysis. The cost per iteration is proportional to the number of edges, hence linear in nn for an LDPC family.

Applications

  • CSS codes. Two classical codes with C2⊆C1C_2 \subseteq C_1 give a quantum code whose parameters are read off from theirs (Calderbank and Shor, Steane); see CSS codes.
  • Stabilizer codes. A general stabilizer code is a classical additive code over F4\F_4 that is self-orthogonal for a suitable inner product.
  • Quantum LDPC codes. Sparse classical parity-check matrices are the raw material of product constructions; see quantum LDPC codes.
  • Decoders. Belief propagation and its variants are reused, with modifications, for quantum codes; see quantum decoders.

Computational Complexity

Encoding a linear code is a matrix multiplication. Decoding an arbitrary linear code to the nearest codeword, and even computing its minimum distance, are NP-hard; the precise statements are on the Coding Theory page. Every practical family obtains efficient decoding from structure: algebraic structure for Reed–Solomon and BCH codes, sparsity for LDPC codes.

Limitations and Common Pitfalls

  • Distance is a worst-case figure. Minimum distance guarantees correction of every pattern of up to ⌊(d−1)/2⌋\lfloor (d-1)/2 \rfloor errors. On a random-error channel what matters is the probability of the patterns the decoder fails on, and codes of modest distance with good iterative decoders can outperform codes of large distance decoded only up to half the distance.
  • A code has many parity-check matrices. The distance and the dual depend only on the code; the Tanner graph, the behaviour of iterative decoding and, for the quantum codes built from it, the weights of the stabilizer generators depend on the chosen matrix.
  • Self-orthogonal does not mean zero. Over F2\F_2 a nonzero code can lie inside its own dual. Intuition from real inner-product spaces, where C∩C⊥={0}C \cap C^{\perp} = \{0\}, fails; only dim⁡C+dim⁡C⊥=n\dim C + \dim C^{\perp} = n survives.
  • Erasures and errors are different budgets. A distance-dd code repairs d−1d - 1 erasures but only ⌊(d−1)/2⌋\lfloor (d-1)/2 \rfloor errors at unknown positions. Quoting "corrects d−1d - 1" without saying which is a common slip.
  • Bounds are not constructions. The Gilbert–Varshamov bound asserts that good codes exist and says nothing about decoding them; codes meeting it are not automatically usable.
  • The Singleton bound ignores the alphabet. It is attained only when the alphabet is large enough; for binary codes it is far from the truth.
Mentioned in

Open in the knowledge graph

Contributions about this record

Nobody has published a contribution about it yet.

Publish a result, reproduction or commentPropose a correction to this page

References

  1. R. W. Hamming (1950). Error Detecting and Error Correcting Codes. Bell System Technical Journal 29 (2), 147-160. doi:10.1002/j.1538-7305.1950.tb00463.x
  2. W. Cary Huffman, Vera Pless (2003). Fundamentals of Error-Correcting Codes. Cambridge University Press. doi:10.1017/CBO9780511807077
  3. R. Singleton (1964). Maximum distance q-nary codes. IEEE Transactions on Information Theory 10 (2), 116-118. doi:10.1109/TIT.1964.1053661
  4. E. N. Gilbert (1952). A Comparison of Signalling Alphabets. Bell System Technical Journal 31 (3), 504-522. doi:10.1002/j.1538-7305.1952.tb01393.x
  5. Jessie MacWilliams (1963). A Theorem on the Distribution of Weights in a Systematic Code. Bell System Technical Journal 42 (1), 79-94. doi:10.1002/j.1538-7305.1963.tb04003.x
  6. R. Gallager (1962). Low-density parity-check codes. IRE Transactions on Information Theory 8 (1), 21-28. doi:10.1109/TIT.1962.1057683
  7. R. Tanner (1981). A recursive approach to low complexity codes. IEEE Transactions on Information Theory 27 (5), 533-547. doi:10.1109/TIT.1981.1056404
  8. Tom Richardson, Rüdiger Urbanke (2008). Modern Coding Theory. Cambridge University Press. doi:10.1017/CBO9780511791338
  9. I. S. Reed, G. Solomon (1960). Polynomial Codes Over Certain Finite Fields. Journal of the Society for Industrial and Applied Mathematics 8 (2), 300-304. doi:10.1137/0108018
  10. D. E. Muller (1954). Application of Boolean algebra to switching circuit design and to error detection. Transactions of the I.R.E. Professional Group on Electronic Computers EC-3 (3), 6-12. doi:10.1109/IREPGELC.1954.6499441
  11. I. Reed (1954). A class of multiple-error-correcting codes and the decoding scheme. Transactions of the IRE Professional Group on Information Theory 4 (4), 38-49. doi:10.1109/TIT.1954.1057465
  12. R. C. Bose, D. K. Ray-Chaudhuri (1960). On a class of error correcting binary group codes. Information and Control 3 (1), 68-79. doi:10.1016/S0019-9958(60)90287-4
  13. A. R. Calderbank, Peter W. Shor (1996). Good quantum error-correcting codes exist. Physical Review A 54, 1098-1105. doi:10.1103/PhysRevA.54.1098
  14. Andrew Steane (1996). Multiple Particle Interference and Quantum Error Correction. Proceedings of the Royal Society A 452, 2551. doi:10.1098/rspa.1996.0136arXiv:quant-ph/9601029
  15. Peter Shor, Raymond Laflamme (1997). Quantum Analog of the MacWilliams Identities for Classical Coding Theory. Physical Review Letters 78, 1600-1602. doi:10.1103/PhysRevLett.78.1600arXiv:quant-ph/9610040

Contributors

  • KetQat maintainers · @ketqatConceptualization; Supervision (CRediT roles)
  • Claude (AI drafting assistant)Writing, original draft (CRediT roles)

Review history

  1. Automated source check · Pass with notes · 2026-12-01 · Independent automated verification pass (AI, not the drafting session)

    Topic's own text checked (embedded records carry their own review states): the [7,4,3] worked example (codeword 1110000, syndrome 110 for y = 1110010, double-error miscorrection to a codeword at distance 3, H_3 H_3^T = 0, weight distribution 1/7/7/1), the small-parameter bound comparisons (n = 7, d = 3: Singleton k <= 5, Hamming k <= 4, GV holds for k <= 4; n = 15, d = 5: GV k = 6, BCH k = 7, Hamming k <= 8 from 121 <= 2^(15-k)) recomputed by hand and against the enumerations made for the embedded records; asymptotic GV/Hamming rates and the remaining prose compared with Guruswami-Rudra-Sudan, Essential Coding Theory (open draft), Ch. 4 and Def. 11.4.1; reference metadata compared with Crossref.

    The peeling-decoder failure condition said every neighbouring check has at least two neighbours, which omits 'in the set'; corrected to the stopping-set condition (every check adjacent to the set has at least two neighbours in it).

Revision history

  1. 2026-12-01Content release 2.1.0: 35 more topics, an independent source check of every record, intake hardening (#17)80537b7e
  2. 2026-11-30KetQat Commons: free learning paths, knowledge records, research problems, literature intake (#14)571c9b10

Current revision b1a66a9935169c8c. Source file knowledge/records/topic/classical-error-correcting-codes.md in the content repository (readable there once it is public).