The Universal Product Code (UPC-A) consists of 12 numerical digits. The first 11 digits are data identifying the manufacturer and the specific product. The 12th digit is the check digit, which is used to verify that the barcode was scanned correctly.
The algorithm used is a "Modulo 10" calculation. Here are the steps used by this calculator:
Sum Odd Positions: Add the digits in the 1st, 3rd, 5th, 7th, 9th, and 11th positions.
Multiply by 3: Take the result from Step 1 and multiply it by 3.
Sum Even Positions: Add the digits in the 2nd, 4th, 6th, 8th, and 10th positions.
Total Sum: Add the results of Step 2 and Step 3.
Find the Check Digit: Determine the smallest number that, when added to the Total Sum, results in a multiple of 10.
Example Calculation
If your 11-digit code is 03600029145:
Odd sum: 0+6+0+2+1+5 = 14
Multiply by 3: 14 × 3 = 42
Even sum: 3+0+0+9+4 = 16
Total: 42 + 16 = 58
Check Digit: 58 + 2 = 60 (Multiple of 10). The check digit is 2.
function calculateUPCCheckDigit() {
var upcInput = document.getElementById("upcInput").value;
var errorDiv = document.getElementById("upcError");
var resultDiv = document.getElementById("upcResult");
var digitDisplay = document.getElementById("digitDisplay");
var fullUpcDisplay = document.getElementById("fullUpcDisplay");
// Reset visibility
errorDiv.style.display = "none";
resultDiv.style.display = "none";
// Validation
if (upcInput.length !== 11) {
errorDiv.style.display = "block";
return;
}
var digits = upcInput.split(").map(Number);
var oddSum = 0;
var evenSum = 0;
// UPC-A logic (1-based index)
// 1st, 3rd, 5th, 7th, 9th, 11th are "odd"
// Array index 0, 2, 4, 6, 8, 10
for (var i = 0; i < 11; i++) {
if (i % 2 === 0) {
oddSum += digits[i];
} else {
evenSum += digits[i];
}
}
var step2 = oddSum * 3;
var step4 = step2 + evenSum;
var checkDigit = (10 – (step4 % 10)) % 10;
// Display results
digitDisplay.innerText = checkDigit;
fullUpcDisplay.innerText = upcInput + checkDigit;
resultDiv.style.display = "block";
}