Introduction
Need to verify a credit card number, IMEI, or other identification number? The Luhn algorithm, also known as "modulus 10" or "mod 10," is the checksum formula used by virtually every credit card system and many other numbering schemes to catch typing errors. This tool validates whether a number passes the Luhn check and can also generate the correct check digit for a partial number. Paste your number below and the result appears instantly with a step-by-step breakdown of the calculation. Everything runs in your browser.
What this tool does
- Validates whether a number passes the Luhn mod 10 checksum check used by credit cards, IMEI numbers, and other identification systems.
- Generates the correct Luhn check digit for a partial number so you can construct a valid full number.
- Shows the step-by-step calculation: which digits were doubled, which were left alone, and how the final sum was computed.
- Detects the likely number type (Visa, Mastercard, Amex, Discover, IMEI) based on the length and prefix of the input.
- Accepts numbers with spaces, hyphens, or no separators. Non-digit characters are stripped automatically.
- Runs entirely client-side. No number you enter is sent to any server.
How this tool works
The tool has two modes. Validate mode checks whether a complete number passes the Luhn algorithm. Generate mode computes the check digit you need to append to a partial number to make it Luhn-valid.
In Validate mode, the tool strips spaces and hyphens from your input, extracts the digits, and runs the Luhn algorithm. Starting from the rightmost digit and moving left, every second digit is doubled. If doubling produces a value greater than 9, the tool subtracts 9 (equivalent to adding the two digits of the result together). All digits, doubled and undoubled, are summed. If the sum modulo 10 is 0, the number is valid.
In Generate mode, the tool appends a placeholder 0 to your input, runs the validation algorithm, and computes the check digit as (10 - (sum mod 10)) mod 10. The full number with the correct check digit is displayed for you to copy.
The step-by-step table shows each digit, whether it was doubled, the result after doubling (with the subtract-9 step shown when applicable), and the final value used in the sum. This makes it easy to verify the calculation by hand or teach the algorithm in a classroom setting.
How the cipher or encoding works
The Luhn algorithm was patented by IBM scientist Hans Peter Luhn on August 23, 1960, as U.S. patent 2,950,048. It is specified in ISO/IEC 7812-1, the standard that defines the numbering system for identification cards, including credit cards. The algorithm is in the public domain and is widely used across the financial and telecommunications industries.
The algorithm works by applying a simple weighting scheme to the digits of a number. Starting from the rightmost digit (the check digit) and moving left, every second digit is doubled. If the doubled value exceeds 9, subtract 9. This is equivalent to adding the two digits of the result: for example, doubling 7 gives 14, and 1 + 4 = 5, which is the same as 14 - 9 = 5. All digits, both doubled and undoubled, are then summed. If the total is a multiple of 10, the number passes the check.
The algorithm detects all single-digit errors and most adjacent digit transpositions. It does not detect transpositions of adjacent digits that differ by 5 (for example, swapping 0 and 5, or 1 and 6), because the Luhn weighting happens to produce the same checksum for those pairs. It also does not detect certain multi-digit errors. The algorithm was designed to catch accidental typing errors, not to provide cryptographic security.
Credit card numbers are the most common application. The first digit is the Major Industry Identifier (MII): 4 for Visa, 5 for Mastercard, 3 for Amex, 6 for Discover. The next 5 to 7 digits identify the issuing bank. The remaining digits (except the last) are the account number. The final digit is the Luhn check digit, computed by the issuer when the card is created.
IMEI (International Mobile Equipment Identity) numbers also use the Luhn algorithm. A 15-digit IMEI consists of an 8-digit Type Allocation Code, a 6-digit serial number, and a 1-digit Luhn check digit. The 3GPP specification defines the IMEI check digit computation in Annex A of TS 02.16, referencing the same ISO/IEC 7812 standard used for credit cards.
Other applications include National Provider Identifier (NPI) numbers in the United States healthcare system, Canadian Social Insurance Numbers, and various survey and tracking numbers. The algorithm's simplicity and effectiveness at catching common transcription errors make it a standard choice for any system where humans manually enter long digit sequences.
How to use this tool
- Paste your number into the input field. Spaces and hyphens are accepted and stripped automatically.
- Keep the mode on Validate to check whether a complete number passes the Luhn check, or switch to Generate to compute the check digit for a partial number.
- Review the result card. In Validate mode, it shows VALID or INVALID with the sum and modulo. In Generate mode, it shows the check digit and the full number.
- Read the step-by-step table to see which digits were doubled, what values resulted, and how the final sum was computed.
- Click Copy to grab the result, the check digit, or the full number for use in your application or document.
Real-world examples
Validating a credit card number
A developer is building a checkout form and wants to catch typos before sending the card number to the payment processor. They paste 4532015112830366 into the validator. The tool shows VALID with a sum of 70 and modulo 0. The step-by-step table confirms that every second digit from the right was doubled, values over 9 had 9 subtracted, and the total is a multiple of 10. The developer adds a client-side Luhn check to their form to reject invalid numbers before submission.
Generating a check digit for an IMEI
A device manufacturer needs to compute the Luhn check digit for a new IMEI with the first 14 digits 49015420323751. They paste the 14 digits into the tool in Generate mode. The tool appends a placeholder 0, runs the algorithm, computes a sum of 52, and returns check digit (10 - (52 mod 10)) mod 10 = (10 - 2) mod 10 = 8. The full IMEI is 490154203237518. The manufacturer verifies this by switching to Validate mode and confirming the 15-digit number passes.
Teaching the Luhn algorithm in a classroom
A computer science professor uses the tool to demonstrate the Luhn algorithm to students. They paste 79927398713 into the validator and project the step-by-step table on the screen. Students can see that the digits 7, 9, 7, 9, 7 were doubled (every second digit from the right), the doubled values 9*2=18->9, 7*2=14->5, and so on, and the final sum is 70. The professor then asks students to compute the check digit for 7992739871 by hand and verify their answer using the Generate mode.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| Luhn algorithm (mod 10) | O(n) single pass, no key | Credit cards, IMEI, NPI, Canadian SIN |
| Verhoeff algorithm | O(n) with permutation table | Aadhaar numbers, catches all transpositions |
| ISBN-10 check digit | O(n) weighted sum mod 11 | Book identification numbers |
| CRC32 | O(n) polynomial division | File integrity, network checksums |
Limitations or considerations
The Luhn algorithm detects all single-digit errors and most adjacent digit transpositions, but it does not catch every error. Transpositions of adjacent digits that differ by 5 (such as 09 becoming 90, or 18 becoming 81) are not detected. The algorithm provides no cryptographic security and can be trivially circumvented by anyone who knows the formula. It is designed to catch accidental typing errors, not deliberate fraud. This tool does not check whether a credit card number is actually issued or has available funds. It only checks whether the number is structurally valid according to the Luhn formula. For payment processing, always use a proper payment gateway that performs authorization with the card issuer.
Frequently asked questions
What is the Luhn algorithm?
The Luhn algorithm, also called "modulus 10" or "mod 10," is a checksum formula used to validate identification numbers. It was patented by IBM scientist Hans Peter Luhn in 1960 and is specified in ISO/IEC 7812-1. The algorithm doubles every second digit from the right, subtracts 9 from any doubled value over 9, sums all digits, and checks whether the total is a multiple of 10. Credit card numbers, IMEI numbers, and many other identification numbers use it to catch typing errors.
How do I check if a credit card number is valid?
Paste the number into the tool in Validate mode. The tool strips spaces and hyphens, runs the Luhn algorithm, and shows VALID or INVALID. A valid result means the number passes the Luhn checksum, which catches most typing errors. It does not mean the card is actually issued or has funds. For payment processing, use a payment gateway to perform authorization with the card issuer.
How is the Luhn check digit calculated?
Append a 0 to the end of the number, run the Luhn validation algorithm on the extended number, and compute (10 - (sum mod 10)) mod 10. That value is the check digit. For example, if the sum with the placeholder 0 is 58, the check digit is (10 - 8) mod 10 = 2. Append 2 to the original number to produce a Luhn-valid number.
What numbers use the Luhn algorithm?
Credit card numbers (Visa, Mastercard, Amex, Discover), IMEI numbers for mobile devices, National Provider Identifier (NPI) numbers in US healthcare, Canadian Social Insurance Numbers, and various survey and tracking numbers. The algorithm is specified in ISO/IEC 7812-1 and is the standard checksum for identification numbers in the financial and telecommunications industries.
Does the Luhn algorithm detect all errors?
No. It detects all single-digit errors and most adjacent digit transpositions, but it misses transpositions of digits that differ by 5 (such as swapping 0 and 5, or 1 and 6). The Verhoeff algorithm and the Damm algorithm catch all single-digit errors and all transpositions, but they are more complex and less widely deployed. Luhn remains the industry standard for credit cards because its simplicity outweighs the small gap in error detection.
Conclusion
The Luhn algorithm is the backbone of credit card validation and identification number checking. This tool handles both validation and check digit generation with a step-by-step breakdown so you can verify the math yourself. For related checksum tools, see the checksum calculator and hash generators.