Luhn Checksum Calculator | Verify or Generate Mod 10 with a Per-Digit Trace Table
A two-mode Luhn (Mod 10) calculator for credit cards, IMEI numbers, and Canadian SIN. Validate a complete number or produce the missing check digit, with a 5-column trace table that exposes every position, doubled value, digit-sum, and running total — so you can debug your own implementation digit by digit.
💡 About this tool
If you've written a Luhn function from scratch — in Python, Go, Rust, or as a test fixture for a payments integration — you've probably hit the moment where your output disagrees with the reference and you cannot tell which digit went sideways. The usual card-validator pages return "valid" or "invalid" and stop there. That tells you nothing about whether the doubling, the digit-sum reduction, or the running-total accumulation broke.
This tool exposes every step in a 5-column table: right-to-left position index, raw digit, doubled value (when the position is doubled), digit-sum (e.g. 16 → 1 + 6 = 7), and running total. Paste the same input into your own code, run it side by side, and the column that first disagrees is your bug.
Both modes share the same trace layout. VERIFY assumes the input already contains the check digit and reports whether the total mod 10 is zero. GENERATE assumes you've omitted the check digit and computes which trailing digit would make the total divisible by 10. Inputs accept the usual visual groupings — 4532 0151 1283 0366 with spaces, 4532-0151-1283-0366 with dashes, or just the raw run.
🧐 Frequently Asked Questions
When do I use VERIFY versus GENERATE?
VERIFY when you have a candidate number and want to know whether it passes Mod 10. GENERATE when you have a PAN minus the check digit (or an IMEI's first 14 digits) and want to know what to append. GENERATE is also what you reach for when synthesizing test data that the Stripe testmode 4242 4242 4242 4242 pool doesn't cover.
Does this work for IMEI? Yes. The 15th digit of an IMEI is a Luhn check digit over the first 14. Drop the full 15-digit IMEI into VERIFY to confirm, or 14 digits (TAC + serial) into GENERATE to compute the missing one. The same scheme applies to Canadian SIN (9 digits) and US NPI (10 digits, healthcare provider IDs) — all Luhn (Mod 10) under the hood.
What's the rule when doubling produces a two-digit result?
You sum the two digits: 8 × 2 = 16 becomes 1 + 6 = 7. Some implementations use doubled - 9 as a shortcut, which is algebraically identical for digits 5–9. This tool shows the digit-sum form because that's the version in the original Luhn patent and in most teaching material.
Is Luhn cryptographically secure?
No, and it was never designed to be. Luhn catches single-digit substitutions and most adjacent transpositions (except the 0 ↔ 9 pair). It won't stop an attacker from generating numbers that pass Mod 10 — they just need to satisfy the constraint. Treat Luhn as a sanity filter on user-typed input, not as authentication.
Can I run it on arbitrary-length inputs? There's no hard cap. The table renders for whatever length you paste. Useful when you're checking custom internal IDs (warehouse SKUs, internal customer IDs) where someone has bolted a Luhn check digit onto a non-standard length.
Which other identifiers use Mod 10 versus a different mod? Credit cards (ISO/IEC 7812), IMEI (3GPP TS 23.003), Canadian SIN, and US NPI all use Luhn Mod 10. ISBN-10 uses Mod 11 with a different weighting. ISBN-13 / EAN use a Mod 10 with weights 1 and 3 alternating — close but not identical. This tool only handles classic Luhn.
📚 Fun Facts
Hans Peter Luhn filed US patent 2950048 in 1954 while at IBM, and the patent issued in 1960. Luhn himself is better known in computer science history for inventing the Key Word in Context (KWIC) index — an early precursor to full-text search and a foundational idea behind document retrieval as a discipline. The Mod 10 check digit is, frankly, a footnote in his portfolio.
The reason the algorithm is so ubiquitous on credit cards today comes down to timing. The patent expired in 1977, freeing the technique just as Visa and MasterCard were settling on ISO/IEC 7812 as the international PAN format. With the IP barrier gone and a need for a low-cost, hand-verifiable check, Luhn slid into the spec and stayed there. Every Visa, Mastercard, Amex, Discover, JCB, and UnionPay card you've ever pulled out of a wallet ends in a digit chosen by a 1954-vintage algorithm running in your browser in microseconds.
A small quirk worth knowing: the algorithm cannot detect a 09 ↔ 90 transposition. If you're auditing typo-resilience for a custom ID scheme, that's the one corner case where Luhn lies about being valid. Most production checks add a length test and a leading-digit (IIN/BIN) test in front of Luhn for that reason.