Luhn Algorithm Calculator
Our Luhn algorithm calculator can test a number with Luhn validation and find the check digit for a given number. This tool has different applications such as:
- Gift card number generator 🎁;
- Credit card number checker 💳; and
- Many more!
Keep reading to learn its use cases and find the answer to questions such as 'What is the Luhn algorithm?', 'What is Luhn validation?' or 'How do I calculate check digit with Luhn algorithm?'.
Let's dive right in!
What is the Luhn algorithm?
The Luhn algorithm, also known as mod 10, is a method of validating numbers using simple operations on each digit. It can detect common typing errors, and because of that, companies use it as pre-validation with credit card numbers.
It was created by the German computer scientist Hans Peter Luhn, who patented it in 1960 while working at IBM. The algorithm is in the public domain and is now specified in the ISO/IEC 7812-1 standard, which is why it turns up in so many numbering schemes at once.
The Luhn algorithm catches every single-digit error and almost all transposition errors — the classic slip of typing ...21... instead of ...12.... However, it is not perfect. It cannot catch the transposition of 09 ↔ 90, and it cannot tell apart certain twin-digit errors such as 22 ↔ 55, 33 ↔ 66 and 44 ↔ 77.
⚠️ It is worth being clear about what this buys you: the Luhn check is a typo detector, not a security feature. A number that passes Luhn validation is well-formed — it is not proof that the account exists, that it has any money behind it, or that it belongs to whoever typed it. Only the issuing bank can tell you that.
Now, let's see how a simple algorithm can act as a credit card number checker.
How does the Luhn algorithm work?
The Luhn algorithm works by taking a number and doing some basic math operations to every digit except the last one. This last digit is called the check digit. According to the Luhn algorithm, if the result of the operations and the check digit are equal, the number is valid.
Credit card, IMEI, and gift card numbers are created so that they pass a Luhn digit check — i.e., after applying the operations to every digit, the result matches the last one.
The rule that every valid number must satisfy is:
(sum of all processed digits) mod 10 = 0
Everything else is bookkeeping. Starting from the rightmost digit (the check digit) and walking left, you double every second digit. If doubling gives a two-digit number, you add its digits together — which is the same as subtracting 9, since 14 → 1 + 4 = 5 and 14 − 9 = 5. Then you add up everything you're left with. If the total ends in a 0, the number passes.
Step by step on how to calculate the Luhn check digit
Let's find the check digit for the number 7992739871. Because we are generating the check digit rather than verifying one, the doubling starts at the rightmost digit of what we have — the empty slot on the right is where the check digit will go.
- Write the number down and start from the rightmost digit.
- Double every second digit, moving leftwards.
- If a doubled digit is greater than 9, subtract 9 from it (identical to adding its two digits).
- Sum every resulting value.
- The check digit is whatever it takes to push that sum up to the next multiple of 10: check digit = (10 − (sum mod 10)) mod 10.
| Digit | Action | Result | Value added |
|---|---|---|---|
| 7 | Keep | — | 7 |
| 9 | Double | 9 × 2 = 18 → 18 − 9 = 9 | 9 |
| 9 | Keep | — | 9 |
| 2 | Double | 2 × 2 = 4 | 4 |
| 7 | Keep | — | 7 |
| 3 | Double | 3 × 2 = 6 | 6 |
| 9 | Keep | — | 9 |
| 8 | Double | 8 × 2 = 16 → 16 − 9 = 7 | 7 |
| 7 | Keep | — | 7 |
| 1 | Double | 1 × 2 = 2 | 2 |
| Total | 67 |
The sum is 67, so the check digit is:
(10 − (67 mod 10)) mod 10 = (10 − 7) mod 10 = 3
The complete number is therefore 79927398713. Let's confirm it: validating the full number adds the check digit to the pile, giving 67 + 3 = 70, and 70 mod 10 = 0. ✅ It passes.
💡 Notice the parity flip. When you validate a complete number, the rightmost digit is the check digit and is never doubled. When you generate a check digit, the rightmost digit you have is one place further left, so it is doubled. Getting this backwards is by far the most common mistake people make when implementing Luhn by hand — the calculator handles it for you.
Using the Luhn algorithm calculator – credit card number checker
The calculator runs in two modes:
- Validate a number — paste a complete number, including its check digit. You get a verdict, the full step-by-step table, the sum, the mod 10 test, and a comparison of the actual check digit against the expected one. If they disagree, you're shown the corrected number.
- Find the check digit — enter a number without its check digit and the calculator appends the right one, giving you a complete, Luhn-valid number.
In either mode you can type the number with spaces, dashes or dots —
4539 1488 0343 6467 works just as well as 4539148803436467. Numbers up to
30 digits are supported, which comfortably covers every card, IMEI and gift card format
in use.
When the number looks like a payment card, the calculator also identifies the card network from its opening digits (the IIN, or issuer identification number) and tells you whether the length matches that network's specification:
| Network | Starts with | Length |
|---|---|---|
| Visa | 4 | 13, 16, 19 |
| Mastercard | 51–55, 2221–2720 | 16 |
| American Express | 34, 37 | 15 |
| Mir | 2200–2204 | 16–19 |
| Discover | 6011, 65, 644–649 | 16–19 |
| Diners Club | 300–305, 36, 38 | 14–19 |
| JCB | 3528–3589 | 16–19 |
| UnionPay | 62 | 16–19 |
| Maestro | 5018, 5020, 5038, 5893, 6304, 6759, 6761–6763 | 12–19 |
🔒 A note on privacy and safety: use test numbers, not a real card you own. The numbers in this page (4539 1488 0343 6467, 4111 1111 1111 1111, and so on) are the publicly published test numbers the card networks hand out for exactly this purpose. They are Luhn-valid but belong to no account.
Gift card number generator 🎁
A Luhn check digit is the cheapest possible defence against a customer reading a code wrong over the phone, so gift card, loyalty and voucher programmes lean on it constantly. That's what the batch quantity field is for: set it above 1 in Find the check digit mode and the calculator issues a run of sequential numbers — up to 50 at a time — each with its own correctly computed check digit.
Because the numbers run in sequence, the check digits do not. That's the whole point: consecutive codes get uncorrelated final digits, so a single mistyped character almost never lands you on a neighbouring valid card.
⚠️ Sequential numbering is fine for validation, but it is guessable. Real-world gift card programmes pair the Luhn digit with a random component or a separate PIN so that knowing one code doesn't hand you the next one.
Units, currencies, and the value behind a number
A number that passes Luhn validation usually has something attached to it — a balance, a limit, a quantity. The optional value per number field lets you attach that, tagged with a unit of your choice, and the calculator multiplies it across the batch:
Total value = quantity × value per number
- World currencies — USD ($), RUB (₽), EUR (€), GBP (£), JPY (¥), CNY (¥), and 14 more. A run of 50 gift cards at ₽1,000 each represents ₽50,000 of issued value.
- Metric units — m, km, cm, mm, kg, g, t, L, mL, m², m³, °C. Handy when the number is an asset or batch tag: 50 tagged drums at 200 L each is 10,000 L.
- US / imperial units — in, ft, yd, mi, lb, oz, gal, fl oz, ft², ft³, °F. The same 50 drums at 55 gal each come to 2,750 gal.
Leave the field blank and the calculator just reports the Luhn result on its own.
Where else is the Luhn algorithm used?
- Payment cards. Every major network's numbers are Luhn-valid, which is why a checkout form can tell you that you fat-fingered your card before talking to a bank.
- IMEI numbers. The 15-digit identifier of every mobile phone ends in a Luhn check digit.
- Gift cards, vouchers, and loyalty codes.
- National identifiers. Canadian Social Insurance Numbers, South African ID numbers, Greek Social Security numbers, and Israeli ID numbers all use Luhn.
- NPI numbers. The US National Provider Identifier for healthcare providers.
- SIM and ICCID numbers on the cards inside your phone.
How to use this calculator
- Pick a mode: Validate a number or Find the check digit.
- Enter your number — spaces, dashes and dots are ignored, so paste it however you have it.
- In generate mode, optionally raise the batch quantity to issue a run of sequential numbers.
- Optionally add a value per number and a unit or currency.
- Hit Calculate to see the verdict, the digit-by-digit table, the mod 10 test, the check digit comparison, and the detected card network.
FAQs
What is the Luhn algorithm? It's a checksum formula — also called mod 10 — that validates identification numbers by doubling every second digit from the right, summing everything, and requiring the total to be a multiple of 10. Hans Peter Luhn devised it at IBM in 1960.
What is Luhn validation? It's the act of running the algorithm over a complete number to see whether it ends in a valid check digit. If the processed digits sum to a multiple of 10, the number passes.
How do I calculate the check digit with the Luhn algorithm? Drop the check digit slot, double every second digit starting from the rightmost digit you have, subtract 9 from any result over 9, add everything up, then take (10 − (sum mod 10)) mod 10. For 7992739871 the sum is 67, so the check digit is 3.
Does passing the Luhn check mean a credit card is real? No. It only means the number is well-formed and free of common typos. Whether the account exists, is active, or has funds is something only the issuing bank can answer.
What errors can the Luhn algorithm not detect? It misses the transposition 09 ↔ 90, and it cannot distinguish the twin-digit swaps 22 ↔ 55, 33 ↔ 66 and 44 ↔ 77. Every single-digit error and every other adjacent transposition is caught.
Why subtract 9 instead of adding the digits? They're the same thing. Doubling a digit 0–9 gives at most 18, so the result only ever has two digits, and for any two-digit number between 10 and 18 the digit sum equals the number minus 9. Subtracting is just faster.
Can the check digit be 0? Yes. If the sum of the processed digits is already a multiple of 10, the check digit is 0 — that's what the outer mod 10 in the formula is for.
Is the Luhn algorithm secure? Not at all, and it was never meant to be. It's public, trivial to compute, and anyone can generate a passing number. It defends against accidents, not attackers.
Do leading zeros matter? Yes. A number is a string of digits, not a quantity, so 0123 and 123 are different numbers with different check digits. This calculator preserves any leading zeros you type.