Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Luhn algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Description== The check digit is computed as follows: # Drop the check digit from the number (if it's already present). This leaves the payload. # Start with the payload digits. Moving from right to left, double every second digit, starting from the last digit. If doubling a digit results in a value > 9, subtract 9 from it (or sum its digits). # Sum all the resulting digits (including the ones that were not doubled). # The check digit is calculated by <math>(10 - (s \bmod 10)) \bmod 10</math>, where s is the sum from step 3. This is the smallest number (possibly zero) that must be added to <math>s</math> to make a multiple of 10. Other valid formulas giving the same value are <math>9 - ((s + 9)\bmod 10)</math>, <math>(10 - s)\bmod 10</math>, and <math>10\lceil s/10\rceil - s</math>. Note that the formula <math>(10 - s)\bmod 10</math> will not work in all environments due to differences in how negative numbers are handled by the [[modulo]] operation. === Example for computing check digit === Assume an example of an account number 1789372997 (just the "payload", check digit not yet included): {| class="wikitable" style="text-align:center;border:none;" ! style="width:1.5em" | Digits reversed | style="width:1.5em" | 7 | style="width:1.5em" | 9 | style="width:1.5em" | 9 | style="width:1.5em" | 2 | style="width:1.5em" | 7 | style="width:1.5em" | 3 | style="width:1.5em" | 9 | style="width:1.5em" | 8 | style="width:1.5em" | 7 | style="width:1.5em" | 1 |- ! Multipliers | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 |- ! | = | = | = | = | = | = | = | = | = | = |- ! | style="background: #FFA; color: #000;" | '''14''' | 9 | style="background: #FFA; color: #000;" | '''18''' | 2 | style="background: #FFA; color: #000;" | '''14''' | 3 | style="background: #FFA; color: #000;" | '''18''' | 8 | style="background: #FFA; color: #000;" | '''14''' | 1 |- ! Sum digits |'''5''' <br> (1+4) |9 <br> |'''9''' <br> (1+8) |2 <br> |'''5''' <br> (1+4) |3 <br> |'''9''' <br> (1+8) |8 <br> |'''5''' <br> (1+4) |1 <br> |} The sum of the resulting digits is 56. The check digit is equal to <math>(10 - (56 \bmod 10))\bmod 10 = 4</math>. This makes the full account number read 17893729974. === Example for validating check digit === # Drop the check digit (last digit) of the number to validate. (e.g. 17893729974 → 1789372997) # Calculate the check digit (see above) # Compare your result with the original check digit. If both numbers match, the result is valid. {{nowrap|1=(e.g. (givenCheckDigit = calculatedCheckDigit) ⇔ (isValidCheckDigit)).}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)