Skip to main content

Barcode Numbers

Convert digits to and from common barcode width numbers.

UPC and EAN barcodes encode each digit as a sequence of four alternating black and white bars whose widths always sum to 7 modules. Use the chart below to translate digits to and from those four-number width patterns. See How To Read A Barcode below for a full walkthrough with diagrams.

Barcode Digit Widths

0123456789
3211222121221411113212311114131212133112

How To Read A Barcode

Barcodes are composed of both black and white lines and are typically found on product packaging. The 12-digit UPC (Universal Product Code) is used in the US and Canada and consists of 10 middle numbers and two numbers at both ends of the code (with the last one being a check digit).

UPC barcode indicators

Barcodes are not formed only by black lines but also by the white space as well. The first thing to notice is that the lines can have 4 different thicknesses.

Barcode line thicknesses

Codes begin with the code 101 (thin black line - thin white line - thin black line) and at exactly half the code, there is the line 01010 as indicated below.

Begin, half and end codes

Each number is represented by 7 lines according to a pre-established pattern. The sum of the four widths is always 7 (e.g. 6 = 1114 → 1+1+1+4 = 7). In the second half of the barcode, the colors of the lines are inverted from the first half so the scanner can detect the reading direction.

Barcode reading example

For example, a barcode whose first two digits are 0 and 1 starts with 10132112221. Broken into segments that's 101-3211-2221: 101 marks the beginning, 3211 is digit 0, and 2221 is digit 1.

Calculating the check digit

For a standard 12-digit barcode like 012345678905 the last digit (5) is the check digit:

  • Add the odd-position digits: 0 + 2 + 4 + 6 + 8 + 0 = 20.
  • Multiply by 3: 20 × 3 = 60.
  • Add the even-position digits: 1 + 3 + 5 + 7 + 9 = 25.
  • Add the two results: 60 + 25 = 85.
  • Take 85 mod 10 = 5; if non-zero subtract from 10. Here the check digit is 5.