Luhn / card validator

Validate credit card numbers with the Luhn algorithm and detect card type

Luhn Algorithm Validator

Validate credit card numbers and check card type using the Luhn algorithm

0 digits

Test Numbers
Visa
Mastercard
AmEx
Discover

TL;DR

What is Luhn / card validator?

The Luhn algorithm is a simple checksum formula created by Hans Peter Luhn in 1954 to detect accidental errors in identification numbers. It is used to validate credit card numbers, IMEI device numbers, and other numeric identifiers. A number that fails the Luhn check is definitely invalid; one that passes may still be invalid for other reasons.

How it works

Starting from the rightmost digit, double every second digit. If doubling produces a number greater than 9, subtract 9. Sum all digits (original and doubled). If the total is divisible by 10, the number is valid. This detects single-digit errors and adjacent transpositions.

Common use cases

  • Form validation: reject obviously invalid card numbers client-side before sending to a payment processor
  • Test data generation: generate valid-looking card numbers for test environments (note: passing Luhn does not mean the card account exists)
  • IMEI validation: verify that a device IMEI is structurally valid

Frequently asked questions

Does passing the Luhn check mean a credit card number is real?

No. Luhn validation only checks the checksum. A number can pass Luhn and still be invalid because the account does not exist, the card has expired, or the number was fabricated to pass the check. Actual card validity requires a payment network authorization.

How are card types detected?

Card networks are identified by their number prefix and length. Visa starts with 4 (13 or 16 digits). Mastercard starts with 51-55 or 2221-2720 (16 digits). Amex starts with 34 or 37 (15 digits). Discover starts with 6011, 622126-622925, 644-649, or 65 (16 digits).