{
  "id": "check-digit",
  "version": "80da0f05a9ea",
  "status": "published",
  "name": "Check Digit Calculator",
  "question": "What is the check digit?",
  "summary": "Works out the check digit of a number with the Luhn, GS1 (UPC, EAN, ISBN-13), ISBN-10 or ISO 7064 MOD 97-10 method, or checks whether a full number has the right one.",
  "category": "logic",
  "subcategory": "binary",
  "url": "https://www.acalculator.org/logic/check-digit-calculator",
  "markdown": "https://www.acalculator.org/logic/check-digit-calculator.md",
  "kind": "function",
  "method": "Luhn: double every second digit from the right of the payload (subtract 9 from results over 9), sum, check = (10 − sum mod 10) mod 10. GS1: weights 3, 1, 3, … from the right of the payload, check = (10 − sum mod 10) mod 10. ISBN-10: weights 2 to 10 from the right, check = (11 − sum mod 11) mod 11, 10 written X. MOD 97-10: check = 98 − (payload × 100 mod 97), two digits.",
  "assumptions": [
    "Spaces and hyphens are ignored; every other character must be a digit (X only as the last ISBN-10 character).",
    "In check mode the last digit (the last two for MOD 97-10) is the check digit.",
    "A valid check digit catches typing slips; it does not show that a card, product or book exists."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "m": {
        "title": "Method",
        "description": "The check digit method the number uses.",
        "type": "string",
        "enum": [
          "luhn",
          "gs1",
          "isbn10",
          "mod97"
        ]
      },
      "do": {
        "title": "I want to",
        "description": "Make the check digit for a number, or check a full number that ends in its check digit.",
        "type": "string",
        "enum": [
          "make",
          "check"
        ]
      },
      "n": {
        "title": "Number",
        "description": "The digits, without the check digit to make one, or with it to check one. Spaces and hyphens are ignored.",
        "type": "string",
        "maxLength": 140
      }
    }
  },
  "outputs": {
    "result": {
      "label": "Answer",
      "description": "The check digit and the full number, or whether the full number is valid.",
      "format": "text"
    },
    "digit": {
      "label": "Check digit",
      "description": "The check digit the payload needs (two digits for MOD 97-10; X stands for 10 in ISBN-10).",
      "format": "text"
    },
    "full": {
      "label": "Full number",
      "description": "The payload followed by its check digit.",
      "format": "text"
    },
    "valid": {
      "label": "Valid",
      "description": "In check mode: whether the last digit (or two) is the right check digit.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "m": "luhn",
      "do": "make",
      "n": "7992739871"
    },
    "outputs": {
      "result": "Check digit 3: 79927398713",
      "digit": "3",
      "full": "79927398713"
    },
    "text": "7992739871: Check digit 3: 79927398713."
  },
  "examples": [
    {
      "given": {
        "m": "luhn",
        "do": "make",
        "n": "7992739871"
      },
      "expect": {
        "digit": "3",
        "full": "79927398713",
        "result": "Check digit 3: 79927398713"
      },
      "source": "Wikipedia, \"Luhn algorithm\" (example 7992739871, check digit 3), https://en.wikipedia.org/wiki/Luhn_algorithm (retrieved 2026-10-05); hand calculation in content.mdx"
    },
    {
      "given": {
        "m": "gs1",
        "do": "make",
        "n": "03600024145"
      },
      "expect": {
        "digit": "7",
        "full": "036000241457"
      },
      "source": "Wikipedia, \"Check digit\", UPC example 036000241457, https://en.wikipedia.org/wiki/Check_digit (retrieved 2026-10-05); hand calculation in content.mdx"
    },
    {
      "given": {
        "m": "gs1",
        "do": "check",
        "n": "978-0-7475-3269-9"
      },
      "expect": {
        "valid": "Yes",
        "digit": "9",
        "result": "Valid"
      },
      "source": "Wikipedia, \"Check digit\", ISBN-13 example 978-0-7475-3269-9, https://en.wikipedia.org/wiki/Check_digit (retrieved 2026-10-05); hand calculation in content.mdx"
    },
    {
      "given": {
        "m": "isbn10",
        "do": "check",
        "n": "0-201-53082-1"
      },
      "expect": {
        "valid": "Yes",
        "digit": "1"
      },
      "source": "Wikipedia, \"Check digit\", ISBN-10 example 0-201-53082-1 (weighted sum 99 = 9 × 11), https://en.wikipedia.org/wiki/Check_digit (retrieved 2026-10-05)"
    },
    {
      "given": {
        "m": "isbn10",
        "do": "make",
        "n": "080442957"
      },
      "expect": {
        "digit": "X",
        "full": "080442957X"
      },
      "source": "hand calculation in content.mdx: weighted sum 199 = 18 × 11 + 1, so 11 − 1 = 10, written X"
    },
    {
      "given": {
        "m": "mod97",
        "do": "check",
        "n": "3214282912345698765432161182"
      },
      "expect": {
        "valid": "Yes",
        "digit": "82",
        "result": "Valid"
      },
      "source": "Wikipedia, \"International Bank Account Number\" (GB82 WEST 1234 5698 7654 32; W = 32, E = 14, S = 28, T = 29, G = 16, B = 11), https://en.wikipedia.org/wiki/International_Bank_Account_Number (retrieved 2026-10-05); hand calculation in content.mdx"
    }
  ],
  "sources": [
    "Wikipedia, \"Luhn algorithm\": the method and the example 7992739871 with check digit 3. https://en.wikipedia.org/wiki/Luhn_algorithm (retrieved 2026-10-05)",
    "Wikipedia, \"Check digit\": UPC-A (036000241457), ISBN-10 (0-201-53082-1) and ISBN-13 (978-0-7475-3269-9) methods and examples. https://en.wikipedia.org/wiki/Check_digit (retrieved 2026-10-05)",
    "Wikipedia, \"International Bank Account Number\": ISO 7064 MOD 97-10 check digits, 98 minus the remainder. https://en.wikipedia.org/wiki/International_Bank_Account_Number (retrieved 2026-10-05)",
    "Wikipedia, \"ISBN\": ISBN-10 weights 10 to 1 and the check character X. https://en.wikipedia.org/wiki/ISBN (retrieved 2026-10-05)"
  ],
  "related": [
    "base-converter",
    "iban",
    "binary"
  ],
  "changelog": []
}
