MRZ Check Digit Calculation with 7-3-1 Weights

How passport and ID card MRZ check digits work, with character values, the 7-3-1 weighting, and Python code for validation.

Character values

Digits keep their value, letters A–Z map to 10–35, and the filler < counts as 0.

Extracting It Automatically

When you read this data from photos, the Passport OCR API returns it as structured JSON, and you can apply the rules on this page as validation. Try it with the free scanner.

Where This Fits

  • Weighting: Multiply each character’s value by the repeating weights 7, 3, 1, add the products, and take the remainder after dividing by 10. That remainder is the check digit.
  • Which fields have check digits: On a TD3 passport, the document number, date of birth, and expiry date each have a check digit, and a composite check digit covers several fields together.
Need more testing? Create a free account to get 200 free credits (equals 100 Passport scans).

Python Implementation

A minimal, dependency-free implementation you can use to validate OCR output.

Prerequisite: Python 3.9+

PYTHON EXAMPLE
def mrz_check_digit(field: str) -> int:
    total = 0
    for i, char in enumerate(field):
        if char.isdigit():
            value = int(char)
        elif char.isalpha():
            value = ord(char.upper()) - 55
        else:
            value = 0  # "<" filler
        total += value * (7, 3, 1)[i % 3]
    return total % 10

print(mrz_check_digit("L898902C3"))  # ICAO sample document number -> 6

Technical Specs

  • •Endpoint: POST https://api.structocr.com/v1/passport
  • •Authentication: x-api-key request header
  • •Inputs: JPG, PNG, or WebP as Base64 JSON; maximum 4.5MB
  • •Price: 2 credits per successful request; failed requests are not billed
  • •Free trial: 200 free credits on sign-up, no credit card required

Key Features

  • •Weighting: Multiply each character’s value by the repeating weights 7, 3, 1, add the products, and take the remainder after dividing by 10. That remainder is the check digit.
  • •Which fields have check digits: On a TD3 passport, the document number, date of birth, and expiry date each have a check digit, and a composite check digit covers several fields together.
  • •Validate after OCR: Apply these rules to API output before storing it.

Reference Summary

Key facts from this page in structured form, for quick lookup.

{
  "Character values": "Digits keep their value, letters A–Z map to 10–35, and the filler < counts as 0..",
  "Weighting": "Multiply each character’s value by the repeating weights 7, 3, 1, add the products, and take the remainder after dividing by 10.",
  "Which fields have check digits": "On a TD3 passport, the document number, date of birth, and expiry date each have a check digit, and a composite check digit covers several fields together.."
}

Frequently Asked Questions

Why do check digits matter for OCR?

A mismatch shows that a character was misread, so the application can ask for a better image before storing data.

Do all documents use the same algorithm?

Yes. ICAO Doc 9303 defines the same 7-3-1 method for passports, ID cards, and visas.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

Norway Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Norway passports.

Node.js · Passport
Country Tutorial

Greece Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Greece passports.

Node.js · Passport
Country Tutorial

Algeria Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Algeria passports.

Node.js · Passport
Country Tutorial

Switzerland Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Switzerland passports.

Node.js · Passport
Country Tutorial

Ecuador Passport OCR: Extract Fields with Python

Extract visible fields from Ecuador passport images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Passport
Country Tutorial

Tajikistan Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Tajikistan passports.

Node.js · Passport
Country Tutorial

Tanzania Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Tanzania passports.

Node.js · Passport
Country Tutorial

Tajikistan Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Tajikistan passports with a server-side integration.

Python · Passport
Country Tutorial

Switzerland Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Switzerland passports with a server-side integration.

Python · Passport
Tutorial

MRZ Formats Explained: TD1, TD2, and TD3

The machine readable zone layouts used on passports and ID cards: line counts, line lengths, field positions, and where each format appears.

Passport

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

From tutorial to production in 5 minutes.

You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.

Instant Access Cancel Anytime No Credit Card