Design

Barcodes and ISBN: the math behind the check digit

Every retail barcode and every ISBN ends in a digit that identifies nothing. It is the result of a calculation run over the digits before it, following a fixed rule, and its only job is catching errors: a mistyped number, a scanner that misread a bar, two digits swapped while copying. The [QR code guide](guide:qr-code-formatos-pix-vcard-wifi) already contrasted the QR’s two-dimensional matrix with the traditional, one-dimensional barcode without opening this particular box; this guide closes that gap. EAN-13 and UPC-A use one formula; ISBN, until 2006, used a different, stricter one; and since 2007 ISBN itself switched to the barcode’s formula. Let us derive both by hand, with real numbers, and test them in this platform’s [barcode generator](tool:gerador-codigo-barras) and [ISBN lookup](tool:consulta-isbn).

J-Kit15 min readIntermediate
  • Barcode
  • EAN-13
  • ISBN
  • Check digit
  • Checksum

Key takeaways

  • EAN-13 and UPC-A use a modulo-10 checksum with weights 1 and 3 (weight 3 always on the data digit closest to the check digit); it is the exact math running inside the platform’s barcode generator.
  • ISBN-10 uses modulo 11 with descending weights from 10 to 2; when the result comes out to 10, it becomes the letter X, the only letter an ISBN-10 ever allows.
  • Since January 1, 2007, every new ISBN has 13 digits and uses the same algorithm as EAN-13, prefixed by 978 or 979 (International ISBN Agency).
  • Modulo 11 catches 100% of transpositions because 11 is prime; modulo 10 (EAN/UPC) lets through a swap of two neighboring digits that differ by exactly 5.

The problem a check digit solves

A check digit is neither a hash nor encryption, it is a checksum: an extra value, computed from the digits before it through a public, reversible formula, whose only job is to confirm that sequence of numbers is internally consistent. If the difference between those three ideas still trips you up, the hashing, encryption and encoding guide settles it. A checksum hides nothing, protects nothing and does not prove a code is authentic or that the product exists: it only proves nobody fat-fingered a key typing it, or that a QR code reader and a barcode reader captured the right number.

This platform’s barcode generator produces four symbologies: Code 128, EAN-13, EAN-8 and UPC-A. The last three share the same checksum family, modulo 10 with weights 1 and 3, the core subject of this guide. Code 128 is different: each character becomes its own numeric code, and its check digit comes from a position-weighted sum, modulo 103, so it sits outside this guide’s scope. One detail only shows up in the tool’s own source: UPC-A has no separate formula of its own, it is generated by prefixing a "0" onto the 11 digits and reusing the exact EAN-13 function. That is not an implementation shortcut, it mirrors what the real standard says: a UPC-A is, structurally, an EAN-13 whose first digit always happens to be zero.

Check digit
The last digit of a code, computed from the ones before it by a fixed formula; it exists only to catch errors, it carries no information of its own about the product or book.
Checksum
The result of that calculation. "Matching the checksum" means the recomputed digit agrees with the one printed on the code.
Symbology
The drawing that turns digits into bars. EAN-13, UPC-A, EAN-8 and Code 128 are different symbologies; the check digit is math, not drawing.
Modulo (modular arithmetic)
The remainder of a division. "Modulo 10" looks at how much is missing to reach the next multiple of 10; "modulo 11" looks at the remainder after dividing by 11, including the special case where it comes out to exactly 10.
GS1 prefix
The first 3 digits of an EAN-13, assigned to whichever body issued the code, not to the country where the product was made. 789 and 790 identify GS1 Brasil.
4symbologies in this platform’s barcode generator
2checksum families: modulo 10 (EAN/UPC) and modulo 11 (ISBN-10)
2007year ISBN switched to the EAN-13 algorithm

EAN-13 and UPC-A: the modulo-10 checksum

The EAN-13 and UPC-A math is a weighted modulo-10 checksum, documented by GS1 itself, the body that administers these codes worldwide. Start at the rightmost data digit, the one right next to the check digit: it gets weight 3. The next one, to its left, gets weight 1. And so on, alternating 3, 1, 3, 1..., all the way to the very first digit on the left. Multiply each digit by its weight, add everything up, and the check digit is whatever number between 0 and 9 is missing to bring that sum to the next multiple of 10. That is exactly the math running inside this platform’s barcode generator, confirmed straight from the tool’s own source.

S = Σ (dᵢ × wᵢ) → CD = (10 − (S mod 10)) mod 10
dᵢ
the i-th data digit (the EAN-13’s first 12, or UPC-A’s 11)
wᵢ
the weight for that position: 3 on the digit closest to the check digit, alternating to 1
S
the sum of all digit × weight products
CD
the check digit, always between 0 and 9
The EAN-13 and UPC-A core: weight 3 on the rightmost digit, alternating to 1, a sum of everything, and the complement to the next multiple of 10.
Worked example 1: the check digit of a fictional EAN-13 with the 789 prefix (GS1 Brasil).
PositionDigitWeightProduct
1st717
2nd8324
3rd919
4th236
5th414
6th5315
7th111
8th030
9th818
10th8324
11th616
12th339

The twelve products add up to 113. The next multiple of 10 above 113 is 120; 120 minus 113 is 7. The check digit is 7, and the full EAN-13 reads 7892451088637. Note the 789 prefix: per GS1 Brasil, it (together with 790) marks codes it issued, not that the product was manufactured in Brazil, the two get conflated often.

UPC-A follows the same math over 11 data digits, one fewer than EAN-13. A quick example: 03600029145. With only 11 positions, the weight alternation already lands on 3 at the first position from the left (the rightmost digit still carries weight 3, the count just climbs from there). The sum is 58; the next multiple of 10 is 60; the check digit is 2, closing the code as 036000291452. That is why, in the barcode generator, generating a UPC-A and an EAN-13 runs exactly the same engine underneath, confirmed in the source: UPC-A gets a leading zero, becomes a 12-digit EAN-13, and the same function computes the check digit for both.

Type the 11 or 12 data digits and watch the check digit get computed and drawn as bars, for EAN-13, EAN-8, UPC-A or Code 128.Open the tool full page

ISBN-10: the modulo-11 checksum and the letter X

ISBN was born apart from the retail barcode. The system began in the United Kingdom in 1967 and reached the United States in 1968, through R. R. Bowker. For decades an ISBN had 10 digits, 9 data digits plus 1 check digit, but the math behind it differs from EAN-13’s. Instead of modulo 10, ISBN-10 uses modulo 11, and the choice is not cosmetic: 11 is prime, which changes what the digit can prove, a point we return to in the final section. The weights change too: they descend from 10 to 2 across the 9 data digits, left to right. The check digit is whatever value between 0 and 10 makes the sum of all products a multiple of 11; when that value comes out to exactly 10, it does not fit a single digit, so the standard uses the letter X instead, the only position in an ISBN-10 that can ever be a letter.

S = Σ (dᵢ × pᵢ) → r = S mod 11 → DV = (11 − r) mod 11
dᵢ
the i-th of the 9 data digits
pᵢ
the weight for that position, descending from 10 to 2, left to right
r
the remainder of the sum divided by 11
DV
the check digit; becomes the letter X when the result is 10
The ISBN-10 core: descending weights from 10 to 2, a sum, the remainder after dividing by 11, and the complement to 11. When the result comes out to 10, it becomes the letter X.
Worked example 2: the check digit of a fictional ISBN-10.
PositionDigitWeightProduct
1st61060
2nd5945
3rd4832
4th7749
5th8648
6th2510
7th144
8th9327
9th326

The nine products add up to 281. The remainder of 281 divided by 11 is 6 (281 = 25×11 + 6). The check digit is 11 minus that remainder, 5. The full ISBN-10 reads 6547821935. A second example shows the letter X in practice: for the base 650114924, the weighted sum is 188, and the remainder of 188 divided by 11 is 1 (188 = 17×11 + 1). Eleven minus one is ten, and ten does not fit a single digit, so the ISBN-10 closes as 650114924X. Registration systems that reject ISBNs ending in X are themselves the bug: the letter is a legitimate part of the standard, not a typo.

The merger with EAN-13: the 2007 transition

  1. 1949–1952The concept’s patent

    Norman Woodland and Bernard Silver file a patent for a pattern-based classifying system in 1949; it is granted on October 7, 1952, as US Patent No. 2,612,994. The two sold the rights for $15,000, the entire direct financial return they ever saw from the invention.

  2. 1967–1968ISBN is born, apart from retail

    The book-numbering system begins in the United Kingdom in 1967 and reaches the United States in 1968 through R. R. Bowker. It starts as a 10-digit identifier, with its own check-digit math, unrelated to the barcodes that would come to dominate retail.

  3. April 3, 1973US retail picks the UPC symbol

    US grocery-industry representatives adopt the rectangular Universal Product Code (UPC) design as the standard, ending years of competing proposals.

  4. June 26, 1974The first commercial scan

    A ten-pack of Wrigley’s Juicy Fruit gum becomes the first product in the world scanned by a barcode reader, at a Marsh supermarket in Troy, Ohio. The product was picked on purpose: nobody was certain a code could even fit on a package that small.

  5. January 1, 2007ISBN becomes an EAN-13

    Under the International ISBN Agency’s rule, every new ISBN becomes 13 digits, prefixed by 978 (or 979, added later), using the exact same modulo-10 algorithm as the retail barcode.

Converting an ISBN-10 to an ISBN-13 does not reuse the old check digit, it discards it and recomputes from scratch. Take the ISBN-10’s 9 data digits (without the check digit), prepend the 978 prefix, forming 12 digits, and apply the same modulo-10 math from EAN-13 in the previous section. The result is a new number, with a new check digit, representing the same book.

The same fictional book (data digits 654782193) in both formats.
FormatFull numberData digitsAlgorithm
ISBN-106547821935654782193 (9 digits)modulo 11, weights 10 to 2
ISBN-139786547821933978654782193 (12 digits)modulo 10, weights 1 and 3 (same as EAN-13)

Notice: it is the same book, the same 9 core digits (654782193), but two different check digits, 5 for ISBN-10 and 3 for ISBN-13, because they are two different calculations. The practical upside of the new format is that it prints as a genuine EAN-13: any store barcode reader, with no special logic for books, already knows how to read it. In Brazil, ISBN has been administered by the Câmara Brasileira do Livro (CBL) since 2020; before that, by the Fundação Biblioteca Nacional. The country prefix inside the ISBN changed too: 85 identified Brazil since the system’s adoption, but it ran out, and the International ISBN Agency released 65 as an additional Brazilian prefix starting in 2018. Older ISBNs starting with 85 remain valid, the new prefix only applies to new registrations. This platform’s ISBN lookup accepts both the 10- and 13-digit formats and fetches book metadata through BrasilAPI, but it does not recompute the check digit before querying, so it is worth doing the math yourself before reporting an ISBN as "broken".

What the check digit actually catches (and what it does not)

A check digit exists for a narrow purpose: catching a typo or a misread before it turns into a wrong order or a search with no results. The CPF and CNPJ validation guide shows this same principle applied to Brazilian documents, also a modulo-11 checksum, and the same caveat holds here: a "valid" code proves the arithmetic checks out, not that the product exists in a manufacturer’s catalog or that an ISBN maps to an actually published book. But the two checksum families in this guide do not catch the same errors with the same reliability, and the difference is mathematical, not a quirk of the standard.

EAN-13 / UPC-A (modulo 10)

  • Catches 100% of single-digit substitutions.
  • Catches most transpositions of neighboring digits.
  • Does NOT catch a swap of two neighboring digits that differ by exactly 5 (0↔5, 1↔6, 2↔7, 3↔8, 4↔9).

ISBN-10 (modulo 11)

  • Catches 100% of single-digit substitutions.
  • Catches 100% of transpositions, neighboring or not, because 11 is prime and every weight is distinct.
  • Cost: the check digit sometimes has to be the letter X.
Three errors applied to example 1’s EAN-13 (7892451088637) and one of them redone on an ISBN-10.
ScenarioWhat changesResult
Typoposition 5: 4 becomes 9 → 789295108863checksum recomputes to 2, does not match the original 7: CAUGHT
Common transpositionpositions 3 and 4 swap (9,2 → 2,9) → 782945108863checksum recomputes to 3, does not match the 7: CAUGHT
Transposition of digits 5 apart789275108863 (2,7) becomes 789725108863 (7,2)both give checksum 4: NOT CAUGHT
The same swap, now on an ISBN-10652278193 (2,7) becomes 652728193 (7,2)gives X in one case and 5 in the other: CAUGHT

The explanation is simple algebra. Swapping two neighboring digits changes the sum by the difference between the two weights (2, since the weights alternate between 1 and 3) times the difference between the two digits. When that digit difference is 5, the result is 2 × 5 = 10, and modulo 10 that simply vanishes: the final sum does not change. In ISBN-10, the difference between neighboring weights is always 1 (10, 9, 8...), so that same calculation never vanishes modulo 11, which is why it catches every transposition, not just most of them. The full step-by-step proof lives in an engineering write-up from the University of New Brunswick, cited in the sources, for anyone who wants the algebra line by line.

Frequently asked questions

How is the EAN-13 check digit calculated?
Multiply the 12 data digits by alternating weights, 3 on the digit closest to the check digit, 1 on the next, and so on. Add everything up. The check digit is whatever number between 0 and 9 is missing to bring that sum to the next multiple of 10. UPC-A and EAN-8 use the same formula, only the count of data digits changes.
Why does an ISBN sometimes end in X?
ISBN-10 uses modulo 11, which can produce a remainder requiring a check digit worth 10. Since an ISBN-10 only has 10 character positions, that "10" is written as the Roman numeral X instead of two digits. It is neither an error nor a placeholder, it is a legitimate part of the standard.
Do the ISBN-10 and ISBN-13 of the same book share the same check digit?
Almost never. The conversion keeps the 9 core digits but discards the old check digit (computed in modulo 11) and computes a new one, in modulo 10, after prepending 978. They are two different formulas, so the two digits are usually different.
Does a correct check digit guarantee the product or book is real?
No. It guarantees only that the arithmetic checks out, the same limit that applies to CPF and CNPJ. A code can "pass" the math and never have been registered with a GS1 member organization or an ISBN agency. Confirming existence requires querying the responsible body’s database, not just validating the digit.
Does the EAN-13 check digit catch any typing error?
It catches every single-digit error and most transpositions between neighboring digits. The known exception: when the two swapped digits differ by exactly 5 (like 2 and 7, or 0 and 5), the weighted sum does not change modulo 10, and the error slips through.
Which barcode formats does this platform’s generator produce?
Code 128, EAN-13, EAN-8 and UPC-A, all as local SVG, with the value never sent to a server. EAN-13, EAN-8 and UPC-A share this guide’s modulo-10 checksum; Code 128 uses its own math, modulo 103, weighted by each character’s position.

The last digit of an EAN-13, UPC-A or ISBN is never chosen, it is always computed. EAN-13 and UPC-A sum the digits before it with alternating weights of 1 and 3, weight 3 always on the digit closest to the check digit, and close in modulo 10. ISBN-10 sums with descending weights from 10 to 2 and closes in modulo 11, which sometimes becomes the letter X, a stricter check that catches every transposition, not just most. Since January 1, 2007, ISBN itself switched to the EAN-13 formula, prefixed by 978 or 979. Understand both formulas and you can, with pen and paper, tell a code with a typo from a genuine one, exactly what this platform’s barcode generator and ISBN lookup do in milliseconds.

Sources & references

  1. GS1, How to calculate a check digit manually
  2. International ISBN Agency, What is an ISBN?
  3. American Library Association, Fact Sheet 28: ISBN and ISSN Systems
  4. Tervo, R. (University of New Brunswick), Secrets of the ISBN: An Error Detection Method
  5. Google Patents, US2612994A, Classifying apparatus and method
  6. National Inventors Hall of Fame, Bernard Silver
  7. Marketplace, The inventors of the now-ubiquitous barcode received a patent 70 years ago
  8. GS1, Historical timeline
  9. Smithsonian Magazine, The History of the Bar Code
  10. GS1 Brasil, Types of barcodes
  11. Câmara Brasileira do Livro, ISBN numbering changes in Brazil