How barcodes work: check digits, EAN-13, UPC, ISBN and Code 128 explained

What the bars in a barcode stand for, how the last check digit is worked out, which type fits which job, and how small a printed bar can safely be.

Open the Barcode maker Free, in your browser, nothing uploaded.

A barcode is a number or a short text written as dark bars and light gaps of set widths, so a scanner can read it in a fraction of a second. This guide explains what the bars mean, why the last digit is a check, and how to choose between the common types, for shop owners, warehouse staff, self-publishers and students. To print the codes on sticker sheets, pair them with label maker; to test a printed code with your phone, use QR and barcode reader; and to scale a PNG for a design, image resizer.

What it is

Every barcode is cut into modules, the narrowest possible bar or gap. Each digit or character is a fixed pattern of modules. An EAN-13 is always 95 modules wide: a start guard (bar, gap, bar), six digits of 7 modules, a centre guard, six more digits and an end guard. The first of the 13 digits is not drawn as bars at all: it is hidden in which of two patterns (called L and G) the next six digits use.

The check digit catches misreads. For EAN-13, number the first 12 digits from the left, multiply them by 1, 3, 1, 3 and so on, add up, and pick the digit that brings the total to the next multiple of 10:

check = (10 − (sum mod 10)) mod 10

UPC-A does the same on 11 digits, with weights starting at 3. Change any single digit and the sum is no longer a multiple of 10, so the scanner rejects it.

Code 128 is different. It holds any keyboard character, and each symbol is 11 modules. It has three code sets: B for text, C packs two digits into one symbol, and A covers control characters. Its check is the start value plus each symbol’s value times its position, taken mod 103. Code 39 is older and wider: capitals, digits and a few signs, each framed by star characters.

How to use it

  1. Open the barcode maker and pick the type: EAN-13, UPC-A, ISBN-13, Code 128 or Code 39.
  2. Type one code per line in the box. Leave off the last digit of EAN, UPC or ISBN numbers and it is added for you; type it and it is checked.
  3. Set the bar width in pixels, the height and whether the numbers print underneath.
  4. Save the first code as PNG or SVG, or all of them as a ZIP of PNGs.
  5. For stickers, choose A4 or US Letter, columns, rows and copies, read the narrowest-bar note, then make the PDF and print at actual size.

A worked example

A small shop has the made-up product number 629104150021 (12 digits).

  • Weights 1, 3, 1, 3 … give 6 + 6 + 9 + 3 + 0 + 12 + 1 + 15 + 0 + 0 + 2 + 3 = 57.
  • 57 mod 10 = 7, and 10 − 7 = 3, so the full EAN-13 is 6291041500213.

A self-published book has the old 10-character ISBN 1-23456-789-X. Its X is a valid ISBN-10 check (it stands for 10). To make an ISBN-13, drop the old check, put 978 in front (978123456789), and work out a new EAN check: the result is 9781234567897.

A warehouse box label reads BOX-2026-000417. Code 128 starts in set B for the letters and the first digits, then switches to set C for the final run of six digits, which packs “00”, “04” and “17” into three symbols. That gives 15 symbols before the stop: start, 9 characters, the switch, 3 digit pairs and the check, whose value works out as 2,316 mod 103 = 50. With 11 modules each plus a 13-module stop, the code is 178 modules wide.

On an A4 sheet of 3 columns by 8 rows, the EAN-13 label’s narrowest bar prints at about 0.37 mm. At 4 by 10 it shrinks to 0.30 mm, still above the 80% minimum (about 0.26 mm) of the usual 0.33 mm EAN module.

Checked with the tools

All of these numbers were run through the tool’s own encoders (src/lib/web/barcode.ts) in Node: encode() added check digit 3 to 629104150021 and converted 123456789X to 9781234567897, code128Values() returned the switch to set C and check value 50, and the sheet maths from the page gave 0.37 mm and 0.30 mm. While checking, we found the Code 128 note said “14 symbols” where there are 15 (start, data and check); that is now fixed and tested.

Where it is used

  • Retail. EAN-13 (most of the world) and UPC-A (North America) on every packaged product, scanned at the till.
  • Books. ISBN-13 on the back cover is an EAN-13 that starts 978 or 979.
  • Warehouses and shipping. Code 128 for box, pallet and parcel numbers, because it is compact and holds letters.
  • Libraries and labs. Code 39 or Code 128 labels on equipment, samples and cards.

Common mistakes

  • Making up retail numbers. A shop or marketplace expects a number licensed through GS1. Use your own numbers only inside your own business.
  • Printing too small. Below the minimum bar width, scanners fail. Use fewer labels per sheet if the note warns you.
  • Losing the quiet zone. The blank margin on each side is part of the code. Do not crop it or print over it.
  • Scaling to fit in the printer box. “Fit to page” shrinks the bars. Print the PDF at 100%.

Questions people ask

What do the first digits of an EAN-13 mean? The first three digits are usually a GS1 prefix that shows which GS1 office issued the number, not where the product was made.

Why is ISBN-10’s check sometimes X? ISBN-10 uses mod 11, so the check can be 10, written as X. ISBN-13 uses mod 10 and never needs it.

Can a barcode hold a web address? Code 128 can hold a short one, but phones read QR codes far more easily.

Sources

  • GS1 General Specifications (gs1.org): EAN-13 and UPC-A structure, the check digit rule (weights 3 and 1) and the L, G and R digit patterns. Product numbers for real shops must come from GS1 or your national GS1 office; this page cannot issue them.
  • ISO/IEC 15417 (Code 128) and ISO/IEC 16388 (Code 39): symbol tables and the Code 128 check character. ISBN-13 is an EAN-13 starting 978 or 979 (isbn-international.org).
  • Encoders are fibub's own. In tests the check digits are compared with published examples (ISBN 978-0-306-40615-7, UPC 036000291452, EAN 4006381333931, Code 128 PJJ123C check value 54).

If you are an author or publisher and want a credit or a passage changed or removed, tell us and we will act quickly.

Tools in this article

Read next