Luhn Calculator - Validate or Generate Mod-10 Check Digits
Use this Luhn calculator to validate any number against the mod-10 checksum or generate the check digit for a payload. Shows the digit, sum, and full number.
Luhn Calculator
Results
What Is a Luhn Calculator?
A Luhn calculator runs the Luhn algorithm, also called the mod 10 or modulus 10 algorithm, against any number. It either validates the number by checking its last digit against the expected check digit, or generates the correct check digit to append to a payload. The algorithm is the procedure used by credit card networks, mobile carriers, and many government identification systems to catch typos before a number is sent.
- • Credit card number pre-validation: Check that a 13 to 19 digit card number passes the mod-10 checksum before sending it to a payment gateway.
- • IMEI number verification: Validate the 15-digit IMEI on a phone, required to register a device on most cellular networks.
- • SIN, NPI, and ID number checks: Test Canadian SIN, US NPI, and similar IDs that use a Luhn check digit.
- • Generate Luhn-valid test payloads: Build test card numbers, gift card codes, or sample IDs without re-implementing the algorithm.
The Luhn algorithm is not a cryptographic check, so it cannot tell you whether a card is active. It can tell you whether the digits were typed or transmitted correctly, which is why almost every payment system runs it as the first gate before any database lookup.
When you only need the leftover of a division on its own, Modulo Calculator returns the mod without the rest of the Luhn machinery.
How the Luhn Calculator Works
The calculator runs the Luhn algorithm in two passes: one to compute the Luhn sum from the rightmost digit of the payload, and one to compare that sum with the existing check digit (validate) or to format the appended check digit (generate).
- inputNumber: The digit string entered by the user. Non-digit characters such as spaces, hyphens, parentheses, and slashes are stripped before processing.
- method: Validate (run the algorithm on the input with its existing last digit and compare) or generate (treat the input as the payload, run the algorithm, and append the resulting check digit to form a full valid number).
- sum: Total of every digit in the payload after the doubling-and-reduction step. A Luhn-valid number always makes sum a multiple of 10.
- checkDigit: Single 0-9 digit equal to (10 - sum mod 10) mod 10. This is what must appear at the end of a Luhn-valid number.
The doubling-and-reduction step is equivalent to splitting any doubled digit greater than 9 into its tens and ones and adding both; the calculator uses the subtract-9 form because it only touches the doubled values.
The mod-10 step at the end is also why the algorithm is called the modulus 10 algorithm: a Luhn-valid number is one whose Luhn sum plus its check digit is a multiple of 10.
Validate 4111111111111111
Method = Validate, input = 4111111111111111
Drop the last digit to get payload 411111111111111. From the right, double every second digit; the trailing 4 becomes 8, the seven 1s in odd positions become 2 each, and the seven 1s in even positions stay 1. Sum 8 + 7*2 + 7*1 = 29, then add the check digit 1 to reach 30.
Validity: Valid. Luhn sum: 29. Check digit: 1. Full number: 4111111111111111.
The trailing 1 matches the computed check digit 1, and 29 + 1 = 30 is the mod-10 invariant.
Generate the check digit for payload 1789372997 (Wikipedia worked example)
Method = Generate, input = 1789372997
Right-to-left, double every second digit of 1789372997: 7*2=14 (1+4=5), 9, 9*2=18 (1+8=9), 2, 7*2=14 (1+4=5), 3, 9*2=18 (1+8=9), 8, 7*2=14 (1+4=5), 1. Sum: 5+9+9+2+5+3+9+8+5+1 = 56.
Validity: Valid. Luhn sum: 56. Check digit: 4. Full number: 17893729974.
Appending 4 produces 17893729974, the same number the Wikipedia example shows.
According to Wikipedia - Luhn algorithm, the Luhn algorithm (also called the modulus 10 or mod 10 algorithm) was published in US patent 2,950,048A on 23 August 1960 and is specified in ISO/IEC 7812-1.
For a different kind of single-number property test, Prime Number Checker reports whether a value is prime rather than Luhn-valid.
Key Concepts Behind the Luhn Algorithm
Four short ideas explain why the algorithm works the way it does and where its blind spots are. Once these are clear, the output panel and the trace read like a checklist rather than a black box.
Mod 10 invariant
A Luhn-valid number is one whose sum of doubled-and-reduced digits plus the check digit equals a multiple of 10. The algorithm is a convenient way to compute and verify that invariant without storing the whole number.
Right-to-left doubling pattern
The doubling always starts at the rightmost digit of the payload, then alternates. This keeps the check digit at the end and matches the way card numbers are read off a magstripe or printed form.
Check digit, not cryptographic hash
The Luhn check digit is a small fixed-size value designed to catch typos and transpositions. It is not a hash, MAC, or signature, so it cannot protect against deliberate tampering.
Known blind spots
The algorithm catches all single-digit errors and almost all adjacent transpositions, but it cannot detect every pair swap. The classic example is 09 transposed to 90, and the twin pairs 22-55, 33-66, and 44-77.
Knowing the blind spots matters in practice. If two Luhn-valid numbers differ only in a 09/90 swap, the Luhn check treats both as valid and the application layer has to catch the error with another rule.
The mod-10 invariant also makes the check digit unique. For any given payload there is exactly one digit 0-9 that, appended at the end, makes the total a multiple of 10.
For a different check-digit scheme that follows the same validate-or-generate pattern, the GTIN Check Digit Calculator handles UPC, EAN-13, and GTIN-14 barcodes with 3-1 weighted steps.
How to Use This Luhn Calculator
Enter the number, pick a method, and read the result. The calculator updates as you type, so you can paste a card number and see the validity decision live.
- 1 Enter the number: Type or paste the digit string. The calculator strips every non-digit character (spaces, hyphens, parentheses, slashes, letters) before running the Luhn check.
- 2 Pick a method: Choose Validate to compare the existing last digit with the algorithm output, or Generate the check digit to treat the input as a payload with no check digit yet and append a new one that makes the number Luhn-valid.
- 3 Read the validity and check digit: Validity says Valid when the algorithm agrees with the last digit and Invalid otherwise. Generate always shows Valid because the appended digit satisfies the check. The Luhn Check Digit row shows the 0-9 digit the algorithm produces.
- 4 Check the Luhn sum: The Luhn Sum row shows the total of every doubled-and-reduced digit. Add the check digit to it and you should always get a multiple of 10 for a valid number.
- 5 Copy the full Luhn-valid number: The Full Luhn-Valid Number row gives you the digits-only form of the input, or the payload plus the new check digit in generate mode. Use it in a payment form or test file.
Example: a QA engineer needs a Luhn-valid test card number. They enter 424242424242424, pick Generate, and the result panel shows check digit 2, Luhn sum 78, and the full number 4242424242424242. Validity reads Valid because 78 + 2 = 80, a multiple of 10. They copy the full number into the test fixture.
When the rest of the workflow needs to translate the digit string into another base, the Base Converter moves the same digits between binary, octal, decimal, and hexadecimal with a positional breakdown.
Benefits of Using This Luhn Calculator
The Luhn check is a small algorithm, but a calculator that runs it consistently turns out to be useful in more places than its size suggests.
- • Removes off-by-one doubling mistakes: The most common Luhn mistakes are starting the doubling from the wrong end or miscounting which digits to double. The calculator follows the right-to-left pattern automatically.
- • Handles both check and generate in one tool: Most reference pages only show one of the two modes. The method switch lets you validate, generate, and copy the result without leaving the page.
- • Accepts messy input: Spaces, hyphens, parentheses, and pasted card formatting are stripped before the algorithm runs, so you can paste from an email without cleaning the digits first.
- • Shows the Luhn sum and not just the verdict: The Luhn sum is reported alongside the verdict, so you can confirm the mod-10 invariant by hand. Useful for teaching, code reviews, and debugging libraries.
- • Free and offline-friendly: The whole algorithm runs in the browser with no network calls, so the calculator works on a locked-down payment testing box or in a privacy-sensitive workflow.
Together these benefits save a few minutes per use, which adds up across dozens of test cards. The biggest win is consistency: the calculator gives the same answer every time, traceable through the Luhn sum on the screen.
When the same digit-by-digit pattern is needed on a packed binary register, the Binary Operations Calculator applies AND, OR, and XOR to the bits of two integers with full column traces.
Factors That Affect the Result and Its Limits
The algorithm itself is fixed, but the meaning of the verdict depends on a few choices you make when you set up the comparison. The same verdict can be useful in one context and misleading in another.
Choice of method
Validate and Generate use the same math, but Generate treats the input as a payload with no check digit. Re-validating a freshly generated number should give Valid, which is a quick way to confirm the tool is wired up correctly.
Position of the check digit
The Luhn check digit is always the last digit. If the check digit is in the middle by mistake, the calculator still produces an answer, but the verdict will not match the issuer.
Leading zeros in the payload
Leading zeros do not change the Luhn sum because the algorithm only reads digits from right to left. A payload of 007 and a payload of 7 produce the same result.
Number length and issuer rules
Issuers use fixed lengths: 15 for American Express, 13 to 19 for Visa and Mastercard, 14 or 18 for Diners Club, 15 for IMEI. The algorithm works at any length, but the issuer may still reject a Luhn-valid number with the wrong length.
- • The algorithm is known to miss the 09/90 swap and the twin pairs 22-55, 33-66, and 44-77. Use a stronger check, such as the Verhoeff algorithm, for applications that need to catch every adjacent transposition.
- • Luhn validation confirms that a number was likely typed or transmitted correctly, not that it is real, active, or authorized. A Luhn-valid number can still be invented, expired, blocked, or unused; only the issuing system can tell you which.
Treat the calculator as a fast pre-filter. If Invalid, do not bother sending the number downstream; if Valid, send it on but expect the issuing system to apply its own length, prefix, and account checks.
According to Omni Calculator, the Luhn algorithm works by taking a number, doing basic math operations on every digit except the last, and treating the last digit as the check digit that must match the resulting sum.
Frequently Asked Questions
Q: What is the Luhn algorithm used for?
A: The Luhn algorithm validates identification numbers by detecting common typing and transmission errors. Credit card networks, mobile carriers, and many government ID systems use it as a first-pass check before any database lookup or business-logic validation runs.
Q: How do I calculate the Luhn check digit?
A: Start at the rightmost digit of the payload (drop the existing check digit if regenerating). Double every second digit; if a doubled value is greater than 9, subtract 9. Sum the resulting digits, then compute (10 - sum mod 10) mod 10. That single 0-9 digit is the check digit.
Q: How do I check if a credit card number is valid with Luhn?
A: Paste the full card number into the calculator with the validate method. The calculator runs the Luhn algorithm on the payload, compares the result with the existing last digit, and reports Valid when they match. A Valid verdict means the number is well-formed for Luhn; the issuing system still has to confirm it is real and active.
Q: Does the Luhn algorithm detect every typing error?
A: No. Luhn detects every single-digit error and almost every adjacent transposition, but it cannot detect the 09/90 swap or the twin pairs 22-55, 33-66, and 44-77. Applications that need to catch every transposition usually layer a stronger check, such as Verhoeff, on top of Luhn.
Q: Which identification numbers use the Luhn algorithm?
A: Most credit and debit card numbers (Visa, Mastercard, American Express, Discover), 15-digit IMEI numbers for mobile phones, Canadian Social Insurance Numbers, US National Provider Identifiers, CUSIP codes for North American financial instruments, and several European ID and VAT numbers all use a Luhn check digit.
Q: What is the difference between the Luhn and Verhoeff algorithms?
A: Both produce a single check digit appended to a number, but Verhoeff uses a multiplication table over a non-commutative group and catches every single-digit error and every adjacent transposition, including the 09/90 pair that Luhn misses. Luhn is simpler and is the standard for most card networks; Verhoeff is preferred when an application cannot tolerate the Luhn blind spots.