UPC barcodes are comprised of a series of black and white bars. Bars can range in width from 1 to 4 (1 being the thinnest and 4 being the thickest). Each digit, 0 through 9 is encoded using exactly 4 bars:

Digit | Bar Thickness Sequence
  0   |        3-2-1-1
  1   |        2-2-2-1
  2   |        2-1-2-2
  3   |        1-4-1-1
  4   |        1-1-3-2
  5   |        1-2-3-1
  6   |        1-1-1-4
  7   |        1-3-1-2
  8   |        1-2-1-3
  9   |        3-1-1-2

How were the bar widths assigned to the numbers 0 through 9? I notice that each series of 4 bars sums to 7, but other than that I am not seeing an obvious pattern?

(Note: The numbers a UPC barcode encodes can have special meanings (product classifcation, vendor, checksum, etc.) This question is only about how the bar widths (the barcode encoding) was derived.

Here is one of the references I found: All About UPC Barcode & EAN Barcode

  • 2
    $\begingroup$ I don't know the full answer, but it certainly was done with an eye toward error correction/detection. (Yes, there is still a check code) A barcode reader has to be able to detect whether it has read the start of a whole digit or a partial digit. If you look at the width numbers, there shouldn't be a pattern that is able to be shifted right or left by one bar and still produce valid digits. $\endgroup$
    – hazzey
    Sep 8 '16 at 19:47
  • $\begingroup$ note the sequence is alternating black/white, so a shift error would need to be a shift of two. There are in fact plenty of examples where that would show up, for example 4-6 shifted by two would give a zero (So my conclusion such a shift error was not a concern ). $\endgroup$
    – agentp
    Sep 13 '16 at 13:34

@hazzey is on the right track. This is kind of the reverse of Gray Code, where the intent was to avoid bad data during meta-states of the encoder. Since a bar code is static, we want to maximize the signal difference between all values, not just neighbors, and we want to minimize the total physical space -- hence the paucity of "4" widths.

I'll point out that there are a number of different implementations in use today.


Just an observation, but first note there are only 20 combinations of 1-4 that add to 7, i.e. half are used and half are invalid.

Any one-bit error (A bar read as too wide or narrow) would be an obvious error, with the sequence no longer summing to 7.

A one bit shift, that is a bar read too wide and one of the adjacent spaces correspondingly too narrow, would add to 7 and appear valid, however if you look at the sequences selected for use you will find that every possible shift like that results in an unused sequence and would so be identified as an error. ( Example if 2-1-2-2 was read as 1-2-2-2 or 2-2-1-2 or 2-1-3-1 that would be an error ).

Of course that doesn't tell us anything about how the specific sequence to number mapping was made.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.