Free tool

Credit card generator for testing

Make credit card numbers that pass the Luhn check and match a real brand prefix and length, with an expiry date and CVC, to test payment forms and validation code. Pick a brand or type your own BIN, generate up to 1,000 at once, add made-up cardholder names if your form needs them, and export them as text, CSV, JSON, XML or SQL. The numbers have no account behind them and cannot pay for anything.

Free · no sign-up · runs in your browser, nothing is uploaded

For testing forms and sandboxes only. These numbers are not real accounts and cannot pay for anything.

Options
Expiry
CVC
3 digits (CVV2)
Test cardVisa

•••• •••• •••• ••••

ExpiresMM/YYCVC•••

Testing a Stripe integration? Gateways only accept their own test numbers. Use the Stripe test cards for that.

Cards

Cards appear here.

How a valid card number is built

A card number (PAN) has three parts. The first 6 or 8 digits are the issuer identification number (IIN, often called BIN), which says which network and bank issued the card. The middle digits identify the account. The last digit is a check digit computed with the Luhn algorithm, so that typos are caught before the number is sent anywhere.

The generator picks a prefix from the brand's IIN range, fills the account digits at random, then appends the Luhn digit. To compute that digit:

  1. Start from the rightmost digit of the number without its check digit, and double every second digit going left, starting with that one.
  2. If doubling gives more than 9, subtract 9 (the same as adding its two digits).
  3. Add up all the digits. The check digit is whatever brings the total to a multiple of 10.

Example: for 7992739871 the sum is 67, so the check digit is 3 and the full number is 79927398713. To validate a full number, run the same sum over all its digits, doubling every second digit from the right, starting with the second-to-last; the total must end in 0.

Card brand prefixes, lengths and CVC

These are the ranges the generator uses and the validator recognises. When ranges overlap, the longer prefix wins: 6011 is Discover, the rest of 60 is RuPay. RuPay also issues cards starting with 65, the same prefix as Discover, so the validator reads 65 as Discover.

BrandIIN prefixesLengthsCVC
Visa413, 16, 193 digits (CVV2)
Mastercard51-55, 2221-2720163 digits (CVC2)
American Express34, 37154 digits (CID)
Discover6011, 644-649, 6516-193 digits (CID)
JCB3528-358916-193 digits (CAV2)
Diners Club30, 36, 38-3914-193 digits (CVV)
UnionPay6216-193 digits (CVN2)
Maestro5018, 5020, 5038, 5893, 6304, 6759, 6761-6763, 676770, 67677412-193 digits (CVC2)
Mir2200-220416-193 digits (CVP2)
RuPay60, 81-82, 508163 digits (CVV)

Mastercard started issuing 2-series numbers (2221 to 2720) in 2017, so a validator that only accepts 51 to 55 rejects real Mastercard cards. Visa numbers can be 13, 16 or 19 digits; the generator uses 16 unless you pick another length.

Luhn check in JavaScript, Python and Go

Strip spaces and dashes first, then check the digits. The same loop gives you the check digit when you run it over the number without its last digit.

// true when the number passes the Luhn check (digits only)
function luhnValid(num) {
  let sum = 0;
  for (let i = 0; i < num.length; i++) {
    let d = Number(num[num.length - 1 - i]);
    if (i % 2 === 1) { d *= 2; if (d > 9) d -= 9; }
    sum += d;
  }
  return num.length > 1 && sum % 10 === 0;
}

luhnValid('4242424242424242'); // true
def luhn_check_digit(body: str) -> int:
    """Digit to append to body so the whole number passes Luhn."""
    total = 0
    for i, ch in enumerate(reversed(body)):
        d = int(ch)
        if i % 2 == 0:
            d *= 2
            if d > 9:
                d -= 9
        total += d
    return (10 - total % 10) % 10

import secrets
body = "411111" + "".join(str(secrets.randbelow(10)) for _ in range(9))
print(body + str(luhn_check_digit(body)))  # a 16-digit Visa-format test number
func luhnValid(num string) bool {
	sum := 0
	for i := 0; i < len(num); i++ {
		d := int(num[len(num)-1-i] - '0')
		if d < 0 || d > 9 {
			return false
		}
		if i%2 == 1 {
			d *= 2
			if d > 9 {
				d -= 9
			}
		}
		sum += d
	}
	return len(num) > 1 && sum%10 == 0
}

In tests, a fixed seed gives repeatable fixtures. Libraries such as Faker (faker.finance.creditCardNumber() in JavaScript, fake.credit_card_number() in Python) generate Luhn-valid numbers too.

Generated numbers vs. gateway test cards

A generated number tests everything on your side: input masks, brand detection and logos, length and Luhn validation, how numbers are stored and masked, CSV imports and load tests. It does not test a payment gateway. Gateway sandboxes respond to the test numbers they publish, each tied to an outcome such as success, a specific decline or a 3D Secure challenge.

For Stripe, use the Stripe test cards list, and the Stripe fee calculator to see what a real charge would cost. PayPal publishes its own generator for its sandbox.

Gotchas when you validate cards

  • Luhn catches any single wrong digit and most swaps of two neighbouring digits, but not a swap of 09 and 90. Passing Luhn says nothing about whether the account exists.
  • Accept spaces and dashes in the input and strip them before checking. People paste numbers in groups of four.
  • American Express groups digits 4-6-5 and prints a 4-digit code on the front. Don't hard-code a 3-digit CVC field.
  • PCI DSS forbids storing the card verification code after authorization. Keep generated CVCs in fixtures, not in a table that mirrors production.
  • Store numbers as strings, not numbers: a 16-digit card number can be larger than JavaScript's Number.MAX_SAFE_INTEGER (253 - 1) and lose digits.

More free tools for building payment flows: JSON formatter for webhook payloads, mock data generator for the rest of your fixtures, the free fake data and testing APIs, and the full list of free developer tools.

FAQ

Are generated credit card numbers real?+

No. A generator only builds a number that has the right prefix, the right length and a correct Luhn check digit. No bank account sits behind it, so it has no balance, no owner and no billing address. It passes the format checks a checkout form runs before sending the card off, and fails as soon as the issuer is asked to authorize a payment.

Is it legal to use a credit card generator?+

Generating numbers that pass the Luhn check is arithmetic, and developers do it to test forms, validation code and databases. Using a made-up number to get goods, services or a free trial is a different matter: it is fraud in most countries, and it would be declined anyway.

Can I use a generated card for a free trial or a purchase?+

No. The merchant sends the number to the card network, which asks the issuing bank to approve the charge. The bank has no such account and declines it. Some sites also run a small authorization to check the card before a trial starts, which fails the same way.

How do I check if a credit card number is valid?+

Three offline checks: the prefix (IIN) belongs to a brand, the length is one that brand uses, and the Luhn check digit is right. The Validate tab above runs all three on many numbers at once and tells you the check digit that would fix a bad number. Whether the account exists can only be answered by the issuer, through an authorization.

Why does Stripe or PayPal reject a generated card number?+

Gateway sandboxes expect the test numbers they publish, such as 4242 4242 4242 4242 in Stripe test mode. Those trigger known results (success, a decline code, 3D Secure). For gateway tests, use the gateway list; use generated numbers for your own validation code, fixtures, UI and load tests.

What expiry date and CVV should I use with a test card?+

Any date in the future and any 3 digits, or 4 digits for American Express. That is the rule Stripe and PayPal give for their test cards, and it is what this generator produces: a random month in the next 1 to 10 years, or a fixed date you choose.

What is a BIN and can I generate cards from one?+

The BIN (bank identification number), also called IIN, is the first 6 or 8 digits of the card number and identifies the issuer. Choose "BIN or pattern", type the BIN, and the generator fills the rest with random digits and the correct check digit. Use x for any digit you want random in the middle.

What does the first digit of a card number mean?+

It is the major industry identifier from ISO/IEC 7812. 3 is travel and entertainment (American Express, Diners Club, JCB), 4 and 5 are banking and financial (Visa, Mastercard), and 6 is merchandising and banking (Discover, UnionPay, Maestro). Mastercard also uses 2221 to 2720, Mir uses 2200 to 2204, and RuPay uses 60, 65, 81, 82 and 508.

Sources: Payment card number (IIN ranges) · ISO/IEC 7812-1 · Luhn algorithm · PayPal card testing · Stripe testing docs · PCI DSS. Checked 2026-10-30.