MRZ Parser

MRZ Parser SDK for Passports, ID Cards and Visas

Turn the machine-readable zone of a passport, ID card, visa or residence permit into labeled fields: document type, name, document number, nationality, date of birth, sex and expiry. TD1, TD2 and TD3 parsing follows ICAO Doc 9303, validates every check digit and runs on the device.

MRZ parser icon with stylized MRZ letters over a row of chevrons

From MRZ text to labeled fields

Reading an MRZ takes two steps. The MRZ Scanner SDK finds the zone in the camera frame and reads its characters with on-device OCR. The MRZ parser then splits that text into fields and checks it. This page covers the second step: what the parser extracts, how it validates the data and what your app receives.

Step 1 · Camera

Where the camera part lives

Camera capture, OCR, image extraction, device requirements and the per-platform setup guides are on the MRZ Scanner SDK page. To see parsing on a real document first, open the web MRZ demo and scan a passport or ID card with your camera or from a photo.

Explore the MRZ Scanner SDK →
Step 2 · This page

What the MRZ parser does

  1. Detects the format: TD1, TD2, TD3 or a machine-readable visa
  2. Reads every field from its fixed position
  3. Splits surname and given names at the << separator and removes filler
  4. Validates each check digit and the overall check digit
  5. Returns the fields to your app, on the device

One parser for passports, ID cards, visas and residence permits

The barKoder MRZ parser follows ICAO Doc 9303 and parses passports, visas and national ID cards from most countries, plus residence permits that carry an MRZ. You don't need a separate passport parser, travel visa parser and residence permit parser. The format decides where each field sits, so the parser identifies it first from the line count and line length.

MRZ formats the parser handles
Format Typical documents Lines Field order
TD3 Passport booklets 2 × 44 characters Name on line 1; numbers, dates and check digits on line 2
TD2 Medium-sized cards, some visas and older ID cards 2 × 36 characters Same fields with adjusted line lengths
TD1 National ID cards, passport cards, some driver's licenses 3 × 30 characters Document number on line 1, dates on line 2, name on line 3
MRV-A and MRV-B Machine-readable visas 2 × 44 or 2 × 36 characters Two lines like a passport, with different lengths for the name and optional data

TD3 parsing: field positions in a passport MRZ

A passport parser reads two lines of 44 characters. Every field has a fixed start and end, and the key fields are followed by a check digit.

TD3 layout
Line and positions Field
Line 1: 1–2 Document type, P< for a standard passport
Line 1: 3–5 Issuing country, 3-letter code
Line 1: 6–44 Name: surname, <<, given names, filler
Line 2: 1–9 Document number
Line 2: 10 Check digit for the document number
Line 2: 11–13 Nationality, 3-letter code
Line 2: 14–19 Date of birth, YYMMDD
Line 2: 20 Check digit for the date of birth
Line 2: 21 Sex
Line 2: 22–27 Expiration date, YYMMDD
Line 2: 28 Check digit for the expiration date
Line 2: 29–42 Optional personal number
Line 2: 43 Check digit for the personal number
Line 2: 44 Overall check digit
Sample Ukrainian passport with its MRZ lines highlighted for parsing
A sample passport with its two TD3 lines

Here is the start of the sample MRZ in barKoder's web MRZ demo, and how the parser reads it:

Text
      P<UTOERIKSSON<<ANNA<<<<
      L898902C36UTO7408122F
    

TD1 parsing for ID cards and residence permits

Credit-card sized documents use three lines of 30 characters. The fields are the same as in a passport, in a different order:

  • Line 1: document type, issuing country and document number
  • Line 2: date of birth, sex, expiration date and nationality
  • Line 3: the name

The parser recognizes the 3 × 30 layout and applies the TD1 positions, so your app gets the same field set from an ID card as from a passport.

Back of a sample Swiss ID card with its three MRZ lines highlighted
A sample ID card with three TD1 lines

Names, dates and filler characters

An MRZ only allows the digits 0–9, the capital letters A–Z and the filler character <. These rules decide how each field is cleaned up.

Names

  • The surname comes first, then <<, then the given names separated by single <.
  • Spaces and punctuation inside names are written as <, and unused space is padded with <.
  • Letters with diacritics are transliterated by ICAO rules, for example Ü to UE and ß to SS. Keep that in mind when you match the MRZ name to a name typed by the user.

Dates, sex and optional data

  • Birth and expiration dates use YYMMDD, each followed by a check digit. The year has two digits, so decide how your app assigns the century.
  • Sex is one character: M, F, or < (sometimes X) when unspecified.
  • The optional personal number holds up to 14 characters in passports. Some countries use it for a national ID number; if unused, it is filled with <.

Built-in MRZ checker: check digit validation

The parser validates each check digit and the formatting of every field. A mismatch means the MRZ was read incorrectly or altered, so your app can ask for a rescan instead of saving bad data.

How a check digit is calculated

  1. Convert each character to a value: 0–9 keep their value, A–Z become 10–35, and < is 0.
  2. Multiply the values by the repeating weights 7, 3, 1.
  3. Add the products. The sum modulo 10 is the check digit.

Document number, date of birth and expiration date each have their own check digit, and often the personal number too. The overall check digit at the end of the last line covers the combined fields.

Example: the document number L898902C3

Character L 8 9 8 9 0 2 C 3
Value 21 8 9 8 9 0 2 12 3
Weight 7 3 1 7 3 1 7 3 1
Product 147 24 9 56 27 0 14 36 3

Sum 316 · 316 mod 10 = 6

The MRZ prints 6 after the number, so the field is valid. If OCR reads the second character as B instead of 8, the sum becomes 325, the check digit 5 doesn't match, and the parser flags the field.

What the MRZ parser returns to your app

An MRZ result has the barcode type name MRZ. The parsed fields come with it, so you don't write your own MRZ decoder.

Parsed fields

  • Document type
  • Issuing country or authority
  • Surname and given names
  • Document number
  • Nationality
  • Date of birth
  • Sex
  • Expiration date
  • Optional personal number
  • Check digits

The result text lists the fields as label: value lines. barKoder's Android demo app reads first_name, last_name and document_number from these lines and shows every other label as a row.

Extra data in the result

  • non-formatted: the original key/value pairs extracted from the MRZ
  • raw: the full, unmodified MRZ string
  • JSON: a JSON string with all decoded MRZ data
  • location_picture, location_signature, location_document: corner coordinates, if found

See extra metadata in results for the reference.

Add the passport MRZ parser SDK to your app

MRZ parsing is part of the ID document decoder. Enable it, and every MRZ result arrives already parsed and validated. You need a license key with MRZ enabled.

JavaScript
                      Barkoder.setEnabledDecoders(Barkoder.constants.Decoders.IDDocument);
                    

Web, with the barkoder-wasm-ocr package.

Kotlin
                      private fun setActiveBarcodeTypes() {
                      // There is option to set multiple active barcodes at once as array
                      bkdView.config.decoderConfig.SetEnabledDecoders(
                      arrayOf(
                      Barkoder.DecoderType.IDDocument,
                      )
                      )
                      bkdView.config.decoderConfig.IDDocument.enabled = true
                      }
                    

Android (Kotlin).

Kotlin
                      override fun scanningFinished(results: Array<Barkoder.Result>, thumbnails: Array<Bitmap>, resultImage: Bitmap?) {
                      for (i in results) {
                      if (i.images != null) {
                      for (j in i.images) {
                      when (j.name) {
                      "main" -> mainBitmap = j.image
                      "document" -> documentBitmap = j.image
                      "signature" -> signatureBitmap = j.image
                      "picture" -> pictureBitmap = j.image
                      }
                      }
                      }
                      }
                      }
                    

On Android and iOS, the result can also carry the document images by name: main, document, signature and picture.

MRZ parsing is available on all barKoder platforms and cross-platform frameworks: iOS, Android, Web and desktop, plus Flutter, React Native, Capacitor, Cordova, .NET MAUI and NativeScript. The setup guide for each one is listed on the MRZ Scanner SDK page.

What MRZ parsing proves and what it doesn't

What you get

  • The data printed in the MRZ, as labeled fields
  • Check digits that confirm the zone was read correctly and is internally consistent
  • Dates you can use for expiry and age checks

What you still need to check

  • That the document itself is genuine
  • That it belongs to the person presenting it
  • Any checks your industry or regulator requires

Where teams use MRZ parsing

Whether you verify identity for onboarding, KYC, access control or fleet management, one scan fills the form with clean, labeled fields.

Document data stays on the device

Parsing runs locally, in real time and offline. The SDK goes online only for the license check, at least once every 30 days, and it does not store personal information from scans. Your application decides what it keeps and where it sends it.

Try barKoder on your phone or in your browser

Install the free barKoder demo app, or open the web demo, and scan your own barcodes before you integrate the SDK.

iPhone and iPad

barKoder demo app for iOS

Scan with your camera, or point it at the QR code to open the App Store.

Download on the App Store
QR code linking to the barKoder demo app on the App Store

Android phones and tablets

barKoder demo app for Android

Scan with your camera, or point it at the QR code to open Google Play.

Get it on Google Play
QR code linking to the barKoder demo app on Google Play

Any modern browser

barKoder web demo

Runs the Web SDK in your browser, on desktop or mobile, with nothing to install.

Open the web demo
QR code linking to the barKoder web demo

Test with known samples. Print or display the testing sheet and scan each 1D and 2D barcode with the demo app. The data sheet summarizes the SDK for your team.

MRZ parser questions

What is an MRZ parser?

An MRZ parser turns the two or three lines of an MRZ into labeled fields. MRZ parsing reads each field from its fixed position, removes the < filler, splits the name at << and validates the check digits. barKoder's MRZ parser returns document type, issuing country, name, document number, nationality, date of birth, sex, expiration date and the optional personal number.

Does the parser handle TD1, TD2 and TD3?

Yes. It parses TD3 passports, TD1 and TD2 ID cards and MRV-A and MRV-B visas, as defined in ICAO Doc 9303. That covers passports, national ID cards, travel visas and residence permits that carry an MRZ.

Is there an online MRZ checker or MRZ decoder I can try?

Yes. The web MRZ demo runs in your browser with nothing to install. Scan a passport or ID card with the camera or pick a photo of the page, and it reads the MRZ and its check digits.

Why would an MRZ not be valid?

Each check digit is calculated from its field with the 7-3-1 weights. If the calculated digit doesn't match the printed one, the MRZ was read incorrectly or altered. The document number, date of birth and expiration date each have their own check digit, and the overall check digit covers the combined fields, so a mismatch points to the field that was misread. Rescan the document before you treat it as invalid.

Do I need the MRZ Scanner SDK as well?

The parser works on the text the scanner reads. The MRZ Scanner SDK finds the zone with the camera and reads it with on-device OCR, and the parsed fields come back in the same result. Both are part of the barKoder SDK: enable the ID document decoder with a license key that has MRZ enabled.

Does MRZ parsing need an internet connection?

No. Parsing runs on the device, offline and in real time. The SDK connects only for the license check, at least once every 30 days, and it doesn't store personal information from scans.

Does a valid MRZ prove that a passport is genuine?

No. Check digits show that the MRZ was read correctly and is internally consistent. They don't establish that the document is authentic or that it belongs to the person presenting it, so add the identity checks your application needs.

How do I get a license for the MRZ parser?

Generate a free trial license, valid for 30 days on up to 25 devices. For production, see SDK pricing or request a quote.

Parse passports, ID cards and visas in your app

Test the MRZ parser on your own documents with a free 30-day trial, or talk to an SDK expert about your onboarding or check-in workflow.