Understanding the Luhn check digit calculator — concept and principle
The Luhn algorithm, also called the mod 10 algorithm, adds one check digit to the end of an identification number so that typing errors can be caught immediately. It is used for payment card numbers (as specified in ISO/IEC 7812), IMEI numbers of mobile phones and many account or membership numbers. This calculator gives the check digit to append to your digits and tells you whether the number as entered already passes the Luhn test.
How it is calculated
- Starting from the rightmost digit of the number that will be checked, number the positions 1, 2, 3 … from right to left.
- Double every digit in an even position. If doubling gives more than 9, subtract 9 (the same as adding its two digits, e.g. 16 → 1 + 6 = 7).
- Add all the digits, doubled and undoubled.
- A number is valid when this sum is a multiple of 10.
- To find a missing check digit, append 0, compute the sum S, and take (10 − S mod 10) mod 10.
Non-digit characters such as spaces and hyphens are ignored.
The principle
Doubling with "subtract 9" maps the digits 0–9 to 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, a permutation, so changing any single digit always changes the sum mod 10 and is detected. Alternating the weight between 1 and 2 also catches swaps of two adjacent digits, because the swapped digits end up with different weights. The one adjacent swap it misses is 09 ↔ 90, since both contribute 9. H. P. Luhn of IBM patented the method in 1960.
Worked example
- Input: 7992739871.
- Append 0: 79927398710. From the right, the doubled digits are 1, 8, 3, 2, 9, giving 2, 16 → 7, 6, 4, 18 → 9, which sum to 28.
- The undoubled digits are 0, 7, 9, 7, 9, 7, which sum to 39. Total S = 67.
- Check digit = (10 − 67 mod 10) mod 10 = (10 − 7) mod 10 = 3, so the full number is 79927398713.
- The input itself: taking its last digit 1 as the check digit, the sum is 56, which is not a multiple of 10, so it is invalid.
How to read the result
"Valid" means only that the digits are internally consistent. On average, a random sequence passes one time in ten, so the test filters typing mistakes but says nothing about whether an account exists or is active. If your number is reported invalid, the most likely causes are one wrong digit, two swapped neighbours or a missing digit.
Common mistakes
- Doubling from the left instead of from the right; the positions depend on the length.
- Forgetting to append a placeholder before computing a new check digit, which shifts every weight.
- Treating a valid Luhn result as proof that a card number is real.
Frequently asked questions
Can Luhn correct an error?
No. It only shows that something is wrong, not which digit.
Does Luhn catch every transposition?
It catches every adjacent swap except 09 ↔ 90; swaps of digits further apart may go undetected.
Are IMEI numbers Luhn-checked?
Yes, the 15th digit of an IMEI is a Luhn check digit over the first 14.
Sources: ISO/IEC 7812-1, Identification cards — Identification of issuers — Part 1: Numbering system · H. P. Luhn, Computer for Verifying Numbers, U.S. Patent 2,950,048 (1960)