Learn / Math / Coding Theory & Reed–Solomon Codes
25. Coding Theory & Reed–Solomon Codes
Coding Theory · Lesson 26 of 26 · 13:00
How the rigidity behind Lagrange interpolation and Schwartz–Zippel becomes a practical tool for surviving lost or corrupted data — the Hamming distance between two words, the Reed–Solomon code that sends many evaluations of one low-degree polynomial, and how that same code underlies soundness checks and data availability in modern proof systems.

The last few lessons showed how rigid polynomials really are: a low-degree one is pinned down by just a few points, and two different ones can only agree in a few places. This lesson puts that rigidity to work on a very practical problem — sending information when some of it gets lost or damaged along the way. This is coding theory, and its star is the Reed–Solomon code: it protects QR codes, CDs, and satellite links, and it sits underneath modern proof systems and blockchain data availability. One notation note carried over from the last lesson: there, dd meant a polynomial’s degree; here, dd means a code’s distance.

Why send extra numbers?

Sending a message plainly leaves no way to tell that anything went wrong. Redundancy — extra numbers computed from the message — is what makes mistakes visible, and distance is what decides how many mistakes survive.

why send extra numbers? How can a message survive when some numbers get changed or lost? PROBLEM   send (3, 5), one number changes to (3, 9) → the receiver can't tell IDEA   add extra numbers computed from the message — this is redundancy HAMMING DISTANCE   the number of positions where two words differ EXAMPLE   (3,8,0,5,10) vs (1,7,0,6,12) differ in 4 places → distance 4 CODE   a chosen set of allowed codewords; the smallest distance between two is d t t d circles of radius t around each codeword must not overlap DETECT   up to d − 1 errors CORRECT   up to t errors when d ≥ 2t + 1 THE FARTHER APART THE CODEWORDS, THE MORE DAMAGE SURVIVES Reed–Solomon codes make d as large as it can possibly be.
Fig. 1 — a message corrupted in transit looks just as valid as the real one; the fix is redundancy, measured by the Hamming distance between words, with circles of radius t around each codeword that must not overlap.
Detecting and correcting errors

d≥2t+1  ⟹  correct up to t errorsd \geq 2t + 1 \implies \text{correct up to } t \text{ errors}

The Hamming distance between two words is the number of positions where they differ. A code’s distance dd is the smallest Hamming distance between any two of its codewords. With distance dd, a receiver can always detect up to d−1d - 1 errors, and correct up to tt errors whenever d≥2t+1d \geq 2t + 1 — picture a circle of radius tt around each codeword; as long as those circles don’t overlap, a corrupted word still lands closest to the codeword it came from.

Reed–Solomon: a message as a line

Reed–Solomon’s trick is to turn the message itself into a low-degree polynomial, then send its value at several agreed points instead of the raw numbers.

Reed–Solomon: a message as a line How do we create extra numbers that are all tied to the message? MESSAGE   (3, 5) → the polynomial f(x) = 3 + 5x EVALUATE   in F(13) at x = 0, 1, 2, 3, 4 f(0)=3, f(1)=8, f(2)=13=0, f(3)=18=5, f(4)=23=10 CODEWORD   (3, 8, 0, 5, 10) SIZES   k = 2 message numbers, n = 5 sent numbers, rate k/n = 2/5 WHY IT WORKS   any 2 points determine a line, so any 2 of the 5 numbers recover the message POINTS OF ONE LOW-DEGREE POLYNOMIAL ARE ALL TIED TOGETHER Reed–Solomon means: send many evaluations of the message polynomial.
Fig. 2 — the message (3, 5) becomes f(x) = 3 + 5x, evaluated at x = 0 through 4 in F(13) to give the codeword (3, 8, 0, 5, 10); any 2 of those 5 numbers are enough to recover the line.
Reed–Solomon encoding

message→f(x),codeword=(f(x1),f(x2),…,f(xn))\text{message} \to f(x), \qquad \text{codeword} = \big(f(x_1), f(x_2), \ldots, f(x_n)\big)

A message of kk numbers becomes a degree-(k−1)(k-1) polynomial, and the codeword is that polynomial’s value at nn agreed points, with n>kn > k. The rate k/nk/n tells you how much of what’s sent actually carries the message — here, 2/52/5. Because any kk points pin down a degree-(k−1)(k-1) polynomial exactly, any kk of the nn transmitted numbers are enough to reconstruct it.

Recovering lost numbers

When some numbers go missing but the receiver knows exactly which positions were lost — an erasure — the surviving points are still enough to rebuild the line.

recovering lost numbers Three of the five numbers are lost. Can we still get the message back? SENT   (3, 8, 0, 5, 10) RECEIVED   (?, 8, ?, 5, ?) — positions known KNOWN POINTS   (1, 8) and (3, 5) SLOPE   (5 − 8) ÷ (3 − 1) = −3 ÷ 2 INVERSE   2−1 = 7 because 2×7 = 14 = 1, so −3×7 = −21 = 5 INTERCEPT   8 = c + 5×1, so c = 3 RESULT   f(x) = 3 + 5x → message (3, 5) ✓ REBUILD   f(0)=3, f(2)=13=0, f(4)=23=10 ✓ ANY 2 SURVIVING NUMBERS REBUILD EVERYTHING An erasure is a lost number at a known place; this code survives n − k = 3 of them.
Fig. 3 — with three of five numbers erased, the two surviving points (1, 8) and (3, 5) are enough to solve for the slope and intercept, recovering f(x) = 3 + 5x and every missing value.
Erasures

survives up to n−k erasures\text{survives up to } n - k \text{ erasures}

An erasure is a lost value at a known position — different from an error, where a value is wrong but its position looks fine. Because kk points determine the message, a Reed–Solomon code with nn total points tolerates losing up to n−kn - k of them and still recovers everything exactly, the same way two points determine a line here.

How far apart are two codewords?

The error-correcting power of this code all traces back to one fact already familiar from Schwartz–Zippel: two different low-degree polynomials can only agree at a handful of points.

how far apart are two codewords? How different are two Reed–Solomon codewords, really? TWO MESSAGES   f(x) = 3 + 5x and g(x) = 1 + 6x CODEWORDS   f → (3,8,0,5,10) and g → (1,7,0,6,12) DIFFERENCE   f − g = 2 − x, which has only one root, x = 2 AGREE   only at x = 2, where both give 0 → they differ in 4 of 5 places RULE   two different polynomials of degree below k agree in at most k − 1 points d = n − k + 1 = 5 − 2 + 1 = 4 ✓ EACH EXTRA EVALUATION ADDS ANOTHER PLACE CODEWORDS DIFFER The same root-counting fact behind the Schwartz–Zippel lemma.
Fig. 4 — two different messages give polynomials that agree at only one of five evaluation points, so their codewords differ in n − k + 1 = 4 of 5 places — the maximum distance any code of this size could have.
Minimum distance

d=n−k+1d = n - k + 1

Two different polynomials of degree below kk can agree in at most k−1k - 1 points — subtract one from the other and the result is a nonzero polynomial of degree below kk, which has at most k−1k - 1 roots. So out of nn evaluation points, at most k−1k - 1 ever agree, meaning at least n−k+1n - k + 1 always differ. Reed–Solomon codes hit this bound exactly, which is why they’re called maximum distance separable.

Finding a corrupted number

Erasures are the easy case, because the receiver knows where to look. A plain error is harder — one value is simply wrong, with no flag attached — but the same distance argument still finds it.

finding a corrupted number One number was changed and we don't know which. Can we still decode? RECEIVED   (3, 8, 0, 9, 10) TRY   the line 3 + 5x matches 4 of 5 numbers, all except x = 3 ANY OTHER CODEWORD   differs from the sent word in ≥ 4 places, so matches received in ≤ 2 decode to 3 + 5x — the error is at x = 3: received 9, correct value 5 ✓ TWO ERRORS   (3,8,0,6,12) is distance 2 from both codewords a tie — we know something's wrong but not which codeword was sent ✗ RULE   correcting t errors needs d ≥ 2t + 1; here d = 4, so t = 1 THE CLOSEST CODEWORD WINS, UNDER HALF THE DISTANCE Real decoders find the winner fast, without trying every line.
Fig. 5 — one wrong value still lets the true line win by a landslide, matching 4 of 5 received numbers against any rival's at most 2; but two errors can tie two different codewords, which is exactly the limit the distance allows.
Nearest-codeword decoding

correct t errors  ⟺  d≥2t+1\text{correct } t \text{ errors} \iff d \geq 2t + 1

Decoding means finding the codeword closest to what was received. Since any two codewords differ in at least dd places, a received word with fewer than d/2d/2 errors is always closer to the true codeword than to any other — that’s exactly the d≥2t+1d \geq 2t + 1 rule from Fig. 1. Push past that limit, as with two errors here, and two codewords can tie, which is why that rule is a hard ceiling, not just a rule of thumb.

Where zero-knowledge uses these codes

Two ideas from earlier lessons meet here: the NTT makes Reed–Solomon encoding fast, and the same distance bound becomes a soundness argument for proof systems and a resilience guarantee for distributed data.

where zero knowledge uses these codes Why do proof systems and blockchains care about error-correcting codes? ENCODE   message (3,5) = polynomial 3+5x, padded with zeros to (3,5,0,0) NTT   evaluate at the roots of unity 1, 5, 12, 8 in F(13) → (8, 2, 11, 4) SIZES   k = 2, n = 4, rate 1/2 → the message is blown up 2× DISTANCE   d = n − k + 1 = 3, so codewords differ in ≥ 3 of 4 places IN PROOFS   a cheating prover's word is far from every codeword; a few checks catch it IN DATA   extend data with Reed–Solomon; any k of the n pieces recover everything CHEATING MEANS BEING FAR FROM EVERY CODEWORD A low-degree polynomial is a codeword — encoded fast with the NTT from Topic 23.
Fig. 6 — padding a message with zeros and running it through the NTT from Topic 23 produces a Reed–Solomon codeword directly; the same codeword-distance idea lets proof systems catch cheating provers with a few spot checks and lets blockchains recover data from any k of n stored pieces.

Encoding a message is padding it to length nn and running the NTT — the same fast transform from Topic 23, repurposed as a Reed–Solomon encoder. In proof systems like STARKs, a cheating prover’s list of values sits far from every valid codeword, so checking a handful of random positions catches it with overwhelming probability. In distributed storage and blockchain data availability, the same code is spread across many nodes, so any kk of the nn stored pieces reconstruct the original data even if the rest disappear.

Key takeaways
  • Redundancy turns a corrupted message into something detectable: the Hamming distance between two words counts the positions where they differ, and a code’s minimum distance dd decides how much damage it survives.
  • Reed–Solomon encodes a kk-number message as a degree-(k−1)(k-1) polynomial and sends its value at nn agreed points; any kk of those points recover the message exactly.
  • The same root-counting fact behind Schwartz–Zippel forces any two different codewords to differ in at least n−k+1n - k + 1 places — the best any code of that size can do.
  • A received word survives up to n−kn - k erasures (lost values at known positions) and up to tt plain errors whenever d≥2t+1d \geq 2t + 1, by always decoding to the nearest codeword.
  • The NTT makes Reed–Solomon encoding fast, and the resulting distance bound underlies both the soundness of spot-checks in proof systems like STARKs and data-availability guarantees in blockchains.