# 卢恩算法

卢恩算法（Luhn algorithm），又称模10算法，是一种简单的校验和公式，用于验证信用卡号、IMEI（国际移动设备识别码）号码和美国国家提供者标识符等标识号码。它由IBM科学家[汉斯·彼得·卢恩](https://www.edgepedia.org/zh/hans-peter-luhn)（Hans Peter Luhn）于1954年提出，至今仍是支付卡主账号最常用的校验位机制。<sup>[1](https://www.cupass.com/en/learn/luhn-guide.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 创造者 | IBM科学家、70项IBM专利持有人汉斯·彼得·卢恩；算法描述于1954年1月6日提交的一项专利申请中<sup>[1](https://www.cupass.com/en/learn/luhn-guide.html)</sup><sup> • </sup><sup>[2](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)</sup> |
| 专利 | “用于验证数字的计算机”（Computer for Verifying Numbers），美国专利US 2,950,048，1954年1月6日申请，1960年8月23日授予，转让给IBM<sup>[3](https://patents.google.com/patent/US2950048)</sup><sup> • </sup><sup>[4](https://sites.google.com/site/calculatinghistory/home/checksum-calculators)</sup> |
| 方法 | 从右数每隔一位将数字加倍，把任何两位数的乘积的各位相加，将全部结果相加，要求总和能被10整除<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup> |
| 其他名称 | 卢恩公式、模10、模10算法；在ANSI标准X4.13中定义<sup>[6](https://patents.google.com/patent/US7333956)</sup> |
| 主要用户 | 信用卡主账号（ISO/IEC 7812）、IMEI移动设备号码、美国国家提供者标识符<sup>[7](https://www.gsma.com/newsroom/wp-content/uploads/TS.06-v16.0.pdf)</sup><sup> • </sup><sup>[8](https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf)</sup> |
| 能检测什么 | 单个数字错误和相邻两位数字的换位；漏检123变成321这类跳跃换位<sup>[3](https://patents.google.com/patent/US2950048)</sup><sup> • </sup><sup>[9](https://github.itlym.cn/zero-context/checkdigit-atlas)</sup> |
| 不能做什么 | 号码通过检验，只说明它可能是有效号码，并不证明账户已经开立并处于活动状态<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup> |

## 校验原理

该算法在一个号码的右端附加一位数字，即校验位。计算这一位时，要使整个号码（含校验位）在经过交叉相加处理——其中隔位的数字用替代值替换——之后结果为零。<sup>[3](https://patents.google.com/patent/US2950048)</sup>

在现代验证形式中，步骤如下：<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup>

1. 从右数第二位开始，将每隔一位的数字加倍；若加倍后的值大于10，则减去9（等价于把乘积的两位数字相加，例如18记为1 + 8 = 9）。<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup><sup> • </sup><sup>[6](https://patents.google.com/patent/US7333956)</sup>
2. 将加倍后的值与未被加倍的数字相加。<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup>
3. 若总和能被10整除，该号码有效。<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup>

若要生成校验位而非验证一个完整号码，则对基础号码计算同样的总和，校验位就是使总和达到下一个10的倍数所需的数值。美国医疗保险和医疗补助服务中心（Centers for Medicare and Medicaid Services）将其描述为：用下一个以零结尾的更高数减去该总和；若总和本身已以零结尾，则校验位为零。<sup>[8](https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf)</sup>

卢恩最初的表述在呈现方式上略有不同。对于10位数字，他的手提计算机将每隔一位的数字加倍，把任何大于或等于10的结果的各位相加，再将全部十位数字相加，总和乘以9，取结果的最后一位。在这一原始方案中，0表示该号码有效；在后来的版本中，计算出的校验值直接作为最后一位附加在末尾。<sup>[2](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)</sup>

## 起源

**卢恩其人。** 汉斯·彼得·卢恩1896年生于德国巴门（Barmen），受训成为印刷工，1924年赴美国。他先从事纺织贸易，其间发明了至今仍在销售的卢诺计（Lunometer）织物纱线密度测量规，之后加入IBM并在那里度过整个职业生涯，最终获得70项专利。他的核心兴趣是信息的存储、传输与检索，尤其是文本。<sup>[2](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)</sup>

**1954年的专利。** 1954年1月6日，卢恩就“用于验证数字的计算机”（Computer for Verifying Numbers）提交美国专利申请，那是一台手持机械装置，用于计算校验位并验证已经带有校验位的号码。它针对的是一个实际问题：信用卡号、社会保障号等标识号码正被广泛使用，但这些号码难以记忆，可能在转录中出错或被人故意伪造，因此需要一种快速检验有效性的手段。<sup>[2](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)</sup> 专利描述了该装置在多位数用于零件订购、制造、开票、发货和结算等场景中的用途：号码首次分配时附加一位校验位，此后即可验证。<sup>[3](https://patents.google.com/patent/US2950048)</sup> 该专利于1960年8月23日授予。<sup>[3](https://patents.google.com/patent/US2950048)</sup>

卢恩更早的一项IBM专利“自校验号码穿孔机”（Self-Checking Number Punch）于1951年11月14日提交、1956年1月17日授予，已经描述了底层的校验原理：在原始号码后附加一位检验位或校验位，其选取要使按替代规则对所有数字作交叉相加、舍去十的倍数后结果为零。<sup>[10](https://patents.google.com/patent/US2731196A/en)</sup>

## 应用领域

**支付卡。** ANSI标准X4.13规定了识别信用卡号时最广泛使用的校验方式，其名称为卢恩和模10。<sup>[6](https://patents.google.com/patent/US7333956)</sup> 支付卡行业安全标准委员会（Payment Card Industry Security Standards Council）指出，卢恩公式（即模10）是验证主账号最常用的算法。<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup> 卡号体系本身，包括发卡机构标识号和主账号格式，由[ISO/IEC 7812](https://www.edgepedia.org/zh/iso-iec-7812)-1规定，该标准由[ISO/IEC JTC 1](https://www.edgepedia.org/zh/iso-iec-jtc-1)/SC 17维护，最近一次确认是在2022年。<sup>[11](https://www.iso.org/standard/70484.html)</sup>

**移动设备。** 分配给手机的IMEI（国际移动设备识别码）的校验位，按通过ISO/IEC 7812引用的卢恩公式计算。校验位是IMEI中所有其他数字的函数，基于前14位数字计算，两位的软件版本号不计入。其目的是防止向设备身份寄存器输入错误，并发现读取或人工转录IMEI时的差错。<sup>[7](https://www.gsma.com/newsroom/wp-content/uploads/TS.06-v16.0.pdf)</sup>

**医疗保健标识符。** 美国国家提供者标识符（National Provider Identifier，NPI）是10位数字标识符，由9位数字加上一位用卢恩公式计算的校验位组成，这一位称为模10“双加双”校验位，并被认定为ISO标准。当NPI在标准健康标识卡上充当发卡机构标识符时，其前面要加前缀80840；为使任何NPI都能以一致方式校验，缺少该前缀时，计算中会加上常数24。<sup>[8](https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf)</sup> 后来的健康计划标识符沿用同一模式：一个10位纯数字标识符，第10位为卢恩校验位。<sup>[12](https://www.govinfo.gov/content/pkg/FR-2012-09-05/pdf/2012-21238.pdf)</sup>

## 错误检测能力与局限

专利本身指出了要针对的错误：抄录多位数时，一种常见错误是把两位数字对调，而用替代隔位数字的交叉相加方案能够检测出这种错误。<sup>[3](https://patents.google.com/patent/US2950048)</sup> 提供这种保护的是加倍这一步，因为它使施加于某位数字的权重取决于其位置。

这种保护是部分的。一项对十种校验位方案进行的实测比较，针对注入的380万个错字，发现卢恩算法对跳跃换位的漏检率为100%——跳跃换位指相隔一位的两位数字被互换，例如123变成321。<sup>[9](https://github.itlym.cn/zero-context/checkdigit-atlas)</sup> 后来的单校验位方案弥补了这一缺口：基于二面体群D5中乘法的弗尔霍夫算法（Verhoeff algorithm）能检测所有单数字替换和相邻换位，对照表显示，弗尔霍夫算法和达姆算法（Damm）能捕获所有单个错误和所有相邻互换。<sup>[13](https://search.r-project.org/CRAN/refmans/CheckDigit/html/verhoeff.html)</sup><sup> • </sup><sup>[14](https://www.matpic.com/essays/ten-digits-need-a-symmetry-that-does-not-commute/)</sup> 一项对巴西标识符体系的调查同样发现，在用的体系（包括卢恩算法）没有一个能检测所有错误类型。<sup>[15](https://www.scielo.br/j/tema/a/88GcJSStDvNchc3X5jGWnZc/?lang=en)</sup>

对任何解读校验结果的人来说，有一点实际的限定很重要：通过卢恩公式只说明某个[支付卡号](https://www.edgepedia.org/zh/payment-card-number)是一个可能成立、形式有效的号码，并不说明它确实已被发行并处于活动状态。<sup>[5](https://www.pcisecuritystandards.org/faqs/1137/)</sup>

## 卢恩更广泛的影响

校验位只是卢恩造机器的众多产物之一。按《IEEE Spectrum》的说法，他那台手持验证器的齿轮与转轮成了散列（hashing）的基础——散列是一类把数据组织进编号“桶”中以便计算机快速查找的算法；他的分桶方案把电话号码的数字两两分组，每组相加，保留两位数结果的末位。散列如今支撑着密码学、图形学、电信和生物学。卢恩还在1958年国际科学信息会议上展示了一套IBM系统，可基于他的上下文关键词（KWIC）方法自动生成文献索引。<sup>[2](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)</sup>

校验和本身几乎没有变化。卢恩描述的那套计算步骤如今被称为模10算法，在专利申请七十多年后仍被广泛使用。<sup>[2](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)</sup>

## References

1. [Luhn Algorithm (Mod 10) — Developer Guide, CUPASS](https://www.cupass.com/en/learn/luhn-guide.html)
2. [Hans Peter Luhn and the Birth of the Hashing Algorithm, IEEE Spectrum](https://spectrum.ieee.org/hans-peter-luhn-and-the-birth-of-the-hashing-algorithm)
3. [US2950048A — Computer for Verifying Numbers, Google Patents](https://patents.google.com/patent/US2950048)
4. [Calculating History — Checksum calculators](https://sites.google.com/site/calculatinghistory/home/checksum-calculators)
5. [How can I validate if a number is a legitimate credit card number? PCI Security Standards Council FAQ 1137](https://www.pcisecuritystandards.org/faqs/1137/)
6. [US7333956B2 — Information management system, Google Patents](https://patents.google.com/patent/US7333956)
7. [GSMA TS.06 v16.0 — IMEI Allocation and Approval Process](https://www.gsma.com/newsroom/wp-content/uploads/TS.06-v16.0.pdf)
8. [Requirements for National Provider Identifier (NPI) and NPI Check Digit, CMS](https://www.cms.gov/Regulations-and-Guidance/Administrative-Simplification/NationalProvIdentStand/Downloads/NPIcheckdigit.pdf)
9. [checkdigit-atlas: Luhn misses 100% of jump transpositions, GitHub](https://github.itlym.cn/zero-context/checkdigit-atlas)
10. [US2731196A — Self-checking number punch, Google Patents](https://patents.google.com/patent/US2731196A/en)
11. [ISO/IEC 7812-1:2017 — Identification cards — Identification of issuers — Part 1: Numbering system, ISO](https://www.iso.org/standard/70484.html)
12. [Federal Register Vol. 77, No. 172 (September 5, 2012), Health Plan Identifier final rule](https://www.govinfo.gov/content/pkg/FR-2012-09-05/pdf/2012-21238.pdf)
13. [Verhoeff algorithm implementation, R CRAN CheckDigit documentation](https://search.r-project.org/CRAN/refmans/CheckDigit/html/verhoeff.html)
14. [Ten digits need a symmetry that does not commute, Matpic](https://www.matpic.com/essays/ten-digits-need-a-symmetry-that-does-not-commute/)
15. [Optimal Check Digit Systems Based on Modular Arithmetic, SciELO (Tema)](https://www.scielo.br/j/tema/a/88GcJSStDvNchc3X5jGWnZc/?lang=en)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Numerical, string, and geometric algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/luhn-algorithm

English original: https://www.edgepedia.org/luhn-algorithm
