Luhn Algorithm is a simple checksum formula used to validate credit card numbers, IMEI numbers etc. This algorithm also known as modulus 10 or mod 10 algorithm. It was created by IBM scientist Hans Peter Luhn.
The formula verifies a number against its included check digit, which is usually appended to a partial account number to generate the full account number. This account number must pass the following test:
- From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if product of this doubling operation is greater than 9 (e.g., 7 * 2 = 14).
- Sum the digits of the products (e.g., 10: 1 + 0 = 1, 14: 1 + 4 = 5) together with the undoubled digits from the original number.
- If the total modulo 10 is equal to 0 (if the total ends in zero) then the number is valid according to the Luhn formula; else it is not valid.
The following picture represents the credit card algorithm clearly.