Luhn Algorithm Test: How the Mod 10 Check Works

Our Cards

Choose from any of our gift cards to give to your loved ones

more on this topic

giftcardimage

Where to Use?

Redeem your gift cards at any of our Merchants

How to Test the Luhn Algorithm for Card Security

Where to Buy?

You can purchase a gift card from any of these locations

luhn algorithm checker

ABOUT US

about

What is ONYX GiftCards?

Onyx Gift Cards is a Grenadian company designed to introduce, market and manage gift cards systems in Grenada for retailers and corporations. We are enthusiastic about the effect and influence we will have on the local market. We intend to expand our systems regionally with a range of product offerings and services.

What is a Gift Card?

Gift cards are the preferred way of giving and receiving gifts. They carry a monetary value that can be redeemed for gifts at your favorite store.
Onyx GiftCards are “Open Gift Cards” which means that they can be redeemed at multiple merchant locations. They are standard credit card size, can fit into the average wallet and made of PVC plastic. Onyx GiftCards are Barcoded for security and safety for the consumer and bear a disclaimer at the back.
Onyx Giftcards can be bought with a branded Card backer which is black in colour and is designed to fit the card. There is an area to write a brief message to the recipient as well.

How it Works?

  • Buy an Onyx Gift Card at these local stores
  • Give your gift card to friends, family, co-workers, etc.
  • The recipient can shop at our select merchants nationwide
  • Your friends, family, co-workers, etc. will present their gift card at checkout to pay for your item(s)
  • They will walk away happy with the best gift ever...the gift of Choice

Why ONYX GiftCards?

  • Save TIME. No need to run around looking for the perfect gift
  • Redeem from a variety of business island-wide. We will continue adding businesses as fast as ONYX grows.
  • ONYX Gift Cards do not expire
  • Cards are valued at convinient amounts to meet every need and occasion

The Luhn algorithm test checks whether a string of digits has a valid format. It doubles every second digit from the right, adds all the digits together, and passes the number when the total is a multiple of 10. It catches typos and most swapped digits, but it says nothing about whether the card, account, or device behind that number exists.

What does the Luhn algorithm test check?

Luhn is a checksum, also called a modulus 10 or mod 10 check. The last digit of the number is a check digit calculated from every digit before it. Change one digit anywhere in the string and the sum stops dividing by 10.

IBM engineer Hans Peter Luhn filed the patent in 1954, and the method spread into banking, telecom, and government numbering systems. It was built for keypunch operators typing long numbers into cards, where a single mistyped digit caused real damage.

How do you run a Luhn check by hand?

  1. Write the digits in order and ignore spaces or dashes.
  2. Starting from the rightmost digit, count positions. Leave the first digit (the check digit) alone.
  3. Double the value of every digit in an even position counting from the right.
  4. If a doubled value is 10 or more, subtract 9 from it. That keeps the result a single digit.
  5. Add the untouched digits and the doubled digits together.
  6. The number is valid when the total ends in 0.

Worked example with 79927398713

Reading right to left, the digits in even positions are 1, 8, 3, 2 and 9. Doubling gives 2, 16, 6, 4 and 18. After subtracting 9 from the two large values, they become 7 and 9.

The doubled column adds to 2 + 7 + 6 + 4 + 9 = 28. The digits left alone (3, 7, 9, 7, 9, 7) add to 42. The total is 70, which is 7 × 10, so 79927398713 passes.

Now change the 8 to a 5. The sum moves by 7 and lands on 63. The check fails at once.

Which numbers use the Luhn check?

Card issuers rely on it because it stops most accidental keystroke errors before a request ever reaches the network. That is the whole purpose. It is a typing filter, not a gate.

Does a passing Luhn test mean a card is real?

No. A number that passes the Luhn check is a number that is spelled correctly. Nothing more.

A valid checksum can sit on a closed account, a canceled card, an expired card, or a number someone invented. Authorization, balance, address verification, and fraud screening all happen elsewhere. The Luhn digit carries no identity, no bank code, and no balance.

This is why a checksum pass is weak evidence on its own. It proves format. It does not prove life.

How do you code a Luhn check?

Treat the input as a string, not an integer. Long card numbers overflow 32-bit types and lose digits when converted.

Python

def luhn_ok(number):
    digits = [int(d) for d in str(number) if d.isdigit()]
    total = 0
    for i, d in enumerate(reversed(digits)):
        if i % 2 == 1:
            d *= 2
            if d > 9:
                d -= 9
        total += d
    return total % 10 == 0

JavaScript

function luhnOk(value) {
  const digits = String(value).replace(/\D/g, '');
  let total = 0;
  for (let i = 0; i < digits.length; i++) {
    let d = Number(digits[digits.length - 1 - i]);
    if (i % 2 === 1) { d *= 2; if (d > 9) d -= 9; }
    total += d;
  }
  return total % 10 === 0;
}

What mistakes break a Luhn implementation?

Frequently asked questions

Is the Luhn algorithm the same as a mod 10 check?

Yes. Luhn is the best-known mod 10 checksum, and the terms are used as synonyms. Other mod 10 schemes exist with different weightings, so name the algorithm when precision matters.

Can the Luhn test detect every error?

No checksum can. Luhn handles single-digit slips and most transpositions but allows the 09 and 90 swap and some two-digit mistakes. Its error detection rate sits near 98% for realistic typing errors.

Why do so many random numbers pass?

One in ten strings passes by chance, because the final digit is free to be anything from 0 to 9. With four billion 16-digit combinations, roughly 400 million pass the check. That is why the test filters typos and nothing else.

Does the Luhn check apply to CVV codes?

No. Three- and four-digit security codes are short, and adding a checksum digit would leave too few digits to carry useful data. They are validated against the issuer's records instead.

Is a Luhn validation a security feature?

No. It is an input validation step that catches typing mistakes. Anyone can compute the check digit for any prefix, so the algorithm offers zero protection against invented numbers.

Contact Us

Latest

Latest

CVV Attack Alert

Stay protected with our CVV Attack Alert system. Get instant notifications and safeguard your finances.

CVV Attack Pattern

Discover the ins and outs of CVV attack patterns to protect your online transactions.

CVV Attack IOCs: Signals to Monitor

CVV attack IOCs are the log signals of a card-testing run: authorization bursts, high decline rates, narrow BIN sets, and low dollar amounts.

Read our complete guide: Should You Buy CVV From a Card Shop? The Honest Buyer's Guide