<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Luhn_algorithm</id>
	<title>Luhn algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Luhn_algorithm"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Luhn_algorithm&amp;action=history"/>
	<updated>2026-07-18T23:43:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Luhn_algorithm&amp;diff=353123&amp;oldid=prev</id>
		<title>imported&gt;JJMC89 bot III: Removing :Category:Eponymous algorithms of mathematics per Wikipedia:Categories for discussion/Log/2025 October 27#Eponyms in mathematics round 2</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Luhn_algorithm&amp;diff=353123&amp;oldid=prev"/>
		<updated>2025-11-09T22:45:52Z</updated>

		<summary type="html">&lt;p&gt;Removing &lt;a href=&quot;/index.php?title=Category:Eponymous_algorithms_of_mathematics&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Eponymous algorithms of mathematics (page does not exist)&quot;&gt;Category:Eponymous algorithms of mathematics&lt;/a&gt; per &lt;a href=&quot;https://en.wikipedia.org/wiki/Categories_for_discussion/Log/2025_October_27#Eponyms_in_mathematics_round_2&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Categories for discussion/Log/2025 October 27&quot;&gt;Wikipedia:Categories for discussion/Log/2025 October 27#Eponyms in mathematics round 2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Simple checksum formula}}&lt;br /&gt;
{{redirects|Luhn|people named Luhn|Luhn (surname)}}&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Luhn algorithm&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;Luhn formula&amp;#039;&amp;#039;&amp;#039; (creator: [[IBM]] scientist [[Hans Peter Luhn]]), also known as the &amp;quot;[[modular arithmetic|modulus]] 10&amp;quot; or &amp;quot;mod 10&amp;quot; [[algorithm]], is a simple [[check digit]] formula used to validate a variety of identification numbers. {{efn|It is described in [[United States|US]] patent 2950048A, granted on {{date|1960-08-23|DMY}}.&amp;lt;ref name=&amp;quot;US2950048A&amp;quot;&amp;gt;{{cite patent|title=Computer for Verifying Numbers|country=US|number=2950048A|status=patent|pubdate={{date|1960-08-23|DMY}}|gdate={{date|1960-08-23|DMY}}|invent1=Luhn|inventor1-first=Hans Peter|fdate=1954-01-06|inventorlink=Hans Peter Luhn}}&amp;lt;/ref&amp;gt;}} The purpose is to design a numbering scheme in such a way that when a human is entering a number, a computer can quickly check it for errors. &lt;br /&gt;
&lt;br /&gt;
The algorithm is in the [[public domain]] and is in wide use today. It is specified in [[ISO/IEC 7812-1]].&amp;lt;ref&amp;gt;{{cite tech report|title=Identification cards {{mdash}} Identification of issuers {{mdash}} Part 1: Numbering system|number=[[ISO/IEC 7812]]-1:{{date|2017|DMY}}|institution=[[International Organization for Standardization]] &amp;amp; [[International Electrotechnical Commission]]|date={{date|Jan 2017|DMY}}|type=standard|url=https://www.iso.org/standard/70484.html|chapter=Annex B: Luhn formula for computing modulus-10 “double-add-double” check digits}}&amp;lt;/ref&amp;gt; It is not intended to be a [[cryptographic hash function|cryptographically secure hash function]]; it was designed to protect against accidental errors, not malicious attacks. Most [[credit card number]]s and many [[government identification numbers]] use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers.&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
The check digit is computed as follows:&lt;br /&gt;
# Drop the check digit from the number (if it&amp;#039;s already present). This leaves the payload.&lt;br /&gt;
# 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 &amp;gt; 9, subtract 9 from it (or sum its digits). &lt;br /&gt;
# Sum all the resulting digits (including the ones that were not doubled).&lt;br /&gt;
# The check digit is calculated by &amp;lt;math&amp;gt;(10 - (s \bmod 10)) \bmod 10&amp;lt;/math&amp;gt;, where s is the sum from step 3.  This is the smallest number (possibly zero) that must be added to &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to make a multiple of 10. Other valid formulas giving the same value are &amp;lt;math&amp;gt;9 - ((s + 9)\bmod 10)&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;(10 - s)\bmod    10&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;10\lceil s/10\rceil - s&amp;lt;/math&amp;gt;. Note that the formula &amp;lt;math&amp;gt;(10 - s)\bmod 10&amp;lt;/math&amp;gt; will not work in all environments due to differences in how negative numbers are handled by the [[modulo]] operation.&lt;br /&gt;
&lt;br /&gt;
=== Example for computing check digit ===&lt;br /&gt;
&lt;br /&gt;
Assume an example of an account number 1789372997 (just the &amp;quot;payload&amp;quot;, check digit not yet included):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;border:none;&amp;quot; &lt;br /&gt;
! style=&amp;quot;width:1.5em&amp;quot; | Digits reversed&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 7&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 9&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 9&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 2&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 7&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 3&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 9&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 8&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 7&lt;br /&gt;
| style=&amp;quot;width:1.5em&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
! Multipliers&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
| 2&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
! &lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
| =&lt;br /&gt;
|-&lt;br /&gt;
! &lt;br /&gt;
| style=&amp;quot;background: #FFA; color: #000;&amp;quot; | &amp;#039;&amp;#039;&amp;#039;14&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| 9&lt;br /&gt;
| style=&amp;quot;background: #FFA; color: #000;&amp;quot; | &amp;#039;&amp;#039;&amp;#039;18&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| 2&lt;br /&gt;
| style=&amp;quot;background: #FFA; color: #000;&amp;quot; | &amp;#039;&amp;#039;&amp;#039;14&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| 3&lt;br /&gt;
| style=&amp;quot;background: #FFA; color: #000;&amp;quot; | &amp;#039;&amp;#039;&amp;#039;18&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| 8&lt;br /&gt;
| style=&amp;quot;background: #FFA; color: #000;&amp;quot; | &amp;#039;&amp;#039;&amp;#039;14&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
! Sum digits&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;5&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt; (1+4)&lt;br /&gt;
|9 &amp;lt;br&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;9&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt; (1+8)&lt;br /&gt;
|2 &amp;lt;br&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;5&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt; (1+4)&lt;br /&gt;
|3 &amp;lt;br&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;9&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt; (1+8)&lt;br /&gt;
|8 &amp;lt;br&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;5&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt; (1+4)&lt;br /&gt;
|1 &amp;lt;br&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The sum of the resulting digits is 56.&lt;br /&gt;
&lt;br /&gt;
The check digit is equal to &amp;lt;math&amp;gt;(10 - (56 \bmod 10))\bmod 10 = 4&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This makes the full account number read 17893729974.&lt;br /&gt;
&lt;br /&gt;
=== Example for validating check digit ===&lt;br /&gt;
&lt;br /&gt;
# Drop the check digit (last digit) of the number to validate. (e.g. 17893729974 &amp;amp;rarr; 1789372997)&lt;br /&gt;
# Calculate the check digit (see above)&lt;br /&gt;
# Compare your result with the original check digit. If both numbers match, the result is valid. {{nowrap|1=(e.g. (givenCheckDigit = calculatedCheckDigit) &amp;amp;hArr; (isValidCheckDigit)).}}&lt;br /&gt;
&lt;br /&gt;
==Strengths and weaknesses==&lt;br /&gt;
The Luhn algorithm will detect all single-digit errors, as well as almost all transpositions of adjacent digits.  It will not, however, detect transposition of the two-digit sequence &amp;#039;&amp;#039;09&amp;#039;&amp;#039; to &amp;#039;&amp;#039;90&amp;#039;&amp;#039; (or vice versa). It will detect most of the possible twin errors (it will not detect &amp;#039;&amp;#039;22&amp;#039;&amp;#039; ↔ &amp;#039;&amp;#039;55&amp;#039;&amp;#039;, &amp;#039;&amp;#039;33&amp;#039;&amp;#039; ↔ &amp;#039;&amp;#039;66&amp;#039;&amp;#039; or &amp;#039;&amp;#039;44&amp;#039;&amp;#039; ↔ &amp;#039;&amp;#039;77&amp;#039;&amp;#039;).&lt;br /&gt;
&lt;br /&gt;
Other, more complex check-digit algorithms (such as the [[Verhoeff algorithm]] and the [[Damm algorithm]]) can detect more transcription errors. The [[Luhn mod N algorithm]] is an extension that supports non-numerical strings.&lt;br /&gt;
&lt;br /&gt;
Because the algorithm operates on the digits in a right-to-left manner and zero digits affect the result only if they cause shift in position, zero-padding the beginning of a string of numbers does not affect the calculation.  Therefore, systems that pad to a specific number of digits (by converting 1234 to 0001234 for instance) can perform Luhn validation before or after the padding and achieve the same result.&lt;br /&gt;
&lt;br /&gt;
The algorithm appeared in a United States Patent&amp;lt;ref name=&amp;quot;US2950048A&amp;quot; /&amp;gt; for a simple, hand-held, mechanical device for computing the checksum. The device took the mod 10 sum by mechanical means. The &amp;#039;&amp;#039;substitution digits&amp;#039;&amp;#039;, that is, the results of the double and reduce procedure, were not produced mechanically. Rather, the digits were marked in their permuted order on the body of the machine.&lt;br /&gt;
&lt;br /&gt;
== Pseudocode implementation ==&lt;br /&gt;
&lt;br /&gt;
The following function takes a card number, including the check digit, as an array of integers and outputs &amp;#039;&amp;#039;&amp;#039;true&amp;#039;&amp;#039;&amp;#039; if the check digit is correct, &amp;#039;&amp;#039;&amp;#039;false&amp;#039;&amp;#039;&amp;#039; otherwise.&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;function&amp;#039;&amp;#039;&amp;#039; isValid(cardNumber[1..length])&lt;br /&gt;
     sum := 0&lt;br /&gt;
     parity := length mod 2&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;for&amp;#039;&amp;#039;&amp;#039; i from 1 to (length - 1) &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; i mod 2 == parity &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
             sum := sum + cardNumber[i]&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;elseif&amp;#039;&amp;#039;&amp;#039; cardNumber[i] &amp;gt; 4 &amp;#039;&amp;#039;&amp;#039;then&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
             sum := sum + 2 * cardNumber[i] - 9&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;else&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
             sum := sum + 2 * cardNumber[i]&lt;br /&gt;
         &amp;#039;&amp;#039;&amp;#039;end if&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;end for&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
     &amp;#039;&amp;#039;&amp;#039;return&amp;#039;&amp;#039;&amp;#039; cardNumber[length] == ((10 - (sum mod 10)) mod 10)&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;end function&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Uses ==&lt;br /&gt;
The Luhn algorithm is used in a variety of systems, including:&lt;br /&gt;
* [[Payment card number|Credit card numbers]]&lt;br /&gt;
* [[International Mobile Equipment Identity|IMEI numbers]]&lt;br /&gt;
* [[CUSIP]] numbers for North American financial instruments&lt;br /&gt;
* [[National Provider Identifier|National Provider Identifier numbers]] in the United States&lt;br /&gt;
* [[Canada|Canadian]] [[social insurance number]]s&lt;br /&gt;
* [[Israeli identity card|Israeli]] ID numbers&lt;br /&gt;
* [[South Africa|South African]] ID numbers&lt;br /&gt;
* [[South Africa|South African]] Tax reference numbers&lt;br /&gt;
* [[Personal identity number (Sweden)| Swedish Personal identity numbers ]]&lt;br /&gt;
* [[Sweden|Swedish]] Corporate Identity Numbers (OrgNr)&lt;br /&gt;
* [[Greece|Greek]] Social Security Numbers (ΑΜΚΑ)&lt;br /&gt;
* [[SIM_card#ICCID|ICCID]] of SIM cards&lt;br /&gt;
* [[European Patent Convention|European patent]] application numbers&lt;br /&gt;
* Survey codes appearing on [[:File:McDonalds Receipt Luhn Algorithm.png|McDonald&amp;#039;s]], [[:File:Taco Bell Receipt Luhn Algorithm.png|Taco Bell]], and [[:File:Tractor Supply Receipt Luhn Algorithm.png|Tractor Supply Co.]] receipts&lt;br /&gt;
* [[United States Postal Service]] package tracking numbers use a modified Luhn algorithm&amp;lt;ref&amp;gt;{{Cite book |url=https://postalpro.usps.com/mnt/glusterfs/2023-10/Pub%20199_v28_10102023.pdf |title=Publication 199: Intelligent Mail Package Barcode (IMpb) Implementation Guide for Confirmation Services and Electronic Payment Systems |date={{date|2023-10-10|DMY}} |publisher=[[United States Postal Service]] |edition=28th |location=[[United States]] |language=en |access-date={{date|2023-11-29|DMY}} |archive-url=https://web.archive.org/web/20231117004502id_/https://postalpro.usps.com/mnt/glusterfs/2023-10/Pub%20199_v28_10102023.pdf |archive-date={{date|2023-11-17|DMY}} |url-status=live}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* Italian VAT numbers ([[VAT identification number#European Union VAT identification numbers|Partita Iva]])&amp;lt;ref&amp;gt;{{Cite web |last=Albanese |first=Ilenia |date={{date|2022-08-10|DMY}} |title=A cosa serve la Partita Iva? Ecco cosa sapere |trans-title=What is a VAT number for? Here&amp;#039;s what to know |url=https://www.partitaiva.it/partita-iva-cosa-serve/ |url-status=live |archive-url=https://web.archive.org/web/20240629162018/https://www.partitaiva.it/partita-iva-cosa-serve/ |archive-date={{date|2024-06-29|DMY}} |access-date={{date|2024-06-29|DMY}} |website=Partitaiva.it |language=it}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
{{notelist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers Luhn test of credit card numbers] on [[Rosetta Code]]: Luhn algorithm/formula implementation in 160 programming languages {{As of|1=2024|2=07|3=22|lc=y|url=https://rosettacode.org/w/index.php?title=Luhn_test_of_credit_card_numbers&amp;amp;action=history}}&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Luhn Algorithm}}&lt;br /&gt;
[[Category:Modular arithmetic]]&lt;br /&gt;
[[Category:Checksum algorithms]]&lt;br /&gt;
[[Category:Error detection and correction]]&lt;br /&gt;
[[Category:1954 introductions]]&lt;br /&gt;
[[Category:Articles with example pseudocode]]&lt;/div&gt;</summary>
		<author><name>imported&gt;JJMC89 bot III</name></author>
	</entry>
</feed>