Saved

Press the star next to a tool's name to save it.

All my tools

Credit Card Validator

Type a card number and this credit card validator checks it with the Luhn algorithm and names the card network. The check runs in your browser, and the number is never stored or sent.

Checked 100% in your browser. Nothing you type is sent, saved or logged.

Spaces and dashes are fine. Use test numbers when you're checking a payment form.

The number is checked in your browser. It's never stored, logged or sent anywhere.

Luhn check

–

Enter a card number and press Check number.

This credit card validator checks whether a card number is correctly formed. Type or paste the number, and it runs the Luhn algorithm, the check that card numbers are built to pass, and tells you which card network the number belongs to. Everything happens in your browser: the number isn't stored, logged or sent to any server. It's a format check only. It's handy for catching a typing mistake, and for developers who are testing a payment form with test numbers.

What is the Luhn algorithm?

The Luhn algorithm, also known as the modulus 10 or mod 10 algorithm, is a simple check digit formula used to validate a variety of identification numbers. It was created by the IBM scientist Hans Peter Luhn. Its purpose is to design a numbering scheme so that, when a person enters a number, a computer can quickly check it for errors. The algorithm is in the public domain and is specified in ISO/IEC 7812-1. Most credit card numbers and many government identification numbers use it to tell valid numbers from mistyped ones.

How the Luhn check works

  1. Start from the right-hand end of the number and move left.
  2. Double every second digit. The last digit, which is the check digit, is left as it is.
  3. If a doubled digit is more than 9, subtract 9 from it.
  4. Add up all the digits.
  5. If the total ends in 0, the number passes.

How to use the credit card validator

  1. Enter the card number. You can include spaces or dashes.
  2. Press Check number.
  3. Read the result: whether the number passes, the card network, and whether the length is right for that network.

Worked example

Take the test number 4111 1111 1111 1111. Working from the right, every second digit is doubled. The seven 1s in those positions become 2s, and the 4 at the far left becomes 8. The other eight digits are 1s. The total is 8 + 7 × 2 + 8 × 1, which is 30. That ends in 0, so the number passes the Luhn check. It starts with 4 and has 16 digits, so the validator reports Visa with the right length. Change the last digit to 2 and the total becomes 31, so the check fails, and the tool tells you that the check digit should be 1.

How the card network is identified

The card number prefix identifies the issuer of the card, and card numbers are allocated in accordance with ISO/IEC 7812. The validator compares the first digits and the length with the published ranges.

NetworkStarts withLength
Visa413, 16 or 19
Mastercard51–55, 2221–272016
American Express34, 3715
Discover6011, 644–649, 6516–19
JCB3528–358916–19
Diners Club International30, 36, 38, 3914–19
China UnionPay6216–19
Maestro5018, 5020, 5038, 5893, 6304, 6759, 6761–676312–19
RuPay60, 81, 82, 50816
Mir2200–220416–19

Some prefixes are shared between networks. Numbers that start with 65, for example, are listed for both Discover and RuPay, and this tool shows them as Discover.

What a pass does and doesn't tell you

The Luhn algorithm was designed to protect against accidental errors, not malicious attacks, and it isn't a security feature. A number that passes is consistent with the way card numbers are built. It doesn't mean that the card exists, that it's active, that it has funds or that it belongs to the person using it. Only the card issuer can confirm those things, when a payment is authorized.

Which mistakes the check catches

The Luhn algorithm detects all single-digit errors, as well as almost all transpositions of adjacent digits. It won't, however, detect the swap of the two-digit sequence 09 to 90, or the other way round. It detects most twin errors, where a pair of identical digits is replaced by another pair, with a few exceptions such as 22 and 55. So if a number fails, there's almost certainly a typing mistake in it, and if it passes, a mistake is unlikely but not impossible.

Your number stays private

The check is a small piece of arithmetic that runs on your own device. The number you type isn't uploaded, saved in your browser or included in any analytics. The result shows only the last four digits. Even so, it's good practice to use a test number, and not a real card, whenever you're simply trying out a form.

Testing a payment form

If you're building or testing a checkout page, you need numbers that pass the Luhn check without belonging to anyone. Use a test number from your payment provider's documentation, and never a real customer's card. Paste the test number here to confirm that it's well-formed and to see which network your form should detect. One more detail helps when you write your own check: because the algorithm works from right to left, adding zeros to the front of a number doesn't change the result, so the check can be run before or after any padding.

Common mistakes

  • Treating a pass as proof that a card is real. It's a format check.
  • Leaving out a digit. Check the count: most cards have 16 digits, and American Express has 15.
  • Typing the expiry date or security code. Enter only the long card number.
  • Entering a bank account number. Account numbers follow different rules.

Check a phone number's format with the phone number validator, test a password with the password strength checker, and create a hash with the SHA-256 hash generator.

What next

Use this often? Add Credit Card to your Home screen.

Frequently asked questions

How does the credit card validator work?

It runs the Luhn algorithm on the digits and compares the first digits and the length with the published ranges for each card network.

Does a valid result mean the card is real?

No. It means the digits are consistent. Only the card issuer can confirm that a card exists and is active.

Is my card number stored or sent anywhere?

No. The check runs in your browser, and the number is never stored, logged or sent.

What is a check digit?

It's the last digit of the number. It's chosen so that the whole number passes the Luhn check.

Which errors does the Luhn algorithm catch?

All single-digit errors and almost all swaps of two adjacent digits. It can't detect a swap of 09 and 90.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools