Guide
How Barcodes Work: Code 128, EAN-13, UPC-A and Check Digits
A plain explanation of how a barcode stores text or numbers, what a check digit does, how EAN-13, UPC-A, Code 128 and Code 39 differ, and why printed barcodes fail to scan.
On this page
A one-dimensional barcode is a row of bars and gaps of different widths. A scanner measures those widths and turns them back into characters. Because the information sits in the widths, a barcode does not care about colour, only about contrast and clean edges.
What is inside a barcode
- Quiet zones: blank margins on both sides that tell the scanner where the code starts and ends.
- Start and stop patterns: fixed marks that let the scanner work out the direction and the bar width.
- Data: the encoded characters.
- Check digit or checksum: a calculated value that lets the scanner detect a misread.
The common types
Code 128 encodes all standard keyboard characters and is very compact because it packs pairs of digits into one symbol. It suits web addresses, serial numbers, shipping labels and inventory. The checksum is the weighted sum of the symbol values divided by 103, and the remainder is added as a symbol.
Code 39 encodes capital letters, digits and a few symbols, with a star as start and stop. It is older and wider than Code 128 but still common on badges and in older systems.
EAN-13 is the 13-digit retail barcode used worldwide. UPC-A is its 12-digit North American form, and EAN-8 is a short version for small packs. ITF-14 (GTIN-14, often called EAN-14) is used on cartons.
How the EAN-13 check digit works
Multiply the first 12 digits alternately by 1 and 3 starting with 1, add the results, and subtract the total from the next multiple of 10. For 400638133393 the sum is 109, so the check digit is 1 and the full number is 4006381333931. The EAN-13 barcode generator does this automatically and tells you if a typed check digit is wrong. UPC-A and EAN-8 use the same idea with the weights 3 and 1 in the opposite order.
Making a barcode
You can turn text or numbers into a barcode with the barcode generator. It supports bulk lists and downloads SVG, PNG and EPS. If you need a 2D code that holds a link instead, read QR codes explained.
Why printed barcodes fail to scan
- The bars are too thin for the printer, or the image was stretched or blurred.
- There is no white margin around the code.
- Contrast is low, or the colours are inverted (light bars on a dark background).
- The label is glossy, curved or wrinkled.
- The check digit is wrong, or the scanner has not enabled that barcode type.
Print at 100% size, keep the margins and always test one printed copy with the scanner you will use.
A note on retail numbers
Shops expect EAN or UPC numbers issued through GS1. A generator can draw a correct barcode, but it cannot give you a registered number. Numbers starting with 20 to 29 are reserved for in-store use and are fine for tests.