Every time a cashier scans your groceries, a laser is reading a precise mathematical pattern encoded in black and white lines. But how do barcodes actually encode data? The answer is more elegant than most people realize, and understanding it reveals why barcodes are one of the most reliable data systems ever built. This guide explains the actual encoding mechanics behind every major barcode format, from the stripes on a cereal box to the QR code on your boarding pass.
A Brief History: From Patent to Grocery Store
The story begins with Norman Woodland and Bernard Silver, who filed US patent 2612994 in 1949. Woodland, inspired by Morse code, extended dots and dashes into lines of varying widths. The technology sat mostly dormant for decades until laser scanning became practical.
The first commercial barcode scan happened on June 26, 1974, in Troy, Ohio, when a pack of Wrigley's Juicy Fruit gum was scanned at a Marsh supermarket. That single scan proved the system worked at retail speed, and the modern supply chain was born.
Today, GS1, the global standards organization, manages barcode standards used in over 150 countries. Roughly 6 billion barcodes are scanned every day worldwide.
How 1D Barcodes Encode Information
Traditional one-dimensional barcodes encode data through the widths of alternating bars and spaces. The key insight is that a scanner does not read color: it reads transitions between dark and light, and measures how wide each element is.
Most modern 1D barcode systems use a module-based encoding approach. A "module" is the narrowest possible bar or space in a given symbol. Wider elements are exact multiples of that module width. The scanner measures element widths as multiples of the module and converts them into a binary string, then decodes that string against a lookup table defined by the barcode standard.
EAN-13: The Global Retail Standard
EAN-13 (European Article Number, 13 digits) is the barcode on almost every consumer product sold outside North America. Its structure is:
| Position | Digits | Meaning |
|---|---|---|
| 1-3 | Country/region prefix | GS1 prefix (e.g., 590 = Poland) |
| 4-8 | Manufacturer code | Assigned by GS1 to the company |
| 9-12 | Product code | Assigned by the manufacturer |
| 13 | Check digit | Calculated from the first 12 |
Each digit is encoded as a pattern of 2 bars and 2 spaces spanning exactly 7 modules. The left and right halves of the barcode use different encoding tables, which is how the scanner knows which direction it is reading.
Check digit calculation for EAN-13: The check digit prevents misreads. For the 12-digit string 590123412345:
- Take odd-position digits (positions 1, 3, 5, 7, 9, 11): 5, 0, 2, 4, 2, 4. Sum = 17.
- Take even-position digits (positions 2, 4, 6, 8, 10, 12): 9, 1, 3, 1, 3, 5. Multiply each by 3, sum = 66.
- Total = 17 + 66 = 83.
- Check digit = next multiple of 10 minus total = 90 - 83 = 7.
The complete EAN-13 is 5901234123457.
UPC-A: The North American Standard
UPC-A is the 12-digit barcode used in the United States and Canada. It is essentially EAN-13 with a leading zero implied. Its structure:
- Digit 1: Number system digit (0 = standard grocery, 2 = variable-weight produce, 3 = drugs and health items, 5 = coupons)
- Digits 2-6: Manufacturer code (5 digits, assigned by GS1 US)
- Digits 7-11: Product code (5 digits, assigned by manufacturer)
- Digit 12: Check digit (same alternating 1/3 weight formula as EAN-13)
A UPC-A barcode encodes 12 digits across 95 modules using start, center, and end guard patterns.
Code 39: The Original Alphanumeric Barcode
Code 39 was invented in 1974, the same year as the first retail barcode scan. It was the first barcode to encode letters as well as numbers, making it the standard for industrial, military, and healthcare applications for many years.
The encoding logic is built into the name: each character is represented by 9 elements (5 bars and 4 spaces), and exactly 3 of those 9 elements are wide. "Three of nine" gives Code 39 its alternative name. Wide elements represent 1, narrow elements represent 0, giving each character a unique 9-bit pattern.
Code 39 natively supports uppercase letters A-Z, digits 0-9, and the symbols: space, $, %, +, -, ., /. It includes a start and stop character (asterisk, *) that the scanner recognizes as delimiters.
Code 128: High-Density ASCII Encoding
Code 128 is a much denser barcode format that can encode all 128 ASCII characters. Each character is represented by 3 bars and 3 spaces with varying widths, and the total width of any character is always exactly 11 modules. This fixed-width property makes scanning highly reliable.
Code 128 has three subtypes:
| Subtype | Encodes |
|---|---|
| Code 128A | Uppercase letters, digits, control characters |
| Code 128B | Upper and lowercase letters, digits, special characters |
| Code 128C | Numeric pairs only (digit density doubles) |
Code 128 includes a check character calculated as: (start symbol value + sum of each symbol value multiplied by its position) mod 103. This is a more sophisticated integrity check than EAN-13's simple check digit.