UPC/EAN - The Global Standard: How the Barcode on Every Product Conquered the World |
Subtitle: A Deep Dive into the Symbology, Its Encoding, Its Decoding, and Its Real-World Implementations - with Examples from Symbol, Zebra, Honeywell, Datalogic, Microchip, and NXP |

|
Opening Summary |
If you have ever bought a product in a supermarket, you have seen a UPC or EAN barcode. The Universal Product Code (UPC) and its international counterpart, the European Article Number (EAN), are the global standards for retail barcoding. They are the reason why checkout is fast, inventory is accurate, and supply chains are efficient. These symbologies are used on billions of products worldwide, and they are the bedrock of the modern retail economy. |
This article is dedicated to UPC and EAN - the global standards. We will explore their history, their encoding structure, and their decoding algorithm. We will examine the differences between UPC-A, UPC-E, EAN-13, and EAN-8. We will look at the left and right halves, the center guard pattern, and the checksum. We will examine how major companies have implemented UPC/EAN decoding in their products. We will see how Symbol (now Zebra) supported UPC/EAN in the LS2208. We will explore Honeywell's implementation of UPC/EAN in their imagers. We will examine Datalogic's support for UPC/EAN in their industrial scanners. We will also look at reference designs from Microchip, NXP, and STMicroelectronics, which include complete UPC/EAN decoding examples. |
By the end of this journey, you will understand that UPC/EAN is not just a simple code but a carefully engineered system that balances data capacity, printability, and error correction. You will see how its elegant structure makes it both easy to print and robust to decode. |

|
Full Article |
Section 1: The Origins of UPC - The Birth of the Retail Barcode |
The Universal Product Code was born in 1973, when the grocery industry in the United States adopted a single standard for product identification. The code was based on a design by George Laurer of IBM. The first UPC barcode was scanned on a pack of Wrigley's chewing gum in a supermarket in Troy, Ohio, on June 26, 1974. The rest, as they say, is history. |
UPC-A is a numeric-only, fixed-length code. It encodes 12 digits: the first digit is the number system, the next five digits are the manufacturer code, the next five digits are the product code, and the last digit is a checksum. The code is designed to be printed on a wide range of surfaces and to be decoded reliably even when damaged. |

|
Section 2: The European Adoption - EAN-13 |
While the United States adopted UPC-A, the European community developed its own standard, the European Article Number (EAN). EAN-13 is very similar to UPC-A, but it encodes 13 digits. The first two or three digits are a country code, followed by the manufacturer code, the product code, and a checksum. (UPC-A can be considered a subset of EAN-13, with a leading zero.) |
EAN-13 is the most common barcode in Europe, Asia, and most of the world. UPC-A is still used in the United States and Canada. Most scanners support both. |
Section 3: The Encoding Structure - The Left and Right Halves |
UPC-A and EAN-13 encode each digit as a pattern of seven elements: two bars and two spaces. The elements are either narrow or wide, but the encoding is not a simple binary representation. Instead, each digit has two possible encodings: a 'left' encoding (for the left half of the barcode) and a 'right' encoding (for the right half). The left encodings are the complements of the right encodings. |
The barcode is divided into two halves by a center guard pattern. The left half contains the first six digits (or the first seven digits for EAN-13, with the first digit encoded in the parity of the left half). The right half contains the remaining digits. |

|
Section 4: The Left Encoding - The L-Code |
The left encoding (also called the L-code) is used for the left half of the barcode. The L-code has an odd number of wide elements (one or three wide elements out of the seven). The L-code is used to represent the digits 0-9. |
Section 5: The Right Encoding - The R-Code |
The right encoding (also called the R-code) is used for the right half of the barcode. The R-code has an even number of wide elements (two wide elements out of the seven). The R-code is the complement of the L-code. |

|
Section 6: The Center Guard Pattern - The Middle Marker |
The center guard pattern is a specific pattern of elements that separates the left and right halves of the barcode. The center guard pattern is: narrow space, wide bar, narrow space, wide bar, narrow space. It is a unique pattern that is not used for any digit. |
The center guard pattern is essential for the decoder. It tells the decoder where the left half ends and the right half begins. |
Section 7: The Left and Right Guard Patterns - The End Markers |
The left and right guard patterns are the patterns at the beginning and end of the barcode. The left guard pattern is: wide bar, narrow space, narrow bar. The right guard pattern is: narrow bar, narrow space, wide bar. |
The guard patterns are used to locate the barcode and to determine its orientation. |

|
Section 8: The Quiet Zone - The White Margin |
UPC and EAN require a quiet zone on both sides of the barcode. The quiet zone is a white margin that is at least 9 times the module width. The quiet zone is used to detect the barcode's presence and to reset the decoder's timing. |
Section 9: The First Digit - The Number System |
In UPC-A, the first digit is the number system. The number system identifies the type of product. For example, 0, 1, 6, 7, and 8 are for regular products. 2 is for products sold by weight. 3 is for drugs and healthcare. 4 is for store coupons. 5 is for coupons. |
In EAN-13, the first two or three digits are the country code. The country code identifies the country or region of the manufacturer. |

|
Section 10: The Manufacturer Code - The Vendor Identifier |
The manufacturer code is a unique identifier assigned to each manufacturer by GS1 (the organization that manages barcode standards). The manufacturer code is typically 5 or 6 digits long. |
Section 11: The Product Code - The Item Identifier |
The product code is a unique identifier assigned by the manufacturer to each product. The product code is typically 5 or 6 digits long. |
Section 12: The Checksum - The Modulo 10 Check |
The checksum is the last digit of the barcode. The checksum is a modulo 10 calculation. The checksum is used to verify the integrity of the decoded data. |
The checksum is calculated by a weighted sum of the first 11 digits (for UPC-A) or the first 12 digits (for EAN-13). The weights are 3 and 1, alternating from right to left. The sum is divided by 10. The remainder is subtracted from 10 to get the checksum. |

|
Section 13: The Checksum Calculation - A Detailed Explanation |
The checksum is calculated by taking the digits from right to left (excluding the checksum), multiplying each digit by 3 or 1 alternately, summing the results, dividing by 10, and subtracting the remainder from 10. For example, if the sum is 42, the remainder is 2, and the checksum is 8 (10 - 2 = 8). If the remainder is 0, the checksum is 0. |
The checksum is an essential error-checking mechanism. |
Section 14: The Decoding Process - An Overview |
The decoding process for UPC/EAN consists of several steps: |
1. Capture the Edge Timings: The timer capture module measures the pulse widths of the digitised waveform. |
2. Estimate the Module Width: The decoder estimates the module width using the shortest pulse method or the histogram method. |
3. Normalize the Pulse Widths: The decoder divides each pulse width by the module width and rounds to the nearest integer. |
4. Find the Quiet Zone: The decoder finds the quiet zone before and after the barcode. |
5. Find the Left Guard Pattern: The decoder finds the left guard pattern. |
6. Decode the Left Half: The decoder decodes the first six digits (or seven digits for EAN-13) using the L-code. |
7. Find the Center Guard Pattern: The decoder finds the center guard pattern. |
8. Decode the Right Half: The decoder decodes the remaining digits using the R-code. |
9. Find the Right Guard Pattern: The decoder finds the right guard pattern. |
10. Verify the Checksum: The decoder calculates the checksum and compares it to the checksum digit. |
11. Output the Data: The decoder outputs the decoded data. |

|
Section 15: Finding the Left Guard Pattern - The Starting Point |
The decoder finds the left guard pattern by scanning the element sequence for the pattern: wide bar, narrow space, narrow bar. The left guard pattern is unique. It is not used for any digit. |
The left guard pattern indicates the beginning of the barcode. |
Section 16: Decoding the Left Half - The L-Code |
The decoder decodes the left half by grouping the elements into 7-element patterns. Each 7-element pattern corresponds to a digit. The decoder compares the pattern to the L-code lookup table. |
The L-code lookup table maps the 7-element patterns to the digits 0-9. |
Section 17: Decoding the Right Half - The R-Code |
The decoder decodes the right half by grouping the elements into 7-element patterns. Each 7-element pattern corresponds to a digit. The decoder compares the pattern to the R-code lookup table. |

|
The R-code lookup table maps the 7-element patterns to the digits 0-9. |
Section 18: Finding the Center Guard Pattern - The Middle Marker |
The decoder finds the center guard pattern by scanning the element sequence for the pattern: narrow space, wide bar, narrow space, wide bar, narrow space. The center guard pattern is unique. |
The center guard pattern indicates the middle of the barcode. |
Section 19: Finding the Right Guard Pattern - The End Marker |
The decoder finds the right guard pattern by scanning the element sequence for the pattern: narrow bar, narrow space, wide bar. The right guard pattern is unique. |
The right guard pattern indicates the end of the barcode. |
Section 20: Symbol's LS2208 - UPC/EAN Support |
Symbol's LS2208 supports UPC/EAN decoding. The LS2208's firmware includes the UPC/EAN decoder. The decoder uses the shortest pulse method to estimate the module width. The decoder includes the checksum verification. |
The LS2208's UPC/EAN decoder is robust and reliable. |

|
Section 21: Honeywell's UPC/EAN Implementation |
Honeywell's imagers support UPC/EAN decoding. The imagers use a histogram-based method to estimate the module width. The histogram-based method provides better accuracy and robustness. |
Honeywell's UPC/EAN decoder also includes the checksum verification. |
Section 22: Datalogic's UPC/EAN Implementation |
Datalogic's industrial scanners support UPC/EAN decoding. The scanners use a running-average method to estimate the module width. The running-average method adapts to speed changes. |
Datalogic's UPC/EAN decoder also includes the checksum verification. |
Section 23: The UPC/EAN Lookup Tables - A Memory of Patterns |
The UPC/EAN decoder uses two lookup tables: one for the L-code and one for the R-code. The lookup tables map the 7-element patterns to the digits 0-9. |
The lookup tables are stored in the microcontroller's program memory. |

|
Section 24: The UPC/EAN Guard Patterns - Unique Markers |
The left guard pattern, the center guard pattern, and the right guard pattern are unique markers. They are not used for any digit. They are essential for locating the barcode and determining its orientation. |
Section 25: The UPC/EAN Quiet Zone - A Minimum Requirement |
UPC/EAN requires a quiet zone of at least 9 modules on each side of the barcode. The quiet zone is essential for reliable decoding. |
Section 26: The UPC/EAN Checksum - The Modulo 10 Check |
The UPC/EAN checksum is a modulo 10 calculation. The checksum is an essential error-checking mechanism. The decoder verifies the checksum to ensure the data's integrity. |

|
Section 27: The UPC/EAN Decoder and the Noise |
The UPC/EAN decoder is robust to noise. The decoder's tolerance helps to mitigate the effects of noise. |
Section 28: The UPC/EAN Decoder and the Jitter |
The UPC/EAN decoder is robust to jitter. The decoder's tolerance helps to mitigate the effects of jitter. |
Section 29: The UPC/EAN Decoder and the Distortion |
The UPC/EAN decoder is robust to distortion. The decoder's tolerance helps to mitigate the effects of distortion. |

|
Section 30: The UPC/EAN Decoder and the Scanning Speed |
The UPC/EAN decoder is robust to scanning speed variations. The module width estimation algorithm handles the variations. |
Section 31: The UPC/EAN Decoder and the Print Quality |
The UPC/EAN decoder is robust to print quality variations. The module width estimation algorithm handles the variations. |
Section 32: The UPC/EAN Decoder in Microchip's Reference Design |
Microchip's reference design includes a complete UPC/EAN decoder. The decoder uses the shortest pulse method to estimate the module width. The decoder includes the checksum verification. |

|
Section 33: The UPC/EAN Decoder in NXP's Reference Design |
NXP's reference design includes a UPC/EAN decoder. The decoder uses a histogram-based method to estimate the module width. |
Section 34: The UPC/EAN Decoder in STMicroelectronics' Reference Design |
STMicroelectronics' reference design includes a UPC/EAN decoder. The decoder uses the shortest pulse method to estimate the module width. |
Section 35: UPC-A vs. EAN-13 - A Comparison |
UPC-A encodes 12 digits. EAN-13 encodes 13 digits. EAN-13 is the international standard. UPC-A is used in the United States and Canada. |
UPC-E is a compressed version of UPC-A that encodes only 6 digits. EAN-8 is a compressed version of EAN-13 that encodes only 8 digits. These are used on small packages. |

|
Section 36: UPC/EAN - A Summary of Best Practices |
Based on our exploration, let us summarize the best practices for implementing UPC/EAN decoding in a barcode scanner: |
1. Understand the Encoding Structure: The left and right halves, the center guard pattern, the L-code, and the R-code. |
2. Use a Robust Module Width Estimation: Use the histogram-based method for better accuracy. |
3. Implement the Lookup Tables: The L-code and R-code lookup tables are essential. |
4. Include Checksum Verification: The modulo 10 checksum ensures data integrity. |
5. Test the Decoder: The UPC/EAN decoder must be tested with a variety of barcodes. |

|
Final Summary |
UPC and EAN are the global standards for retail barcoding. They are numeric-only, fixed-length codes. UPC-A encodes 12 digits; EAN-13 encodes 13 digits. The code is divided into two halves by a center guard pattern. The left half uses the L-code; the right half uses the R-code. The checksum is a modulo 10 calculation. |
We have seen how major companies have implemented UPC/EAN decoding in their products. Symbol's LS2208 supports UPC/EAN. Honeywell's imagers include a UPC/EAN decoder. Datalogic's industrial scanners support UPC/EAN. Microchip, NXP, and STMicroelectronics provide reference designs with complete UPC/EAN decoders. |
UPC/EAN is the bedrock of the modern retail economy. Its elegant structure makes it both easy to print and robust to decode. |