Skip to content
Utilities2026-11-22Shuai Li4 min read

UPC Check Digits Explained: How to Validate and Generate UPC-A Barcodes Correctly

Listing a product on Walmart or Amazon US, fixing a spreadsheet of inventory barcodes, or printing labels for the first time — every one of these eventually hits the same question: is this 12-digit UPC actually valid? This post explains how the check digit works, where real-world UPC data usually breaks, and how to validate or generate a barcode without tripping GS1 rules.

The anatomy of a UPC-A

A UPC-A is 12 digits, and it is the North-American face of the broader GTIN-12:

  • Number system digit (1): the first digit of the GS1 Company Prefix. A few values have dedicated uses (2 for random-weight items, 3 for pharmaceuticals, 5 for coupons); see GS1's own documentation for the meaning of the remaining values.
  • Company prefix + item reference (10 digits together): GS1 assigns a company prefix to one company, and the company uses the remaining digits to number its own products. The split between the two is variable — a shorter prefix leaves more room for item references — so neither field has a fixed length.
  • Check digit (1): computed from the previous 11 digits.

An EAN-13 that starts with 0 is exactly a UPC-A with a leading zero — which is why a scanner sometimes hands you 13 digits for what the label prints as 12.

The check digit algorithm, with a worked example

Take the classic sample UPC 01234567890 5:

  1. Multiply the digits in odd positions (1st, 3rd, 5th, 7th, 9th, 11th) by 3: 0,2,4,6,8,0 → 20 × 3 = 60.
  2. Add the even positions (2nd, 4th, 6th, 8th, 10th): 1,3,5,7,9 → 25.
  3. Sum: 60 + 25 = 85. The check digit is what rounds the total up to a multiple of 10: (10 − 85 mod 10) mod 10 = 5. ✓

The same weights (3,1,3,1,…) apply to EAN-13 and GTIN family codes — learn it once and you can hand-verify any retail barcode. One edge case worth knowing: if the weighted sum is already a multiple of 10, the check digit is 0, not 10.

Where real UPC data breaks

The Excel leading-zero trap. Store a UPC in a spreadsheet cell formatted as a number and the leading 0 gets dropped — 012345678905 becomes 12345678905, which is no longer a valid UPC-A. Format the column as Text before pasting.

Scanning an EAN-13 into a US-only form. Marketplaces that accept UPC-A will reject 13-digit values starting with anything other than 0. The value may be perfectly valid — it just belongs to the EAN-13 space.

Assuming a valid check digit means a legitimate code. The checksum only proves the string is internally consistent. A code with a perfect check digit can still be an unregistered prefix, another company's item reference, or a typo that happens to checksum correctly. Checksum validation is a filter, not an authorization.

UPC-E: the zero-suppressed variant

Small packages use UPC-E, an 8-digit form that compresses a UPC-A by suppressing zeros according to six known patterns (governed by the manufacturer code's trailing digits and the item reference). Expanding a UPC-E back to UPC-A is deterministic, but the suppression rules are fiddly enough that hand-verification is a bad idea — validate with a tool instead.

Generate without violating GS1

A generator has to pick a prefix for you, and that choice matters. The generator behind our UPC tool draws its default codes from a small fixed set of two-digit prefixes (04, 02, 20, 21, 22, 29) rather than from prefixes chosen at random, so the output is aimed at test data rather than at looking like ordinary retail codes. That is a design choice, not a guarantee: we have not verified how each marketplace treats these ranges, so do not assume a generated code is safe to list with. The tool also has a custom-prefix mode in which you supply your own digits — use your own GS1-licensed prefix there if you are generating real codes.

The tool validates pasted codes and generates batches of distinct random codes — useful when you need a block of test barcodes for label templates or a POS staging environment.

Try it

More checksum guides in this series

Same algorithm family, different data standards: VIN check digits, China ID card numbers, China USCC business codes, and China license plate formats. For passport and ID documents, see the MRZ parser.

If you work with Chinese data standards alongside retail barcodes, the China Compliance Toolkit groups the ID, USCC, plate, VIN and MRZ validators in one place — all running locally in the browser, nothing uploaded.