Credit Card Number Validator | Luhn Algorithm & Brand Detection

Enter a credit card number to verify its check digit with the Luhn algorithm and automatically detect the brand (Visa, Mastercard, Amex, etc.). Handy for testing form validation.

[[ labels.client_side_note ]]

[[ labels.format_error ]]
[[ labels.sample_label ]]:
[[ labels.no_input ]]

[[ labels.result_label ]]

[[ labels.formatted_label ]] [[ result.formatted ]]
[[ labels.brand_label ]] [[ brandName ]] [[ labels.brand_unknown ]]
[[ labels.checksum_label ]] ✓ [[ labels.checksum_valid ]] ✗ [[ labels.checksum_invalid ]]

Supported Brands and Detection Rules (IIN & Length)

Brand Leading Digits (IIN) Length
Visa 4 13, 16, 19
Mastercard 51–55, 2221–2720 16
American Express 34, 37 15
Discover 6011, 65 16
JCB 3528–3589 16
Diners Club 300–305, 36, 38 14
UnionPay 62 16–19

What this card number validator does

Every credit card number carries a check digit at the end, put there so that typing mistakes can be caught. Running the sequence through the Luhn algorithm finds the great majority of single-digit slips and transpositions of neighbouring digits. This tool performs that check on whatever number you enter and, at the same time, works out the card brand from the leading digits and the length.

The important caveat is that this is a format check and nothing more. Passing the Luhn check does not mean the number belongs to a card that exists, still less that it can be used. Real authorisation has to go through a payment provider’s API. The number you type is processed only in your browser and is never sent anywhere.

How to check a number

  1. Enter the number Spaces and hyphens are stripped automatically, so you can paste a copied value exactly as it is.
  2. Look at the check digit result The outcome of the Luhn algorithm is shown as valid or invalid. If it is invalid, one of the digits is wrong.
  3. Check the detected brand The brand is inferred from the leading digits and the length. The table below sets out the conditions used.
  4. Try the behaviour with a sample The sample button inserts a test number, letting you confirm how the tool behaves without using a real one.

Tips for getting more out of it

  • Try the sample buttons for well-known test numbers (e.g. Visa: 4111 1111 1111 1111) instead of a real card number.
  • Spaces and hyphens are stripped automatically, so you can paste a number copied from anywhere.
  • This tool only checks the format via the Luhn algorithm. For real authorization or balance checks, use your payment processor's API.
  • When building form validation, use this tool to generate both a passing case and a failing case to test your logic.

When the validator is useful

Building validation into a form

Compare the verdict from your own validation against this one. You can line up both passing and failing cases.

Checking brand detection logic

The table shows which brand results from each combination of leading digits and length — useful when you need to display the matching card icon.

Isolating a typing mistake

When a payment will not go through, you can first establish whether the number’s format is already wrong, which shortens the hunt for the cause.

Learning the Luhn algorithm

Change a single digit and you will watch the check flip to invalid, which makes the mechanism concrete in a way a description cannot.

Terms used with card numbers

Luhn algorithm
A calculation that tests whether a sequence of digits is plausible. Working from the right, every second digit is doubled and everything summed; if the total divides by 10, the number is treated as valid.
Check digit
The digit appended at the end so that input errors can be detected. It is derived by calculation from the other positions.
IIN
The issuer identification number at the start of a card number. It identifies both the brand and the issuing institution.
Brand
International brands such as Visa, Mastercard and American Express. The brand is determined from the combination of leading digits and length.
Authorisation
The process that establishes whether a card can actually be used and whether the available limit is sufficient. It is an entirely separate procedure from a format check.

Frequently Asked Questions

No. This tool only performs a Luhn format check — it cannot tell you whether the card actually exists, has been deactivated, or has sufficient funds. Real authorization requires your payment processor's systems.

The number is never sent to a server — all calculation happens in your browser's JavaScript. That said, if you just want to test the tool, we recommend using one of the sample test numbers instead of a real card.

It's an error-detection algorithm devised in 1954 by IBM's Hans Peter Luhn. Starting from the right, every second digit is doubled, and if the total of all digits is a multiple of 10, the format is considered valid. It catches most typos.

It's based on the leading digits (the Issuer Identification Number) combined with the total length. For example, Visa numbers start with "4" and have 13, 16, or 19 digits, Mastercard starts with "51-55" and has 16 digits, and JCB starts with "3528-3589" and has 16 digits — all publicly documented rules. See the "Supported Brands and Detection Rules" table further down this page for the full list.

No. Passing Luhn only confirms the number is internally consistent as a format. Even a made-up 16-digit number can be adjusted at the last digit to pass the Luhn check.
Tool-kun

Side Note — Hans Peter Luhn, the Father of the Check Digit

The check digit at the end of a credit card number is verified using an algorithm devised in 1954 by IBM engineer Hans Peter Luhn. He was awarded a patent for it in 1960, but the patent has long since expired, so the algorithm is now free for anyone to use.

The mechanism is surprisingly simple. Starting from the rightmost digit, every second digit is doubled; if the result is two digits, they are added together (e.g. 8×2=16 → 1+6=7). If the sum of all digits is a multiple of 10, the number is considered formally valid.

The algorithm is used well beyond credit cards — it also catches typos in IMEI numbers (used to identify smartphones) and Canadian Social Insurance Numbers, among others. It is worth remembering that Luhn only detects accidental mistypes; it says nothing about whether the card actually exists or has any balance.

The first 6 to 8 digits of a card number form the Issuer Identification Number (IIN), which identifies the card network and issuing bank. This tool's brand detection is based on the publicly documented IIN ranges for each network.