Last updated
What Is a UPC Code?
A UPC (Universal Product Code) is a 12-digit barcode used on virtually every retail product in North America. The last digit is a check digit calculated from the first 11 digits. The UPC Validator verifies this check digit to confirm a UPC is valid, and supports UPC-A, UPC-E, and EAN-13 formats.
UPC-A Structure
UPC-A: 0 12345 67890 5
Position Digits Meaning
-------- ------ -------
1 0 Number system character
2–6 12345 Manufacturer code (GS1 assigned)
7–11 67890 Product code (manufacturer assigned)
12 5 Check digit (calculated)
Number system characters:
0, 1 Regular products
2 Variable-weight items (produce, deli)
3 Pharmaceuticals and health products
4 In-store use (loyalty cards, coupons)
5 Coupons
6, 7 Regular products
Check Digit Calculation
The check digit algorithm uses a weighted sum:
UPC: 0 1 2 3 4 5 6 7 8 9 0 ?
Step 1: Multiply odd positions by 3, even positions by 1
Position: 1 2 3 4 5 6 7 8 9 10 11
Digit: 0 1 2 3 4 5 6 7 8 9 0
Weight: 3 1 3 1 3 1 3 1 3 1 3
Product: 0 1 6 3 12 5 18 7 24 9 0
Step 2: Sum all products
0 + 1 + 6 + 3 + 12 + 5 + 18 + 7 + 24 + 9 + 0 = 85
Step 3: Check digit = (10 - (sum mod 10)) mod 10
(10 - (85 mod 10)) mod 10 = (10 - 5) mod 10 = 5
Check digit: 5
Full UPC: 012345678905 ✓ Valid
Validating a UPC-A
Input: 012345678905
Validation result:
Format: UPC-A (12 digits) ✓
All digits numeric: ✓
Length: 12 ✓
Check digit calculation:
Expected: 5
Actual: 5 ✓
Status: VALID ✓
---
Input: 012345678906
Validation result:
Format: UPC-A (12 digits) ✓
Check digit calculation:
Expected: 5
Actual: 6 ✗
Status: INVALID — check digit mismatch
Correct UPC should be: 012345678905
UPC-E (Compressed Format)
UPC-E is a 6-digit compressed format for small packages. It expands to a full 12-digit UPC-A:
UPC-E: 425261
Expansion rules (based on last digit):
Last digit 0: XXNNN0 → 0 + XX + 00000 + NNN
Last digit 1: XXNNN1 → 0 + XX + 10000 + NNN
Last digit 2: XXNNN2 → 0 + XX + 20000 + NNN
Last digit 3: XXXNN3 → 0 + XXX + 00000 + NN
Last digit 4: XXXXN4 → 0 + XXXX + 00000 + N
Last digit 5: XXXXX5 → 0 + XXXXX + 00005
Last digit 6: XXXXX6 → 0 + XXXXX + 00006
...
UPC-E 425261 expands to:
0 42526 00001 → 042526000015 (UPC-A)
Validate the expanded UPC-A check digit to verify
EAN-13 Validation
EAN-13 is the international extension of UPC-A with a 13th digit (country code prefix):
EAN-13: 5 012345 678900
Structure:
Digits 1–3: Country/prefix code (501 = UK)
Digits 4–7: Manufacturer code
Digits 8–12: Product code
Digit 13: Check digit
Check digit algorithm (same as UPC but positions reversed):
Odd positions × 1, even positions × 3
Input: 5012345678900
Expected check digit: 0
Actual check digit: 0
Status: VALID ✓
Batch UPC Validation
Validate an entire product catalog at once:
Input (one UPC per line):
012345678905
036000291452
012000161155
012345678906
049000028911
Results:
012345678905 ✓ Valid
036000291452 ✓ Valid
012000161155 ✓ Valid
012345678906 ✗ Invalid — check digit error (expected 5, got 6)
049000028911 ✓ Valid
Summary: 4 valid, 1 invalid
Implementing UPC Validation in Code
// JavaScript UPC-A check digit validator
function validateUPC(upc) {
if (!/^\d{12}$/.test(upc)) return false;
const digits = upc.split('').map(Number);
const sum = digits.slice(0, 11).reduce((acc, digit, i) => {
return acc + digit * (i % 2 === 0 ? 3 : 1);
}, 0);
const checkDigit = (10 - (sum % 10)) % 10;
return checkDigit === digits[11];
}
console.log(validateUPC('012345678905')); // true
console.log(validateUPC('012345678906')); // false
// Python
def validate_upc(upc):
if not upc.isdigit() or len(upc) != 12:
return False
digits = [int(d) for d in upc]
total = sum(d * (3 if i % 2 == 0 else 1) for i, d in enumerate(digits[:11]))
return (10 - total % 10) % 10 == digits[11]
Common UPC Errors
- Transposed digits — two adjacent digits swapped during manual entry
- Missing leading zero — UPC-A always starts with a digit, often 0
- UPC-E confused with UPC-A — 6-digit vs 12-digit format
- EAN-13 submitted as UPC-A — 13 digits vs 12 digits
- Corrupted barcode scan — scanner misreads a digit
Use Cases
- Validating supplier product feeds before importing to your catalog
- Point-of-sale systems verifying scanned barcodes
- E-commerce platforms checking product data quality
- Inventory management systems preventing bad data entry
- Developers implementing barcode validation in retail applications