Luhn Check Digit Calculator

Compute the Luhn check digit for a partial number.

How this tool works

This tool works in the other direction: given the digits of a card number without its last digit, it computes the check digit that should be there. The algorithm is the same one the Luhn checker uses in reverse. You double every second digit from the right of the partial number, subtract 9 from any doubled result above 9, sum those, and the check digit is whatever brings the total up to the next multiple of 10.

This is what a card issuer does at the point of issue. The issuer picks the account number, computes the check digit and prints both, and the network's rule is that a card number is only valid if the last digit is consistent with the rest. It is also what a test suite needs when it generates card numbers, because a generated number without a correct check digit will be rejected by every validator downstream.

Worked example

InputResult
Partial number4242 4242 4242 424
Doubled and reduced digits8 4 8 4 8 4 8 4 8 4 8 4 8 4 8 4
Sum of the partial number72
Check digit to reach the next multiple of 108

Append the 8 and the result is the published test number 4242 4242 4242 4242.

When to use it

Frequently asked questions

How do I calculate a Luhn check digit?

Take the number without its last digit, double every second digit from the right, subtract 9 from any doubled result above 9, sum the digits, and take the difference between that sum and the next multiple of 10. If the sum is already a multiple of 10, the check digit is 0.

Why do I need the check digit when I can just generate a random number?

Because a random number fails the Luhn check about 90% of the time, so a test suite built from random numbers fails at the first validation step. A number with a correct check digit behaves like a real one at every downstream layer.

Does a computed check digit make the number valid?

It makes the number checksum-valid. It has no bearing on whether the account exists or works, and it is not a security measure.

What is the check digit for the number 4242 4242 4242 424?

8. Appended, it gives 4242 4242 4242 4242, the standard published test number.

Can I use this to build working card numbers?

No. It produces numbers that are structurally correct, which is useful for testing, and it produces nothing else. The numbers it produces are not connected to any account.

Related tools

Related guides