Inside the ZATCA QR Code: TLV Records, Base64 and Common Mistakes
How the ZATCA e-invoice QR code is built: TLV tags 1 to 5, UTF-8 byte lengths, base64 encoding, phase 2 tags and how to decode and check a code yourself.

Inside the ZATCA QR Code: TLV Records, Base64 and Common Mistakes
Scan the QR code on a receipt from a Saudi shop with an ordinary QR reader and you get a strange string of letters, numbers and slashes. That string is not random: it is a compact record of the invoice, built to a format set by the Zakat, Tax and Customs Authority. Once you know the format, you can create, read and check these codes yourself. The ZATCA E-Invoice QR Code Generator and Decoder does both directions in the browser.
Tag, length, value
The payload is a series of records. Each record has three parts:
- Tag: one byte that says which field it is.
- Length: one byte with the number of bytes in the value.
- Value: the text itself, encoded as UTF-8.
The records are joined one after another, and the whole byte string is then encoded as base64. That base64 text is what the QR code carries.
The five phase 1 tags
- Tag 1: seller name
- Tag 2: VAT registration number
- Tag 3: time stamp of the invoice
- Tag 4: invoice total including VAT
- Tag 5: VAT total
For example, a seller called "Example Trading Est." gives tag 1 with a length of 20, since that name is 20 bytes. The VAT number 310122393500003 gives tag 2 with a length of 15. A total of 1150.00 is written as text, so tag 4 has a length of 7.
Bytes, not characters
The most common bug in home-made systems concerns Arabic names. In UTF-8, each Arabic letter takes two bytes. A seller name of four Arabic letters, such as شركة, has a length of 8, not 4. Systems that write the number of characters instead of bytes produce codes that the official app cannot read. The decoder in the tool shows the byte length of each record so you can spot the problem at once.
Other frequent mistakes
- Totals written with commas, such as 1,150.00, or with a currency sign.
- A VAT number with spaces or the wrong number of digits.
- A time stamp in a local format such as 28/10/2026 instead of ISO 8601.
- Swapping tags 4 and 5, so the VAT looks bigger than the total.
- Adding the same tag twice.
The checks in the tool look for all of these.
Phase 2 tags
In the integration phase, invoices are produced by a compliant e-invoicing solution and the QR code carries more tags: 6 for the hash of the invoice XML, 7 for the ECDSA signature, 8 for the public key and, for simplified invoices, 9 for the stamp signature of ZATCA's certificate. These values are binary and long. The decoder lists them in short form, but they can only be created by a certified solution with its own keys, so the generator does not make them.
Using the decoder
Paste the base64 text from your system, or load a photo or screenshot of the QR code. The tool reads it locally in your browser, splits it into records and shows a table of tag, meaning, byte length and value. A message at the top says whether all five phase 1 fields are present and well formed.
Batch work
Accountants and developers often need to check many invoices. In batch mode, paste one line per invoice. Lines with five comma-separated values are turned into codes; lines with base64 text are decoded. The table shows the status of each line, and you can download it as a CSV file for a spreadsheet.
A quick test
Create a code with the seller name, a valid VAT number, the current time, a total of 1150.00 and VAT of 150.00. Copy the base64 into decode mode. You should see five tags with byte lengths of 20, 15, 19, 7 and 6 and no issues.
Limits
The tool checks the structure of the QR payload and some format rules. It does not confirm that an invoice was reported to ZATCA, that a seller is registered, or that a phase 2 signature is valid. It is not tax advice. For official validation, use ZATCA's own tools and your certified solution's reports.



