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
- Pick the brands your form accepts. Include one you do not accept to check the rejection message.
- 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.
- Toggle CVC, expiry and cardholder name to match your form's fields, and switch on some cards already expired to exercise the expiry check.
- 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.