What is a credit card number?

A credit card number, also called the PAN (primary account number), is the long number on a credit, debit or prepaid card. Most cards have 16 digits in groups of four, XXXX XXXX XXXX XXXX, while American Express cards have 15, grouped as XXXX XXXXXX XXXXX. The first digits name the network and the issuing bank, and the last one is a check digit.

You need a valid number when you build or test a checkout form, clean up customer records, or want to catch a typo before you pay online.

Tool description

Type or paste a number into the Credit card number field, and the result shows as you type: "Credit card number is valid" or "Credit card number is not valid". Spaces and line breaks around the number are ignored, and so are spaces and hyphens between the digits, so XXXX XXXX XXXX XXXX and XXXX-XXXX-XXXX-XXXX count the same as one unbroken block. Dots, slashes and other characters make the number fail.

The Card network menu starts on Any, which accepts numbers of all the networks below and no others. Pick one of them to accept only its numbers.

First digits and lengths by network

  • Visa: 4, with 13 or 16 to 19 digits
  • Mastercard: 51 to 55 or 2221 to 2720, with 16 digits
  • American Express: 34 or 37, with 15 digits
  • Diners Club: 300 to 305, 36 or 38, with 14 digits
  • Discover: 6011 or 65, with 16 to 19 digits
  • JCB: 35 with 16 digits, or 2131 or 1800 with 15
  • UnionPay: 62 or 67 with 16 digits, or 81 with 16 to 19

How the Luhn check works

Every number also has to pass the Luhn check. Leave the last digit as it is and double every second digit from the one before it, going left. When doubling gives 10 or more, add its two digits together, so 14 counts as 5. Then add up all the digits: the number passes when the total ends in 0. This catches any single mistyped digit and almost every swap of two neighboring digits.

Good to know

  • The check looks at the form only. It can't tell whether a card exists or is still open.
  • The Mastercard rule in validator.js doesn't check the length of numbers that start with 51 to 55: with Any or Mastercard, they pass at any length, even four digits, when the Luhn digit works out.
  • The Credit Card Type Identifier shows which network a number belongs to while you type, and the Luhn number validator runs the Luhn check alone.

Features

  • Checks the network pattern and the Luhn check digit
  • Visa, Mastercard, American Express, Discover, JCB, Diners Club and UnionPay
  • Accepts spaces and hyphens between groups of digits
  • Results as you type, with no button to press
  • Runs in your browser, so nothing you type is sent anywhere