Luhn Algorithm Checker
Check whether any number passes the Luhn checksum, with a step-by-step visualization of exactly how the algorithm works — the check behind every card number.
Runs entirely in your browser — nothing is transmitted. Works for any Luhn-checked number: cards, IMEIs, some national IDs.
✓ Passes the Luhn check — checksum 80 (divisible by 10)
Step by step (right to left, double every 2nd digit):
Sum of the bottom row = 80 → multiple of 10 → valid
The Luhn algorithm catches typos, not fraud — it validates structure, never whether an account exists or has funds. Every card on our Stripe test cards list passes it except the deliberate 4242 4242 4242 4241 incorrect-number card.
Implementations
JavaScript
function luhnCheck(number) {
const digits = number.replace(/\D/g, '');
let sum = 0;
for (let i = 0; i < digits.length; i++) {
let d = +digits[digits.length - 1 - i];
if (i % 2 === 1) { d *= 2; if (d > 9) d -= 9; }
sum += d;
}
return digits.length >= 2 && sum % 10 === 0;
} Python
def luhn_check(number: str) -> bool:
digits = [int(c) for c in number if c.isdigit()]
digits.reverse()
total = 0
for i, d in enumerate(digits):
if i % 2 == 1:
d *= 2
if d > 9:
d -= 9
total += d
return len(digits) >= 2 and total % 10 == 0 Frequently asked questions
What is the Luhn algorithm?
A checksum formula (also called mod 10) invented by IBM’s Hans Peter Luhn in 1954, used to validate card numbers, IMEIs, and various ID numbers. Walking right to left, double every second digit (subtracting 9 when the result exceeds 9), sum everything, and the total must be divisible by 10.
What is the Luhn algorithm used for?
Catching input errors, not fraud. Every major card brand’s numbers pass Luhn, so a checkout can instantly reject a typo — a wrong digit or two swapped neighbors — before wasting an API call. It provides zero security: passing Luhn says nothing about whether a card is real, active, or funded.
How do I implement the Luhn check in code?
Around ten lines in any language: iterate the digits from the right, double every second one, subtract 9 from results above 9, sum, and test sum % 10 === 0. The code examples below this calculator show JavaScript and Python versions.
Why does 4242 4242 4242 4242 pass the Luhn check?
Doubling every second digit of the 4242 pattern yields 8+2 pairs summing to 10 per group of four, giving a total of 80 — divisible by 10. That is exactly why Stripe chose it as its canonical test card: memorable and structurally valid.