# How were the sequence of bar widths assigned to digits 0-9 for UPC barcodes?

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

• 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.
– hazzey
Sep 8 '16 at 19:47
• 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 ). Sep 13 '16 at 13:34

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 ).