Skip to content
faker.tools
All 79

Plate III · Financial, E-Commerce & Retail Stubs

Credit Card Number Generator

Luhn-valid Visa, Mastercard, Amex, Discover, JCB and Diners numbers for testing payment forms.

#BrandNumberExpiryCVCLuhn Valid
1Mastercard2707 9724 7260 290510/28728true
2American Express3433 902485 4510601/282941true
3American Express3711 800711 7872805/277185true
4Visa4629 0193 2528 637808/29012true
5Visa4365 4606 2284 338801/31894true
6Mastercard2703 2442 1023 060311/31914true
7Mastercard2525 3386 7021 330104/28252true
8Visa4971 7596 9180 494002/27605true
9Visa4160 9447 0306 331010/27372true
10Visa4397 0552 2854 752404/29989true
10 rows · 877 BGenerated in your browser · Credit Card Number Generator

A test credit card number is a number that passes every check a payment form can run offline — brand prefix, length and the Luhn checksum — while belonging to no account. This generator produces them for six networks, with matching CVCs and expiry dates, so your form has to reach the processor before it can reject one.

That matters because a payment form validates in layers. A number that fails at the first layer never exercises the formatting, masking, brand detection and error handling behind it. These pass all of them.

How to use it

  1. Pick the brands your form accepts. Include one you do not accept to check the rejection message.
  2. Choose a number format: digits only, grouped with spaces or dashes, or masked to the last four — the shape you display after a card is saved.
  3. Toggle CVC, expiry and cardholder name to match your form's fields, and switch on some cards already expired to exercise the expiry check.
  4. Copy the table, or export it as JSON, CSV or SQL for a fixture. Keep the seed and the same batch regenerates next time.

What you can control

  • Six brands with correct prefixes and lengths: Visa (4, 16 digits), Mastercard (51–55 and 2221–2720, 16), American Express (34 or 37, 15), Discover (6011, 644–649, 65; 16), JCB (3528–3539, inside JCB's 3528–3589 block; 16) and Diners Club (300–301, 36, 38; 14).
  • Brand-correct grouping: Amex prints as 4-6-5, everything else in fours.
  • A four-digit CVC for Amex and three digits for everything else.
  • Expiry dates one to five years ahead, with an option to make about a third of them already expired.
  • Cardholder names in the upper case that embossed cards use.

How the Luhn check works

Take the payload 7992739871 and append a check digit. Starting from the rightmost payload digit, double every second digit, and subtract 9 from any result above 9:

Digit (right to left) 1 7 8 9 3 7 2 9 9 7
After doubling 2 7 7 9 6 7 4 9 9 7

The sum is 67. The check digit is whatever brings it to the next multiple of ten: 3, giving 79927398713. Validation runs the same walk over the full number, including the check digit, and accepts only a total divisible by ten. In JavaScript:

function luhnValid(number) {
  const digits = number.replace(/\D/g, "");
  let sum = 0;
  for (let i = 0; i < digits.length; i++) {
    let d = Number(digits[digits.length - 1 - i]);
    if (i % 2 === 1) {
      d *= 2;
      if (d > 9) d -= 9;
    }
    sum += d;
  }
  return digits.length > 0 && sum % 10 === 0;
}

Every number this tool generates returns true. Change any single digit and it returns false.

Testing ideas

  • Brand detection. Generate fifty Mastercard numbers and check that your card-type icon recognises the 2-series ones. Many hand-rolled regexes still stop at ^5[1-5].
  • Field length. Paste a 14-digit Diners number and a 15-digit Amex. Forms that require exactly sixteen digits reject both.
  • Formatting on input. Paste a number grouped with dashes and one with spaces. Your field should normalise both, and the cursor should not jump when a space is auto-inserted.
  • Masking and storage. Use the masked format to check how saved cards render, and confirm your logs and analytics never receive the full number.
  • Expiry. Turn on expired cards and confirm the error is shown before submission, not after a round trip.

What this is not

These numbers are structurally valid, not live. They cannot authorise a payment, and they will not trigger sandbox scenarios such as an insufficient-funds decline or a 3-D Secure challenge — your processor's published test cards do that. The guide Test credit card numbers lists the sandbox cards for Stripe, PayPal Braintree and Adyen, and explains which to use where. Never present a generated number to a real merchant.

Questions

Are these credit card numbers real?

No. They satisfy the brand prefix, length and Luhn checksum that a form can check offline, but no issuer has them on file. A processor declines them the moment they reach the card network.

Can I use a generated number to buy something or start a free trial?

No. The number will be declined, and presenting a number you know to be fake to obtain goods or services is fraud. These are for testing software you own.

What is the Luhn algorithm?

A mod-10 checksum on the last digit of every payment card number. It catches every single-digit typo and most transpositions of adjacent digits, which is why forms run it before making a network call.

Should I use these or my payment processor's test cards?

Use generated numbers for front-end validation, fixtures and anything that never reaches a processor. Use your processor's published test cards — such as Stripe's 4242 4242 4242 4242 — for sandbox payments, because only those trigger specific outcomes like a 3-D Secure challenge or a decline.

Why does my form reject Mastercard numbers starting with 2?

Because its brand detection only knows 51–55. Mastercard has issued cards in the 2221–2720 range since 2017. Generate a batch of Mastercard numbers here and you will see both ranges, which is a quick way to find that bug.

Why is the American Express CVC four digits?

Amex prints a four-digit Card Identification Number on the front of the card instead of a three-digit code on the back. A form that hard-codes a three-digit CVC field rejects every Amex customer.

Next in Finance

All 11 →