The last digit of every EAN or UPC is not part of the product number — it is a checksum computed from the other digits, and it is why a register beeps angrily at a mistyped code instead of charging you for the wrong product.
For EAN-13, take the first 12 digits. ① Multiply each digit alternately by 1 and 3, starting with 1 at the left. ② Sum all the products. ③ Find the remainder of that sum ÷ 10. ④ The check digit is 10 − remainder (or 0 if the remainder is 0).
Digits 5,9,0,1,2,3,4,1,2,3,4,5 with weights 1,3,1,3…: 5+27+0+3+2+9+4+3+2+9+4+15 = 83. 83 mod 10 = 3, so the check digit is 10 − 3 = 7, giving 5901234123457. Type any single digit wrong and the recomputed checksum almost certainly disagrees — the decoder rejects the scan rather than passing bad data to the till.
Mod-10 catches all single-digit errors and most adjacent-digit swaps (the classic typing mistakes). It is not cryptographic and not a registration: a number with a valid check digit is merely well-formed, which is why "valid-looking" barcodes from dubious sources can still be unlicensed — the math checks structure, GS1 checks ownership.
Every competent generator does it for you: our barcode generator takes the 12 digits, appends the correct check digit, and — more usefully — when you paste a full 13-digit code with a wrong final digit, it tells you which digit it expected, instantly flagging transcription errors in supplier spreadsheets.