💳

Luhn Algorithm

The Luhn Algorithm (also called Mod 10) is a simple checksum formula that detects typographical errors in identification numbers. Created by Hans Peter Luhn in 1954, it's used in credit cards, IMEI, account numbers and other codes to validate they haven't been accidentally altered.

Examples

  • Valid card: 4532015112830366 (✅ passes Luhn)
  • Invalid card: 4532015112830367 (❌ fails Luhn, wrong last digit)
  • IMEI example: 490154203237518 (15 digits, last is Luhn check digit)
  • Canadian account number: validation via Luhn mod 10
  • Test with Visa: starts with 4, 13-16 digits, last digit calculated with Luhn

FAQ

Does the Luhn Algorithm validate that the card exists?

No. Luhn only verifies that the digits are mathematically consistent (without typos). It doesn't query bank databases, doesn't verify funds, nor confirms the card is active. It's the first filter, not authorization.

Can I generate real cards with Luhn?

No. Although you can generate numbers that pass Luhn, real cards have BINs (first 6 digits) registered by banks, internal account numbers, and validations in payment networks. Numbers valid according to Luhn don't imply existing cards.

Why Luhn if it's so simple?

Because it solves the specific problem of detecting common typos (human errors when transcribing). It's fast, no overhead, and sufficient to filter 90% of accidental errors before expensive server queries. It doesn't pretend to be security, but format validation.