Guide
The Luhn check: validating card numbers, IMEIs and other identifiers
Hans Peter Luhn, an IBM engineer, patented a simple check-digit formula in 1960. Today it is built into payment card numbers, the IMEI numbers that identify mobile phones, many national identifiers and loyalty cards. Its purpose is modest: to catch the typing mistakes people make when they copy a long number, before it is sent to a server. This validator applies the formula, adds the network and length rules for cards, and can calculate the digit you need.
The algorithm
Start from the rightmost digit, which is the check digit, and move left. Double every second digit. If doubling gives a two-digit number, add its digits together, which is the same as subtracting 9. Add all the digits. If the total is divisible by 10, the number passes. To calculate a check digit for a number without one, apply the same steps to the digits with a zero placeholder and choose the final digit that brings the total to a multiple of 10.
A worked example
Press Sample to check five numbers in card mode; three are valid and two are not. 4111 1111 1111 1111 is a valid Visa test number of 16 digits with check digit 1. 5555-5555-5555-4444 is a valid Mastercard format and 3782 822463 10005 a valid American Express number of 15 digits. 4111 1111 1111 1112 differs in the last digit only: the page says it fails the Luhn check, and that the correct check digit is 1. The last, 490154203237518, passes the arithmetic, but as a card it is rejected because Visa numbers have 13, 16 or 19 digits and this has 15. Switch to the IMEI mode and the same 15 digits validate as an IMEI.
Cards, networks and lengths
The first digits identify the issuer network: 4 for Visa, 51 to 55 and 2221 to 2720 for Mastercard, 34 and 37 for American Express. Each network allows particular lengths. The page reports the network it detects from the prefix, the number of digits and the check digit, and refuses combinations that cannot exist. That catches a number which is Luhn-valid by accident.
IMEI numbers
An International Mobile Equipment Identity has 15 digits: an eight-digit type allocation code that identifies the model, a six-digit serial number and a Luhn check digit. The page shows the three parts. An IMEISV, 16 digits, replaces the check digit with a two-digit software version, so it carries no checksum to verify.
Calculating a check digit
Developers who generate test data or issue their own identifiers can enter the number without its last digit and get the digit to append. Use only test ranges for card-like numbers.
Limits
A passing number may belong to no account, and a failing one may still be a real number typed wrongly. Luhn is no protection against fraud. Please use published test numbers rather than real card numbers on any website; this page works in your browser and sends nothing.
Related tools
- Verhoeff Algorithm Validator catches the swaps that Luhn misses.
- IBAN Validator uses a different, stronger check for bank accounts.
- GTIN, EAN and UPC Check Digit Calculator covers barcodes.
- ISBN Converter and Validator validates book numbers.
Checked against the current version of the Luhn Validator on .

