Blog · 27 Nov 2026
ZATCA QR Code Explained: TLV, Base64 and the 9 Tags
By Muhammad Hamid · Last reviewed 27 Nov 2026
Free toolZATCA QR Code Generator & Decoder
Build or decode the TLV Base64 QR on Saudi e-invoices. Runs in your browser.
Every e-invoice in Saudi Arabia carries a QR code. When I built ZATCA Phase 2 e-invoicing into a point-of-sale system, the QR was the part that looked easiest and caused the most confusing bugs. This post explains exactly what’s inside it.
If you just want to see one, open the ZATCA QR generator & decoder. It runs in your browser.
The short version
A ZATCA QR code contains a Base64 string. Decode the Base64 and you get a list of TLV records:
| Part | Size | Meaning |
|---|---|---|
| Tag | 1 byte | Which field this is (1–9) |
| Length | 1 byte | How many bytes the value has |
| Value | Length bytes | The field itself, UTF-8 for text fields |
The records are joined back to back, and the whole byte array is Base64-encoded once. That string is what goes in the QR.
The nine tags
| Tag | Field | Phase |
|---|---|---|
| 1 | Seller name | 1 and 2 |
| 2 | Seller VAT registration number | 1 and 2 |
| 3 | Invoice timestamp (date and time) | 1 and 2 |
| 4 | Invoice total, including VAT | 1 and 2 |
| 5 | VAT total | 1 and 2 |
| 6 | Hash of the XML invoice | 2 |
| 7 | ECDSA signature | 2 |
| 8 | ECDSA public key | 2 |
| 9 | ZATCA’s signature of the cryptographic stamp’s public key (simplified invoices) | 2 |
Tags 1–5 are values you already have on the invoice. Tags 6–9 come out of the signing step in Phase 2, so you can’t type them in by hand. Your e-invoicing solution produces them when it signs the invoice XML.
A worked example
Take these five fields:
1 Seller name Bobs Records
2 VAT number 310122393500003
3 Timestamp 2022-04-25T15:30:00Z
4 Total 1000.00
5 VAT 150.00
The first record is tag 01, length 0C (12 bytes, the length of “Bobs Records”), then the 12 bytes of the name:
01 0C 42 6F 62 73 20 52 65 63 6F 72 64 73
Do the same for the other four fields, join them, and Base64-encode the result:
AQxCb2JzIFJlY29yZHMCDzMxMDEyMjM5MzUwMDAwMwMUMjAyMi0wNC0yNVQxNTozMDowMFoEBzEwMDAuMDAFBjE1MC4wMA==
Paste that into the decoder and you’ll get the five fields back.
Mistakes that break ZATCA QR codes
1. Counting characters instead of bytes
The length byte is the number of bytes, not characters. Arabic letters take two bytes each in UTF-8, so a seller name like “شركة التوريدات” is 14 characters but 27 bytes (13 Arabic letters at two bytes each, plus a one-byte space). Use the byte length:
const bytes = new TextEncoder().encode(sellerName);
const length = bytes.length; // not sellerName.length
2. Base64-encoding each field
Encode the whole TLV byte array once. Encoding each value separately and joining the strings produces something that looks similar but won’t decode.
3. Turning bytes into a hex string
Some libraries hand you a hex string like 010c426f.... ZATCA expects Base64 of the raw bytes, not Base64 of the hex text.
4. A malformed VAT number
A Saudi VAT registration number has 15 digits and starts and ends with 3. The generator flags this before it builds the QR.
5. Inconsistent amounts
Tags 4 and 5 should match the invoice: total including VAT, and the VAT amount. Use the same formatting as the invoice, for example 1150.00.
One-byte lengths
The length is a single byte, so a value can be at most 255 bytes. That’s plenty for names, numbers and the Phase 2 signature values, but it’s worth checking if a very long seller name is ever truncated.
Phase 1 vs Phase 2 in practice
- Phase 1 (generation): your system builds the QR from tags 1–5.
- Phase 2 (integration): your solution signs the invoice XML, and the QR includes the hash, signature and key (tags 6–9 as applicable). The QR has to be generated from the signed invoice, so build it in the same step as signing, not separately in the print template.
If you’re integrating Phase 2, the follow-up post shows the code: How to generate a ZATCA QR code in Node.js.
This post explains the data format from hands-on implementation work. It isn’t tax advice. Check ZATCA’s official e-invoicing specifications, or ask your e-invoicing provider, for the rules that apply to your business.
FAQ
Is the ZATCA QR code just the invoice details as text?
No. Each field is stored as tag, length and value bytes (TLV). The records are joined and the result is Base64-encoded. A normal QR scanner shows that Base64 string, not readable fields.
Which tags are needed in Phase 1 and Phase 2?
Phase 1 uses tags 1 to 5: seller name, VAT number, timestamp, invoice total and VAT total. Phase 2 adds tags 6 to 8 (invoice hash, ECDSA signature, public key) and, for simplified invoices, tag 9.
Why does my ZATCA QR fail validation?
The most common causes are counting characters instead of UTF-8 bytes for Arabic text, Base64-encoding each field separately instead of the whole payload, and a VAT number that isn't 15 digits starting and ending with 3.