Luhn Algorithm Checker

Validate card numbers with the Luhn mod-10 check and generate test numbers.

Free Luhn algorithm checker. Validate credit card and other MOD-10 numbers, see the exact check-digit calculation, detect the card brand, and generate fictitious Luhn-valid test numbers. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the Luhn algorithm?

The Luhn algorithm, also called the mod-10 algorithm, is a simple checksum used to catch accidental errors in identification numbers. Starting from the right, every second digit is doubled (subtracting 9 if over 9), all digits are summed, and the number is valid if the total is a multiple of 10.

The Luhn algorithm (mod-10) is the checksum that guards almost every payment card number, as well as IMEI device IDs and many national identifiers. It catches the most common data-entry mistakes — a single wrong digit or two swapped digits — before a number ever reaches a server. This tool runs that check locally and explains the result.

How it works

Working from the rightmost digit leftward:

  1. Double every second digit.
  2. If a doubled value is greater than 9, subtract 9 (equivalently, add its two digits).
  3. Add up all the resulting values.
  4. The number is valid when that total is a multiple of 10.

The final digit of the number is the check digit — it is specifically chosen so the whole sequence passes step 4. When a number fails, the tool computes what the check digit should have been, which usually pinpoints the typo.

It also inspects the leading digits to label the likely card brand (Visa starts with 4, Mastercard with 51-55 or 2221-2720, American Express with 34 or 37, and so on).

Tips and notes

  • Spaces and dashes are ignored, so you can paste 4539 1488 0343 6467 directly.
  • For example, 79927398713 is a classic Luhn-valid test value — its digits sum to a multiple of 10.
  • Use the generator to create fictitious, Luhn-valid numbers per brand for testing checkout forms. These are not real cards and cannot be charged; they only exercise your validation logic.
  • A pass means well-formed, not authorised. Always rely on your payment processor for real authorisation. Everything here stays on your device.

Card brand detection explained

The tool inspects the first one to four digits to identify the likely card network. The rules are publicly documented by each network:

BrandPrefix pattern
VisaStarts with 4
MastercardStarts with 51–55 or 2221–2720
American ExpressStarts with 34 or 37
DiscoverStarts with 6011, 622126–622925, 644–649, or 65
Diners ClubStarts with 300–305, 36, or 38

The prefix check is a heuristic — it identifies the likely brand, not the issuing bank. A number starting with 4 that passes Luhn is Visa-format, but whether it maps to a real Visa account is a different question entirely.

How the check digit pinpoints a typo

When a number fails Luhn, the expected check digit tells you what the last digit should have been. If you typed a number and the last digit is wrong, the expected-vs-actual comparison reveals the discrepancy instantly. More usefully, if the number is long (16 or 19 digits) and the check digit seems correct, the actual typo is likely in one of the other positions — perhaps a transposition of two adjacent digits in the middle. In that case, systematically swapping adjacent pairs and re-checking is faster than re-entering the whole number.

Why Luhn is not an anti-fraud measure

The Luhn algorithm was designed in 1954 to detect accidental data-entry errors before sending data over slow and expensive networks. It was never intended to stop deliberate fraud. Any number of Luhn-valid cards can be generated by anyone with this tool, a calculator, or five minutes of arithmetic. The actual fraud prevention in modern card payments is layered on top: CVV2 verification, address verification (AVS), 3D Secure authentication, EMV chip cryptograms, and real-time network fraud scoring. Luhn is the first, simplest gate — it rules out obvious typos, nothing more.

Common developer mistakes with Luhn

  • Stripping only spaces but not dashes: card numbers are sometimes formatted with dashes; strip both before checking
  • Checking Luhn on test transactions against a sandbox that ignores Luhn: the test environment may accept any number, making Luhn failures invisible until production
  • Assuming Luhn failure means the user typed wrong: a failed Luhn on a physically issued card more often means a digit was mis-scanned by the camera or misread from a worn emboss — prompt the user to try again before showing an error