Card Number Formatter

Format a card number into groups and validate its checksum.

Related tools

How this tool works

Card numbers are printed in groups of four digits, separated by spaces, and that grouping is a convention rather than part of the data. A number entered without spaces is the same number, and any system that compares card numbers must normalise before comparing or it will reject a correctly typed number.

This tool groups a number for display and strips everything that is not a digit before it does so, so a number typed with spaces, dashes, full stops or a copied paste artefact comes out in the conventional grouping. It also reports the detected brand and the length, which are the two things a checkout usually needs alongside the formatting.

Worked examples

InputOutput
42424242424242424242 4242 4242 4242
4242-4242-4242-42424242 4242 4242 4242
4242 4242 4242 42424242 4242 4242 4242
3782822463100053782 822463 10005

American Express groups in fours of four plus three, which is why the last group is shorter.

When to use it

Frequently asked questions

Why format a card number?

The grouping is what people recognise, and it makes transcription errors visible. It also makes a stored number comparable, provided both sides are normalised first.

Should I store card numbers with spaces?

No. Store the digits only, or better, store a token instead of the number. Formatting is a display concern and should be applied on the way out, not the way in.

Does the formatting affect the Luhn check?

No. The checksum works on the digits, so the grouping and separators are irrelevant to it.

Why does American Express have a different grouping?

It is a 15 digit number, so a strict grouping of four leaves a final group of three. The convention follows the number.

Is it safe to paste a card number into a web form?

Only into a form that is served over TLS and that you trust. A page that receives a full card number is a page with cardholder data on it, and it comes with obligations under PCI DSS.