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).

Creative Commons Attribution/Share-Alike License 3.0 (Unported)

This content is licensed under Creative Commons Attribution/Share-Alike License 3.0 (Unported). That means you may freely redistribute or modify this content under the same license conditions and must attribute the original author by placing a hyperlink from your site to this work https://planetcalc.com/2464/. Also, please do not modify any references to the original work (if any) contained in this content.

The Luhn algorithm was developed by German computer scientist Hans Peter Luhn 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 a digit mistyping. It will detect any single-digit error, as well as almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence 09 to 90 (or vice versa).
The calculator below gives Luhn checksum of the given digit sequence. The sequence is considered valid if the checksum mod 10 equals to zero. It also gives the next check digit to be appended at the end of source sequence to form valid number according Luhn algorithm.

PLANETCALC, Luhn checksum

Luhn checksum

Luhn checksum mod 10
Next check digit

The formula is quite simple: to calculate Luhn checksum you need to sum all odd digits ( calculating from right to left, so last digit is considered N1) plus 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 ckecksum is zero, the whole sequence is valid.
To produce validation digit we can simply append "0" to source sequence and calculate Luhn checksum again. If last digit of the obtained checksum is zero then the validation digit is also zero, otherwise validation digit can be obtained by subtracting last checksum digit from 10.

URL copied to clipboard
Creative Commons Attribution/Share-Alike License 3.0 (Unported) PLANETCALC, Luhn algorithm