Barcodes, Explained
After reading this you will know how the common retail and logistics barcodes encode digits, how their check digits work, and how to pick the right symbology so your labels scan on the first pass.
What a barcode actually stores
A linear barcode is a printed number, nothing more. The bars and spaces are just a machine-readable spelling of a short string of digits or characters. A scanner measures the widths of light and dark stripes, converts those widths into a symbol pattern, and hands your software the decoded value. The bars carry no price, no product description, no color. They carry an identifier that your database looks up.
Take a supermarket example. A can with the EAN-13 number 4006381333931 encodes exactly 13 digits. The first 12 are the real payload: a country or GS1 prefix, a manufacturer code, and a product code. The 13th digit, 1, is a check digit computed from the other 12. When the checkout beam reads all 13 and the check digit does not match, the register rejects the read and the cashier scans again.
Retail barcodes are assigned, not invented. EAN and UPC numbers come from GS1, which sells company prefixes. A barcode you generate with an arbitrary number will scan fine, but it will not match any real product unless you own that number range.
The main symbologies and when to use each
Different jobs use different symbologies. The rule is simple: use the one your reader expects.
- EAN-13
- Thirteen digits. The global retail standard outside North America and increasingly everywhere. Encodes 12 payload digits plus 1 check digit.
- EAN-8
- Eight digits (7 payload plus 1 check). Used on small packages where a full EAN-13 will not fit.
- UPC-A
- Twelve digits (11 payload plus 1 check). The North American retail standard. It is mathematically a subset of EAN-13 with a leading zero.
- Code 128
- Full ASCII, variable length. The workhorse for shipping labels, serial numbers and internal tracking. High density.
- Code 39
- Digits, uppercase letters and a few symbols. Older, lower density, no mandatory check digit. Common in defense, automotive and ID cards.
- ITF-14
- Fourteen digits for shipping cartons. Encodes the case-level GTIN. Prints large and tolerates rough cardboard.
Do not reach for a linear barcode when you need to store more than a short code. A URL, a Wi-Fi credential or a paragraph of text belongs in a two-dimensional symbol. For that, use the QR Code Generator & Reader instead.
The check digit formula
EAN and UPC use a weighted modulo-10 check digit. You alternate weights of 1 and 3 across the payload digits, sum the products, and choose the check digit that rounds the total up to the next multiple of 10.
Here d_i is the i-th payload digit and w_i is its weight. For EAN-13 the weights, reading left to right across the 12 payload digits, are 1, 3, 1, 3, ... and so on. The final outer modulo turns a raw result of 10 back into 0. Every scanner runs this same arithmetic and compares the result to the digit printed on the far right.
Reproducing the demo: EAN-13 4006381333931
The demo uses the default EAN-13 payload 400638133393, which is 12 digits. Compute the check digit step by step.
- Write the 12 digits with alternating weights starting at 1: positions 1, 3, 5, 7, 9, 11 get weight 1; positions 2, 4, 6, 8, 10, 12 get weight 3.
- Weight-1 digits are
4, 0, 3, 1, 3, 9. Their sum is20. - Weight-3 digits are
0, 6, 8, 3, 3, 3. Their sum is23, times 3 is69. - Total is 20 + 69 = 89.
- 89 \bmod 10 = 9, so the check digit is (10 - 9) \bmod 10 = 1.
The full number is therefore 4006381333931, matching what the calculator draws when you press the demo button. Change any single payload digit and the check digit almost always changes, which is exactly how the scheme catches typos.
Why weighted sums catch errors
The two most common human errors are a single wrong digit and a transposition of two adjacent digits. The modulo-10 scheme catches every single-digit error, because changing one digit changes the weighted sum by a nonzero amount less than 10 in magnitude when scaled correctly, which shifts the required check digit.
Transpositions are subtler. Swapping two neighbors changes the sum by 2 \times (d_a - d_b) because one digit moves from weight 1 to weight 3 and the other moves the opposite way. That difference is caught unless d_a - d_b is a multiple of 5. So swapping a 2 and a 7 (difference 5) slips through, but the other 44 of every 45 adjacent-digit pairs are caught. The scheme is cheap and catches the large majority of real mistakes.
Reading a generated barcode
Three parts of the printed symbol matter for scanning success.
The quiet zone is the blank margin on each side. EAN-13 needs a left quiet zone of at least 11 module widths and a right zone of at least 7. A module is the width of the narrowest bar. If you crop the margin, scanners lose the start and stop patterns and the read fails.
The module width sets physical size. At the nominal EAN-13 magnification the symbol is about 37.29 mm wide and 25.93 mm tall. You can print between roughly 80 percent and 200 percent of nominal and still scan reliably. Below 80 percent the bars blur together under most laser scanners.
The human-readable line under the bars lets a person key the number in when the scan fails. Keep it. It is not decoration.
Export as SVG when the label goes to a printer or a design tool. SVG scales to any size with no blur because the bars are vector rectangles. Use PNG only when the target needs raster pixels, and then set the width high enough that each module is at least 2 pixels wide.
Common mistakes
The errors below account for most barcodes that fail at the till or on the loading dock.
- Passing 13 digits to an EAN-13 field. The generator expects the 12 payload digits and computes the check digit for you. If you paste all 13, you either double the check digit or shift the payload.
- Scaling the PNG in a document. Stretching a 300 px barcode to fill a wide label changes the aspect ratio and smears module edges. Regenerate at the target size or use SVG.
- Inverting colors. Scanners expect dark bars on a light background. White bars on black, or red on green, kill contrast. Keep bars near black and background near white.
- Using Code 39 for long numeric data. Code 39 is about 40 percent wider than Code 128 for the same digits. For a 20-character serial number that difference decides whether the symbol fits.
- Truncating the quiet zone. Designers routinely crop the white margin to save space. That single change breaks more scans than any other.
Related tools
If your data does not fit a linear barcode, or you are building printable assets, these pages help.
- QR Code Generator & Reader for URLs, contact cards and any payload longer than a short code.
- Placeholder Image Generator for mock label layouts before your real artwork is ready.
- Sprite Sheet Generator & Splitter when you need to pack many small label images into one file.
- Dithering Tool if you must print to a one-bit thermal device and want to preview contrast.
- ASCII Art from Image for a text-only rendering of a logo that sits beside the code.
Frequently asked questions
Why does my EAN-13 number turn red as I type?
The calculator validates the check digit live. If you type a full 13-digit number whose last digit does not match the computed check digit, the field flags it. Either supply 12 payload digits and let the tool add the check digit, or fix the final digit to match.
Is UPC-A the same as EAN-13?
Nearly. A UPC-A code with a leading zero prepended is a valid EAN-13. The 12 UPC digits map onto the last 12 positions of the EAN-13 payload. Most retail scanners read both.
Can I put text or a URL in a Code 128 barcode?
Yes. Code 128 encodes the full ASCII set, so letters, digits and punctuation all work. It stays compact for short strings, but for anything past 20 or so characters a QR code is smaller and more robust.
Does the height of the bars carry data?
No. A linear barcode stores information only in the horizontal widths of bars and spaces. Height exists so the scanner beam can cross the symbol at a slight angle and still capture a full scan line. Taller bars tolerate a worse aim.
Why do my printed barcodes fail but the screen version scans fine?
Usually resolution or ink spread. On a low-DPI printer thin bars merge with neighboring spaces. Print at 300 DPI or higher, keep the module width at or above 0.33 mm, and leave the quiet zones intact.