Luhn Algorithm Explained

The Luhn algorithm is the checksum formula used to validate payment card numbers.

What it is

The Luhn algorithm (mod 10) is the checksum formula used to validate payment card numbers. It detects single-digit errors and most transpositions. It is not a security check - it only confirms the number is structurally valid.

  • Developed by Hans Peter Luhn
  • Used by all major card brands
  • Catches single-digit errors
  • Catches most transpositions
  • Not a security or fraud check

How it works

Starting from the rightmost digit, double every second digit. If a doubled digit exceeds 9, subtract 9. Sum all digits. If the total is divisible by 10, the number passes.

StepAction
1Start from the rightmost digit
2Double every second digit moving left
3Subtract 9 from any result above 9
4Sum all digits
5If divisible by 10, valid

History of Luhn

The Luhn algorithm was created by Hans Peter Luhn, an IBM scientist, in 1954. It was designed as a simple checksum to catch transcription errors in account numbers. It has since become the standard for payment card validation worldwide.

  • Created by Hans Peter Luhn at IBM in 1954
  • Originally for account number validation
  • Adopted by all major card networks
  • Simple to implement, effective at catching errors
  • Now an ISO/IEC standard

Implementation examples

The algorithm is simple to implement in any language. The key steps are: reverse the number, double every other digit, subtract 9 from results over 9, sum all digits, check divisibility by 10. The free Luhn checker and mod-10 calculator on this site show the calculation step by step.

  • Reverse the number string
  • Double every second digit
  • Subtract 9 from digits over 9
  • Sum all resulting digits
  • Check if sum mod 10 equals 0

Edge cases

Luhn does not catch all errors. It misses some transpositions (swapping two digits that are 5 apart). It also cannot detect missing or extra digits in certain positions. For production use, combine Luhn with other validation (BIN lookup, issuer verification).

  • Misses transpositions of digits 5 apart
  • Cannot detect all missing/extra digits
  • Combine with BIN lookup for production
  • Combine with issuer verification for full validation
  • Not a fraud prevention tool

Other checksums

Luhn is not the only checksum algorithm. IMEI numbers use a Luhn variant. ISBN-13 uses a mod 10 checksum with different weights. IBAN uses mod 97. Each is designed for its specific use case.

StandardAlgorithmUse case
Luhn (mod 10)Double every other digitPayment cards
IMEILuhn variantMobile devices
ISBN-13Mod 10 with weightsBooks
IBANMod 97Bank accounts
EAN/UPCMod 10Product barcodes

Limitations

Luhn does not verify that a card exists, is active or has balance. It only confirms the number is structurally valid. Use the free Luhn checker on this site to test a number.

  • Does not verify card existence
  • Does not check active status
  • Does not verify balance
  • Only structural validity
  • Combine with issuer checks for full validation

Frequently Asked Questions

What is the Luhn algorithm?

A checksum formula (mod 10) used to validate payment card numbers.

Does Luhn prove a card is real?

No, it only confirms structural validity, not existence or balance.

Who invented Luhn?

Hans Peter Luhn, at IBM, in 1954.

Which cards use Luhn?

All major brands: Visa, Mastercard, AMEX, Discover.

Can I test a number?

Yes, use the free Luhn checker tool on this site.

What errors does Luhn catch?

Single-digit errors and most adjacent transpositions.

What errors does Luhn miss?

Transpositions of digits 5 apart and some missing/extra digit cases.

Is Luhn used for anything else?

Yes: IMEI numbers, some national ID numbers, and other account validation systems.