Skip to content

Luhn formula

The Luhn formula is the decimal modulus-10 check-digit algorithm that alternately doubles digits, reduces two-digit products, and selects a final digit making the transformed sum divisible by ten.

Version
v2 · 2026-11-14 · History
Domain-specific #
7690
Origin domain
Mathematics Logic Statistics

Core Idea

The Luhn formula, also called the Luhn algorithm, modulus 10, or mod 10 algorithm, is a decimal check-digit procedure for detecting accidental errors in identification numbers. It appends one digit chosen so that a weighted transformation of the complete number has a sum divisible by ten. To calculate the check digit, scan the payload from right to left and double every second digit, beginning with the digit in the appropriate alternating position for an appended check digit.

How would you explain it like I'm…

The Zero-Ending Helper Digit

Some long numbers, like the ones on cards, have one extra helper number at the end. It's picked using a little adding game with all the other digits, so the total comes out to a number ending in zero. If someone types one digit wrong, the adding game won't end in zero, and the computer knows there's a mistake. That trick is the Luhn formula.

The Typo-Catching Check Digit

The Luhn formula is a quick way to catch typing mistakes in long ID numbers, like card numbers. An extra 'check digit' is added at the end. To test a number, go from right to left and double every second digit; if doubling gives more than 9, subtract 9. Add up all the digits. If the total ends in 0 (divisible by 10), the number passes. It catches any single wrong digit and most cases of two neighboring digits swapped. But passing only means the number follows the rule — it doesn't prove the card or account is real.

Luhn Mod 10 Check Digit

The Luhn formula (also called the Luhn algorithm or mod 10) is a decimal check-digit method for catching accidental errors in ID numbers. One digit is appended so that a weighted version of the whole number adds up to a multiple of 10. To compute it, go through the main number from right to left, doubling every second digit in the right positions; if a doubled value is over 9, subtract 9. Add everything and choose the smallest digit 0–9 that brings the total to a multiple of 10. The alternating weights catch every single-digit mistake and almost every swap of neighboring digits, though not 09 swapped with 90. A pass only shows the number is internally consistent: it isn't proof the account exists, it doesn't stop deliberate forgery, and it isn't a cryptographic hash.

 

The Luhn formula (Luhn algorithm, modulus 10, mod 10 algorithm) is a decimal check-digit scheme for detecting accidental errors in identification numbers. A single digit is appended so that a weighted transformation of the full number sums to a multiple of 10. Computing it: scan the payload right to left, doubling every second digit starting from the position that will alternate correctly once the check digit is appended; subtract 9 from any doubled value above 9; sum transformed and untouched digits; and choose the smallest digit 0–9 that makes the total divisible by 10. Validation repeats the transformation over the whole number and checks the congruence, or recomputes the check digit and compares. The alternating weights detect every single-digit substitution and nearly all adjacent transpositions, though 09↔90 and some paired substitutions go undetected; leading zero padding does not change the result provided it leaves the operative parity unchanged. A passing check establishes only consistency with the numbering rule, not issuer authenticity, account existence or resistance to forgery, and Luhn is not a cryptographic hash. Luhn mod N generalizes the construction to non-decimal alphabets and is a broader neighboring algorithm, not a synonym.

Scope of Application

The Luhn formula applies to decimal identifiers whose issuer has adopted its terminal check-digit convention: alternating right-to-left doubling, subtract-nine reduction, and a transformed sum divisible by ten. Its reach is limited to accidental-error screening and internal consistency; each identifier scheme must separately establish that it uses ordinary Luhn rather than another mod-10 or modified rule.

  • Payment-card numbers — generate and validate the decimal check digit under the issuer-numbering convention.
  • IMEI equipment identifiers — screen entered device numbers for consistency with the adopted Luhn position and parity.
  • CUSIP identifiers — apply the relevant Luhn-based check convention while respecting the identifier's declared character handling.
  • United States National Provider Identifiers — validate the decimal check digit under the scheme's prescribed Luhn treatment.

Clarity

Passing a Luhn check means that a decimal identifier is internally consistent with one check-digit rule; it does not mean that the issuer assigned it, the account exists, or the presenter is authorized to use it. That distinction keeps transcription screening separate from authentication and cryptographic integrity. A deliberately fabricated number can easily be given a valid Luhn digit.

Manages Complexity

Identification schemes vary in issuer, length, grouping, and business meaning, but their decimal transcription check can be reduced to a payload, a check-digit position, an alternating parity, a digit transform, and one modulus-10 remainder. Implementers need not encode separate error logic for every identifier family: scanning from the check-digit end, doubling the designated positions, reducing products above nine, and summing yields either the required check digit or a single validity result.

Abstract Reasoning

Luhn reasoning maps a decimal digit string to one modular invariant. From a payload with a declared check-digit position, to the check digit, the algorithm fixes right-to-left parity, doubles alternating digits, subtracts nine from products above nine, and selects the digit that makes the transformed sum congruent to zero modulo ten. Running the same transform in reverse use—from a complete identifier to a validity result—tests consistency with that rule without consulting the identifier's issuer or record system.

Knowledge Transfer

Within identifier validation, the Luhn formula transfers literally across account, card, and reference-number systems that adopt its decimal check-digit convention. The cargo that carries intact is the payload digits, check-digit position, right-to-left alternating parity, doubling transform, subtraction of nine for products above nine, and divisibility-by-ten invariant. Diagnostics transfer by recomputing the check digit, testing a complete identifier, and locating parity or digit-order mistakes. This is (C) a formal algorithm wherever that exact convention is used.

Relationships to Other Abstractions

Local relationship map for Luhn formulaParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Luhn formulaDOMAINDomain-specific abstraction: Luhn Mod N Algorithm — is a kind ofLuhn Mod NAlgorithmDOMAIN

Current abstraction Luhn formula Domain-specific

Parents (1) — outgoing typed relations

  • Luhn formula is a kind of Luhn Mod N Algorithm Domain-specific

    Luhn Formula strictly instantiates the general check-character scheme with the ordered alphabet fixed to decimal digits, N fixed to 10, the selected-position operation fixed to doubling followed by subtract-nine reduction, and a terminal digit chosen to complete the zero congruence.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Luhn formula sits in a sparse region of the domain-specific corpus (82nd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (3155 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14