Luhn Algorithm Validator
Validate credit card numbers, IMEI codes, and other identifiers using the Luhn checksum algorithm.
How to Use the Luhn Algorithm Validator
- Select the mode: Validate number to check an existing number, or Generate check digit to compute a check digit for a partial number.
- Enter the digits in the input field (spaces and dashes are ignored automatically).
- Click Validate or Generate to run the algorithm.
- Review the result and the step-by-step breakdown showing each digit's transformed value and the final sum.
Quick Reference
| From | To |
|---|---|
| Visa | Starts with 4 (16 digits) |
| Mastercard | Starts with 51–55 (16 digits) |
| Amex | Starts with 34 or 37 (15 digits) |
| Discover | Starts with 6011 (16 digits) |
| IMEI | 15 digits, last digit is Luhn check |
| 4532015112830366 | Valid (Visa test number) |
Use Cases
- •Verifying credit card numbers before submitting payment forms in web applications.
- •Checking IMEI numbers to confirm a mobile device identifier is correctly formatted.
- •Generating valid test card numbers for payment gateway integration testing.
- •Learning how checksum algorithms detect data entry errors.
Formula
The Luhn algorithm (also known as the mod-10 algorithm) validates a number by: (1) starting from the rightmost digit and moving left, double every second digit; (2) if doubling produces a number greater than 9, subtract 9; (3) sum all digits; (4) if the total modulo 10 equals 0, the number is valid.
Frequently Asked Questions
What is the Luhn algorithm used for?
The Luhn algorithm is a simple checksum formula used to validate identification numbers such as credit card numbers (Visa, Mastercard, Amex), IMEI numbers for mobile devices, Canadian Social Insurance Numbers, and various other account identifiers. It detects single-digit errors and most transposition errors.
Does passing the Luhn check mean a card number is real?
No. The Luhn check only verifies that the number is formatted correctly — it confirms the check digit matches the rest of the digits. A number can pass Luhn validation and still not correspond to any real, active account. Card issuers perform additional checks for actual authorization.
How is the Luhn check digit calculated?
Remove the last digit (the check digit). Reverse the remaining digits. Double every digit at an odd index (positions 1, 3, 5 …). Subtract 9 from any doubled value greater than 9. Sum all the resulting digits. The check digit is (10 − (sum mod 10)) mod 10.