What is a BCH code? TL;DR
BCH codes are cyclic error-correcting codes that recover a message after up to t bit errors per codeword. BCH stands for Bose–Chaudhuri–Hocquenghem. With binary BCH(n,k), n is the transmitted block length, k is the number of data bits, and n − k bits provide redundancy. This tool offers t = 1, 2 or 3. Error correction helps recover damaged data; it does not encrypt it.
The generator combines minimal polynomials with consecutive roots in a finite field, giving a designed distance of 2t + 1. See MathWorks’ BCH construction and primitive-polynomial table.
Encode text, then correct damaged bits
- Choose a code. BCH(7,4) is the default: four data bits become seven transmitted bits and t = 1.
- Enter text or binary bits. Each displayed output group is one complete codeword. Text is encoded as UTF-8; save the displayed trailing-zero padding count with the output.
- Open Inject errors and click bit positions, or enter N and a seed. The helper compares the decoder’s candidate with the known original.
- Select Decode damaged codewords, or paste complete codewords in Decode. Choose text or binary output and set the original padding count. The report lists corrected positions or detected failures. Copy saves the displayed result; Download includes settings and the report.
For example, text A is the byte 01000001. In BCH(7,4), its nibbles 0100 and 0001 encode to 0100111 0001011. No padding is needed.
How BCH decoding works
- Calculate syndromes. Evaluate the received polynomial r(x) at α¹ through α²ᵗ. Zero syndromes mean the received word is a member of the code.
- Find the error locator. Berlekamp–Massey fits the shortest recurrence to the syndrome sequence, producing Λ(z) = 1 + λ₁z + … + λᵥzᵛ.
- Locate errors with a Chien search. Evaluate Λ at α⁻ⁱ for every bit exponent i. A root identifies a bit to flip.
- Validate the candidate. Require at most t distinct roots, a root count equal to the locator degree, and zero syndromes and generator remainder after flipping. Otherwise return “uncorrectable.” Extract the first k bits of an accepted codeword.
The ECC Page’s BCH reference implementation documents the same algebraic decoding approach. The code here uses binary errors, whose nonzero magnitude is always one.
Detection has a limit. With more than t errors, the received word may lie within t bits of a different codeword—or already be another codeword. A decoder cannot identify the original in those cases. BCH(7,4) and BCH(15,11) are perfect single-error-correcting codes: their bounded-distance decoders always find a candidate. A nonzero syndrome can detect a double-bit error before correction, but cannot distinguish it from a single-bit error. See the UNB explanation of syndrome ambiguity.
Worked BCH(15,7) example: correct two flipped bits
Use g(x) = x⁸ + x⁷ + x⁶ + x⁴ + 1 over GF(16), with α a root of x⁴ + x + 1. Bits are written most significant first. Displayed position p corresponds to x¹⁵⁻ᵖ.
- Message m(x)
1010101(7 data bits)- Shift by 8
101010100000000- Remainder / parity
11100101from m(x)x⁸ mod g(x)- Systematic codeword
101010111100101- Flip positions
- 3 and 12 (x¹² and x³)
- Received word
100010111101101- S₁, S₂, S₃, S₄
7, 6, 6, 7= α¹⁰, α⁵, α⁵, α¹⁰- Error locator Λ(z)
- 1 + 7z + z² = 1 + α¹⁰z + z²
- Chien roots
- α⁻¹² = α³ and α⁻³ = α¹² → positions 3 and 12
- Corrected codeword
101010111100101- Recovered message
1010101
Field elements are shown as polynomial-basis integers: 7 = α² + α + 1 and 6 = α² + α. Addition is XOR, not ordinary integer addition. The syndromes, locator, positions and output above are recomputed alongside the experiment below.
Supported BCH parameters and generator polynomials
These are binary, primitive, narrow-sense BCH codes with n = 2ᵐ − 1 and roots α¹…α²ᵗ. All use systematic encoding: c(x) = m(x)xⁿ⁻ᵏ + [m(x)xⁿ⁻ᵏ mod g(x)], where addition is XOR.
| n | k | t | Generator g(x) |
|---|---|---|---|
| 7 | 4 | 1 | x^3 + x + 1binary 1011 · UNB record |
| 15 | 11 | 1 | x^4 + x + 1binary 10011 · UNB record |
| 15 | 7 | 2 | x^8 + x^7 + x^6 + x^4 + 1binary 111010001 · UNB record |
| 15 | 5 | 3 | x^10 + x^8 + x^5 + x^4 + x^2 + x + 1binary 10100110111 · UNB record |
| 31 | 21 | 2 | x^10 + x^9 + x^8 + x^6 + x^5 + x^3 + 1binary 11101101001 · UNB record |
| 31 | 16 | 3 | x^15 + x^11 + x^10 + x^9 + x^8 + x^7 + x^5 + x^3 + x^2 + x + 1binary 1000111110101111 · UNB record |
Generators follow Richard Tervo’s UNB BCH polynomial tables: choose P(x) = x³ + x + 1 for n = 7, x⁴ + x + 1 for n = 15, or x⁵ + x² + 1 for n = 31. These primitive polynomials also match the MathWorks table. The polynomial basis and bit order matter when comparing output with another encoder.
What happens beyond the correction limit?
For each code and each error count e = 1…t + 2, we generated 10,000 random codewords and flipped exactly e distinct positions. That is 240,000 trials in all. Every tested word with e ≤ t decoded correctly.
Each compact table reports percentages. Correct means the accepted word equals the original. Detected means the decoder returned uncorrectable. Wrong means a miscorrection: an accepted wrong codeword, including zero-syndrome errors that pass unchanged. Only this experiment knows the transmitted word.
| Flips e | Correct % | Detected % | Wrong % |
|---|---|---|---|
| 1 | 100.00 | 0.00 | 0.00 |
| 2 | 0.00 | 0.00 | 100.00 |
| 3 | 0.00 | 0.00 | 100.00 |
| Flips e | Correct % | Detected % | Wrong % |
|---|---|---|---|
| 1 | 100.00 | 0.00 | 0.00 |
| 2 | 0.00 | 0.00 | 100.00 |
| 3 | 0.00 | 0.00 | 100.00 |
| Flips e | Correct % | Detected % | Wrong % |
|---|---|---|---|
| 1 | 100.00 | 0.00 | 0.00 |
| 2 | 100.00 | 0.00 | 0.00 |
| 3 | 0.00 | 60.28 | 39.72 |
| 4 | 0.00 | 61.36 | 38.64 |
| Flips e | Correct % | Detected % | Wrong % |
|---|---|---|---|
| 1 | 100.00 | 0.00 | 0.00 |
| 2 | 100.00 | 0.00 | 0.00 |
| 3 | 100.00 | 0.00 | 0.00 |
| 4 | 0.00 | 62.42 | 37.58 |
| 5 | 0.00 | 61.15 | 38.85 |
| Flips e | Correct % | Detected % | Wrong % |
|---|---|---|---|
| 1 | 100.00 | 0.00 | 0.00 |
| 2 | 100.00 | 0.00 | 0.00 |
| 3 | 0.00 | 58.96 | 41.04 |
| 4 | 0.00 | 58.48 | 41.52 |
| Flips e | Correct % | Detected % | Wrong % |
|---|---|---|---|
| 1 | 100.00 | 0.00 | 0.00 |
| 2 | 100.00 | 0.00 | 0.00 |
| 3 | 100.00 | 0.00 | 0.00 |
| 4 | 0.00 | 83.52 | 16.48 |
| 5 | 0.00 | 82.67 | 17.33 |
For BCH(15,7) with three flipped bits, 60.28% were detected and 39.72% returned the wrong codeword. This illustrates why “corrected” alone cannot certify a message sent through a channel that exceeds the code’s error budget.
Reproduce the seeded experiment
PRNG: Mulberry32. Base seed: 20261029. Each row starts with seed = base seed + n × 10000 + k × 100 + e. Each trial draws one uniform k-bit message, then samples e positions without replacement using a partial Fisher–Yates shuffle. Trials use hard bit flips, no erasures and no soft information. Percentages describe this experiment, not a device or channel error rate; two decimals reflect the 10,000-trial sample, not a guarantee of population precision.
Download JSON: seeds, counts, percentages and worked example. Download source and tests (v2, October 29, 2026; ZIP) to reproduce the results offline. The bundle includes the BCH implementation, simulation generator, tests, both JSON files and instructions for Node.js 22.6 or later. No package installation is needed.
BCH vs Hamming vs Reed–Solomon
| Code | Error unit | Correction |
|---|---|---|
| Binary BCH | Bit | Up to t bits, with parameters chosen for that t |
| Hamming | Bit | 1 bit; extended Hamming adds double-error detection |
| Reed–Solomon | Symbol, often a byte | Up to ⌊(n − k)/2⌋ symbol errors without erasures |
BCH(7,4) and BCH(15,11) are cyclic forms of binary Hamming codes. Reed–Solomon is part of the broader nonbinary BCH family. Several bit flips within one byte can count as one Reed–Solomon symbol error; the same flips count separately for binary BCH. See MathWorks’ block-code and symbol-format documentation.
Where BCH codes are used
- QR format information. The 5 format bits use BCH(15,5) and a fixed mask; QR payload data uses Reed–Solomon. The Nayuki QR implementation’s format-bit routine uses generator
0x537and mask0x5412. The tool’s BCH(15,5) output is the unmasked codeword. - Flash-memory error correction. Texas Instruments’ AM335x memory controller supports BCH error correction with an error-locator module; see the AM335x data sheet, page 1. Its larger BCH configurations operate on 512-byte blocks.
- DVB-S2 satellite transmission. An outer BCH code precedes the inner LDPC code in the ETSI DVB-S2 standard, sections 5.3 and 5.3.1. These system codes are longer than the short teaching examples here.
BCH code FAQ
What is a BCH code?
A BCH (Bose–Chaudhuri–Hocquenghem) code is a cyclic error-correcting block code. It adds parity bits so a receiver can recover data after a limited number of bit errors. A binary BCH(n,k) code carries k data bits in each n-bit codeword; it provides error correction, not encryption.
How many errors can a BCH code correct?
A BCH code designed for t-error correction corrects any combination of up to t bit errors per codeword. Its designed minimum distance is 2t + 1. The codes here correct one, two or three bits. Beyond t, the decoder may reject a word as uncorrectable or accept a wrong codeword; zero syndromes do not guarantee that no transmission errors occurred.
What is the difference between BCH and Reed–Solomon?
Binary BCH codes correct individual bit errors. Reed–Solomon codes operate on symbols, often bytes, so one corrected symbol can contain several flipped bits. Reed–Solomon codes belong to the broader nonbinary BCH family. Choose based on whether errors are measured in bits or in symbols and on the required code length and redundancy.