A secure testing tool for payment system developers and QA professionals. All test numbers are non-functional and strictly for development environments.

Luhn Algorithm Validator

The Luhn algorithm (also called MOD 10) is the checksum used by all major card networks to catch typos in card numbers. Paste a number below to check whether it passes โ€” validation happens instantly in your browser and nothing is sent to a server.

How the Luhn algorithm works

  1. Starting from the rightmost digit, double every second digit.
  2. If doubling produces a number greater than 9, subtract 9 (equivalent to adding the two digits).
  3. Sum all digits (doubled and unchanged).
  4. If the total is divisible by 10, the number is valid.

Example: 79927398713 passes the check โ€” the processed digits sum to 70. Change any single digit and the sum will no longer be divisible by 10.

Implementation

JavaScript

function isValidLuhn(number) {
  const digits = number.replace(/\D/g, '');
  let sum = 0;
  let double = false;

  for (let i = digits.length - 1; i >= 0; i--) {
    let digit = Number(digits[i]);

    if (double) {
      digit *= 2;
      if (digit > 9) digit -= 9;
    }

    sum += digit;
    double = !double;
  }

  return sum % 10 === 0;
}

Python

def is_valid_luhn(number: str) -> bool:
    digits = [int(c) for c in number if c.isdigit()]
    total = 0

    for index, digit in enumerate(reversed(digits)):
        if index % 2 == 1:
            digit *= 2
            if digit > 9:
                digit -= 9
        total += digit

    return total % 10 == 0

Luhn is not the whole story

A number can pass Luhn and still be invalid: the BIN may not exist, the length may be wrong for the network, or the card may simply not be issued. Luhn only detects accidental errors such as typos. For a full check, combine it with the BIN checker, and for practice numbers use the test card generator.

Free payment testing tools