# Luhn algorithm

Calculates digit sequence checksum using Luhn algorithm (mod 10), calculates validation digit (the digit to be appended to the digit sequence to make whole sequence checksum equal to zero).

German computer scientist Hans Peter Luhn developed the Luhn algorithm in 1954. It calculates simple checksum formula used to validate identification numbers such as credit card numbers. The algorithm was designed to protect against accidental errors, such as digit mistyping. It will detect any single-digit error, as well as almost all transpositions of adjacent digits. However, it will not detect transposition of the two-digit sequence 09 to 90 (or vice versa).
The calculator below gives Luhn's checksum of the given digit sequence. The sequence is considered valid if the checksum mod 10 equals zero. It also gives the next check digit to be appended at the end of the source sequence to form a valid number according to the Luhn algorithm. #### Luhn checksum

Luhn checksum mod 10

Next check digit

The formula is quite simple: to calculate the Luhn checksum, you need to sum all odd digits ( calculating from right to left, so the last digit is considered N1) plus the sum of all even digits multiplied by 2 (if the product of multiplication is greater than 9 you must subtract 9). If the last digit of the checksum is zero, the whole sequence is valid.
To produce a validation digit, we can append "0" to the source sequence and calculate the Luhn checksum again. If the last digit of the obtained checksum is zero, then the validation digit is also zero; otherwise, the validation digit can be obtained by subtracting the last checksum digit from 10.

URL copied to clipboard
PLANETCALC, Luhn algorithm