Skip to content

Free · No sign-up · Nothing leaves your browser

Validate a credit or debit card number

Card number

Do not type a real card unless you have to. To try it out, use an official test number:

Just the number, with or without spaces. We will never ask for the expiry date or CVV.

Luhn only catches typing mistakes. It does not tell you whether the card exists, is active or has funds: only the issuing bank knows that when it authorises a payment.

Check whether a card number is typed correctly with the Luhn algorithm, see which network it belongs to (Visa, Mastercard, American Express…) from the ranges each one publishes, and calculate the missing check digit. Testing an online shop? Use the official test cards from Stripe, Redsys or PayPal: you do not need a real one.

It runs in your browser: the number is not sent, not stored and never reaches analytics. We never ask for the expiry date or CVV.

What it checks

What this tool checks (and what it does not)

  • Yes: that the number passes the Luhn algorithm (no mistyped digit); which network it belongs to according to the ranges the networks themselves publish; whether its length matches what that network publishes; and the check digit of an incomplete number.
  • No: whether the card exists, is active, has funds or whose it is. Only the issuing bank knows, and it only checks when it authorises a payment.
  • No: which bank issued it or whether it is credit or debit. That data lives in the networks' BIN tables, which are not public. See below.

Do not type a real card unless you have to. The tool sends nothing, but the good rule is never to type your card into a website unless you are paying. To try it out, there are official test numbers and buttons with them in the tool itself.

Test cards

Official test cards from Stripe, Redsys and PayPal

If you are building or reviewing an online checkout, each gateway publishes test numbers: they pass Luhn and only work in the gateway's test environment, so nothing is charged. These are the ones published by Stripe, Redsys (the virtual POS used by most Spanish banks) and PayPal, with the expiry date and CVV each one asks for. Paste them into the tool above to see the result.

Card (as named by the gateway)NumberNetwork
StripeExpiry and CVV: Any future date and any CVC (4 digits for American Express). Test mode only.
Visa4242 4242 4242 4242Visa
Visa (debit)4000 0566 5566 5556Visa
Mastercard5555 5555 5555 4444Mastercard
Mastercard (2-series)2223 0031 2200 3222Mastercard
Mastercard (debit)5200 8282 8282 8210Mastercard
Mastercard (prepaid)5105 1051 0510 5100Mastercard
American Express3782 822463 10005American Express
American Express3714 496353 98431American Express
Discover6011 1111 1111 1117Discover
Discover (debit)6011 9811 1111 1113Discover
Diners Club3056 9300 0902 0004Diners Club International
Diners Club (14-digit card)3622 7206 2716 67Diners Club International
JCB3566 0020 2036 0505JCB
UnionPay6200 0000 0000 0005UnionPay
UnionPay (19-digit card)6205 5000 0000 0000 004UnionPay
RedsysExpiry and CVV: Expiry 12/49 and CVV 123 (1234 for American Express). Only in the sis-t.redsys.es test environment.
VISA genérica, EMV3DS 2.24548 8100 0000 0003Visa
Mastercard, EMV3DS 2.15576 4415 6304 5037Mastercard
American Express, SafeKey 1.0.23766 740000 00008American Express
Diners Club International3684 9800 0000 18Diners Club International
JCB, JSecure 1.0.23587 8700 0000 0001JCB
VISA frictionless, EMV3DS 2.14548 8144 7972 7229Visa
VISA challenge, EMV3DS 2.14548 8172 1249 3017Visa
PayPalExpiry and CVV: Any future date and a 3-digit CVV (4 for American Express). Sandbox only.
Visa4012 8888 8888 1881Visa
Mastercard2223 0000 4840 0011Mastercard
American Express3766 808163 76961American Express
Diners Club3646 1510 0000 39Diners Club International
Copied from each gateway's documentation on 22/11/2026. They only work in the gateway's test environment: a live shop declines them.

How to force a declined payment in Redsys

According to the Redsys documentation, any CVV works in its test environment except these, which trigger a decline:

CVVWhat it simulates
999Declined (on the authentication screen, choose to authenticate successfully).
172Declined; the scheme says not to retry.
173Declined; the scheme says not to retry without updating the card data.
174Declined; the scheme says not to retry for 72 hours.
Amounts ending in .96, .72, .73 or .74 € are also declined. Source: Redsys, “Tarjetas y entornos de prueba”.

Why not test with a real card

Besides the risk, it breaks the gateways' terms. Stripe's testing page says the Stripe Services Agreement prohibits testing in live mode with real payment method details, and it recommends using test payment methods (such as pm_card_visa) in code instead of card numbers, because card numbers in server-side code may not meet PCI requirements once you go live.

How it works

The Luhn algorithm, step by step

The last digit of a card is a check digit, calculated from the others so that a typing mistake shows up. The calculation is the Luhn algorithm (or “mod 10”). With the sample number 7992 7398 713, the one Stripe uses in its guide to the algorithm:

  1. 101

    Start from the right

    7 9 9 2 7 3 9 8 7 1 3

    The last digit (3) is the check digit. Walk through the number from right to left.

  2. 202

    Double every second digit

    1→2 · 8→16 · 3→6 · 2→4 · 9→18

    Starting with the second digit from the right, double every other digit.

  3. 303

    Over 9? Subtract 9

    16→7 · 18→9

    Same as adding its two digits (1 + 6 = 7). Digits that are not doubled stay as they are.

  4. 404

    Add up and check for a 0

    7+9+9+4+7+6+9+7+7+2+3 = 70

    If the total is a multiple of 10, the number passes Luhn. 70 is: the number is correct.

How to calculate the check digit

To get the missing digit, append a 0, compute the Luhn sum and see how much is needed to reach the next multiple of 10. With 7992 7398 71: the sum with a trailing 0 is 67, the next multiple of 10 is 3 away, so the check digit is 3. The “Calculate check digit” tab of the tool does it for you.

Which errors it catches and which it misses

  • Always catches a single wrong digit: changing one digit changes its contribution to the sum, which stops being a multiple of 10.
  • Almost always catches two adjacent digits swapped (typing 45 instead of 54).
  • Misses swapping 09 for 90 (a doubled 0 is still 0 and a doubled 9 is 18 − 9 = 9, so the sum does not change) and some double errors, such as 22 for 55.
  • It is not a security measure. Anyone can make up a number that passes Luhn, so passing it does not mean the card exists.

Where it comes from: Luhn's patent and ISO/IEC 7812

Hans Peter Luhn of IBM described it in US patent 2,950,048, “Computer for verifying numbers”, filed on 6 January 1954 and granted on 23 August 1960: a hand-held device “for computing a check digit” or “verifying numbers which already have a check digit appended”. Today the card number format is governed by ISO/IEC 7812-1, as Visa notes. The standard is paid, so we do not quote it here.

Networks

How to tell whether a card is Visa, Mastercard or American Express

The first digits tell you. Each network publishes (or does not) the ranges it uses. This table only has ranges published in official documents, with links; it is the same table the tool uses.

NetworkStarts withDigitsOfficial source
Visa416 and 19Visa, «8-Digit BIN Expansion FAQ» (merchants)
Mastercard222100–272099, 510000–559999Not publishedMastercard Developers, BIN Lookup API
American Express34, 3715American Express, «Getting Started Guide» para comercios (Reino Unido)
Discover6011, 644–65816–19Discover Global Network, «IIN Range Summary»
Diners Club International3000–3059, 3095, 36, 38–3916–19 · 14–19Discover Global Network, «IIN Range Summary»
JCB3088–3094, 3096–3102, 3112–3120, 3158–3159, 3337–3349, 3528–358916–19Discover Global Network, «IIN Range Summary»
UnionPay621094, 622126–623796, 624–626, 6282–6288, 8100–8171, 6216–19 · Not publishedUnionPay International («card number starting with 62») y Discover Global Network, «IIN Range Summary»
Maestro639000–639099, 670000–679999Not publishedMastercard Developers, BIN Lookup API
Prefixes as published by each network (or by Discover Global Network, which processes Diners Club, JCB and UnionPay). Visa and American Express do not publish finer ranges; Mastercard does not give the length on that page. The full BIN list is paid and we do not reproduce it.

If a number is in none of these ranges, the tool does not call it fake: it may belong to another network (there are domestic ones) or to a range the network does not publish openly.

Mastercard also starts with 2

Besides 51 to 55, Mastercard uses the 222100 to 272099 block, according to its developer documentation. Many old validators only check for a leading 5 and reject 2-series Mastercards. Stripe has a test one: 2223 0031 2200 3222.

How many digits does a card have?

  • Visa: 16 or 19 digits, according to its 8-digit BIN FAQ.
  • American Express: 15 digits, printed in groups of 4, 6 and 5, according to its merchant guide. Its security code has 4 digits and is on the front.
  • Diners Club, JCB, Discover and UnionPay: 16 to 19 digits; Diners cards starting with 36, from 14. Published by Discover Global Network.
  • Mastercard: its page does not give the length, so the tool does not flag it. The Stripe, Redsys and PayPal test cards have 16.
  • Maximum: 19 digits for any network.

BIN

The BIN: the first 6 or 8 digits

The first digits are the BIN (bank identification number) or IIN (issuer identification number): they identify the card issuer. For years they were 6. Today they can be 8: Visa has assigned 8-digit BINs since 2019 and set April 2022 as the date for acquirers and processors to be ready (Visa). Discover speaks of “the first six or eight digits” (Discover) and Mastercard says the BIN covers “the first 6 to 11 digits” (Mastercard).

That is why the tool shows the first 6 and 8 digits. If you build a checkout, do not assume the BIN has 6: Visa recommends using the first 9 digits (the “account range”) for transaction processing.

Can you tell the bank, or whether it is credit or debit?

Not from the number alone. Which bank owns each BIN, whether it is credit, debit or prepaid and its country are in each network's BIN tables, which are licensed (Mastercard, for example, offers them through its BIN Lookup API). Sites that show the bank use third-party databases that may be out of date. We do not have one and we do not make it up: check your contract, your banking app or the card itself.

Security

Why we never ask for the expiry date or CVV

You do not need them to check whether a number is typed correctly, and they are exactly what is needed to pay with a card. PCI DSS, the card industry security standard, does not allow card verification codes (CVV or CVC) to be stored after the payment is authorised, not even with the customer's consent (PCI SSC). If a “card validator” site asks for them, be suspicious.

  • The number never leaves your browser: there is no server request with it.
  • It is not stored anywhere (not even in browser storage) and is cleared when you leave the page.
  • It never reaches analytics: the field is not inside a form, has no name, and the number never goes into the page address, which is all our statistics measure.
  • The field has autocomplete="off" so the browser does not remember it.

Code

Validate a card with Luhn in Excel, JavaScript and Python

The same calculation the tool does, for your checkout form, a spreadsheet or a script. Remember that a Luhn check in the form only prevents typos: the payment is authorised by the gateway.

card.xlsx · Excel
Card number in B2, entered as TEXT (Excel keeps only 15 significant digits in
a number: with 16 it would turn the last one into a 0).

Passes Luhn? (Excel 365 or 2021)
=LET(n,SUBSTITUTE(B2," ",""),k,SEQUENCE(LEN(n)),
     d,--MID(n,LEN(n)-k+1,1),v,d*(1+(MOD(k,2)=0)),
     MOD(SUM(v-9*(v>9)),10)=0)

Missing check digit (number without its last digit in C2):
=LET(n,C2,k,SEQUENCE(LEN(n)),
     d,--MID(n,LEN(n)-k+1,1),v,d*(1+(MOD(k,2)=1)),
     MOD(10-MOD(SUM(v-9*(v>9)),10),10))
luhn.js · JavaScript
// Luhn algorithm (the check digit of payment cards).
// Runs wherever you put it: it does not send the number anywhere.
function luhnSum(digits) {
  let sum = 0;
  for (let i = 0; i < digits.length; i++) {
    let d = Number(digits[digits.length - 1 - i]); // right to left
    if (i % 2 === 1) {      // every second digit, starting with the second
      d *= 2;
      if (d > 9) d -= 9;    // 7 × 2 = 14 → 14 − 9 = 5
    }
    sum += d;
  }
  return sum;
}

function passesLuhn(number) {
  const digits = number.replace(/[\s-]/g, "");
  return /^\d{8,19}$/.test(digits) && luhnSum(digits) % 10 === 0;
}

// Missing check digit (number without its last digit).
function checkDigit(withoutLast) {
  return (10 - (luhnSum(withoutLast + "0") % 10)) % 10;
}

// Network from the prefix, using only the ranges published by Visa, Mastercard and Amex.
function network(number) {
  const c = number.replace(/[\s-]/g, "");
  if (/^3[47]/.test(c)) return "American Express"; // 15 digits
  if (/^4/.test(c)) return "Visa";                  // 16 or 19 digits
  if (/^(5[1-5]|222[1-9]|22[3-9]\d|2[3-6]\d\d|27[01]\d|2720)/.test(c)) return "Mastercard";
  return null; // another network or an unpublished range: not necessarily fake
}

passesLuhn("4242 4242 4242 4242"); // true (Stripe test card)
checkDigit("7992739871");          // 3
network("2223003122003222");       // "Mastercard" (2-series)
luhn.py · Python
import re

def luhn_sum(digits: str) -> int:
    total = 0
    for i, c in enumerate(reversed(digits)):  # right to left
        d = int(c)
        if i % 2 == 1:                        # every second digit
            d *= 2
            if d > 9:
                d -= 9
        total += d
    return total

def passes_luhn(number: str) -> bool:
    digits = re.sub(r"[\s-]", "", number)
    return bool(re.fullmatch(r"\d{8,19}", digits)) and luhn_sum(digits) % 10 == 0

def check_digit(without_last: str) -> int:
    return (10 - luhn_sum(without_last + "0") % 10) % 10

print(passes_luhn("3782 822463 10005"))  # True (Stripe American Express test card)
print(check_digit("7992739871"))         # 3

FAQ

Frequently asked questions

What does validating a credit card mean?

It depends who says it. Here, checking that the number is typed correctly (Luhn algorithm) and that its prefix and length belong to a network. When a shop or a bank “validates” a card, it usually means asking the issuing bank for an authorisation, which is the only way to confirm the card exists and can be used.

Is a number that passes Luhn a real card?

Not necessarily. Luhn only catches typing mistakes: anyone can write a number that passes it. The Stripe and Redsys test cards, for example, pass it and belong to nobody.

How do I know whether my card is active or has funds?

You cannot tell from the number. Check your bank's app or website, or call the number on the back of the card.

Which card starts with 4, 5 or 3?

4 is Visa. 51 to 55 (and 2221 to 2720) is Mastercard. 34 or 37 is American Express; 36, 38 or 39 is Diners Club; 3528 to 3589 is JCB. 6011 or 644 to 658 is Discover, and 62 is UnionPay. These are the ranges each network publishes; the table has the links.

How many digits does a credit card have?

Usually 16. Visa publishes 16 or 19; American Express, 15; Diners Club, JCB, Discover and UnionPay, 16 to 19 (Diners cards starting with 36, from 14). None has more than 19.

What is a card's BIN?

The first digits of the number (6 or 8, depending on the card), which identify the issuer. Visa has assigned 8-digit BINs since 2019.

Can I find out the bank, or whether it is credit or debit?

Not from the number alone: that information is in the networks' BIN tables, which are not public. Check your contract, your banking app or the card itself.

Which test cards do I use with Redsys?

Visa 4548 8100 0000 0003, Mastercard 5576 4415 6304 5037, American Express 3766 740000 00008, Diners 3684 98000 00018 and JCB 3587 8700 0000 0001, with expiry 12/49 and CVV 123 (1234 for Amex). They only work in the Redsys test environment. All of them are in the table.

And with Stripe or PayPal?

On Stripe, the best known is 4242 4242 4242 4242 (Visa), with any future date and any CVC. PayPal publishes its own for the sandbox, such as Visa 4012 8888 8888 1881. More in the table, with a link to each documentation page.

Why don't you ask for the expiry date or CVV?

Because they are not needed to check that the number is typed correctly, and they are the data that let someone pay with a card. Be wary of any “validator” that asks for them.

Do you store the number I type?

No. It is checked in your browser, not sent to any server, not stored and never reaches analytics. It is cleared when you leave the page.

About

About this validator

Built by Black Wings, a software studio in Valencia (Spain) working with small and medium businesses. Our validators are free, single-purpose tools that show how we work.

Privacy

What happens to what you type

It never leaves your browser. The calculation runs in JavaScript on your device, with no server request. We do not store the number, put it in the page address or in browser storage, and it is cleared when you leave.

Our analytics (Vercel Web Analytics and, if you accept cookies, Google Analytics) measure page views, not what you type into fields. More in our privacy policy.

Other validators

More free validators

Need this inside your own software?

Validating IBANs and tax IDs when a customer signs up, checking whole lists or connecting invoicing to the bank: that is the kind of work we do at Black Wings.

Tell us about it