hZqr against the alternatives, and against itself.
Everything on this page is measured on documents the dictionaries were never trained on, with the set used to choose what to ship kept separate from the set used to score it. Where a number was wrong, the old one is still here next to the new one, because the size of a correction is worth as much as the correction.
Every compressing-QR design is three separate decisions: how the payload is packed, how the packed bytes are written into the symbol, and whether the two ends share a dictionary. Here is what each combination costs, on 136 documents none of the dictionaries had seen.
| Approach | How it packs | Payload | QR characters | QR version | Fits one symbol |
|---|---|---|---|---|---|
| Uncompressed | the text, byte mode | 3,121 B | 3,060 | 32 | 57 / 136 |
| Hex + dictionary | hex → zlib + dict → hex | 1,100 B | 2,200 | 27 | 121 / 136 |
| SMART Health Cards | deflate → base64url → digits | 946 B | 2,527 | 23 | 126 / 136 |
| EU covid certificate | CBOR → zlib → Base45 | 962 B | 1,447 | 22 | 128 / 136 |
| Plain deflate | zlib → Base45 | 946 B | 1,418 | 22 | 128 / 136 |
| hZqr, no dictionary | brotli → Base45 | 800 B | 1,208 | 20 | 130 / 136 |
| hZqr | brotli + dict → Base45 | 504 B | 770 | 16 | 130 / 136 |
| hZqr, compact header | brotli + dict → Base45 | 504 B | 758 | 15 | 130 / 136 |
| hZqr, packed | brotli + dict → packed base-44 | 504 B | 741 | 15 | 132 / 136 |
The last three rows carry identical payloads and differ only in how the header and the alphabet are written — which is the honest way to read them, and why the structure transform appears nowhere in this table. It is measured on its own below.
Read those two middle columns against each other. SMART Health Cards and plain deflate produce identical payloads — 946 bytes — and SMART Health Cards needs 78 % more of the symbol, because mapping base64url to pairs of decimal digits throws away most of what the alphanumeric mode would have given it. The hexadecimal scheme is the mirror image: a larger payload than either, 1,100 bytes, yet fewer characters than SMART Health Cards.
So a comparison in bytes ranks these designs differently from a comparison in symbol capacity, and only the second one decides whether a code can be printed. That is why every figure on this page is in QR characters and measured QR versions, with the version read back from the rendered symbol rather than computed from a table.
| Layer | Worth | Measured against |
|---|---|---|
| A shared dictionary | 67.5 % | the same codec with none |
| Structure transform | 18.3 % | on top of a dictionary (35.9 % without one; 8.3 % with a real codec) |
| Alphabet | 3.0 % | packed base-44 against Base45 |
| Codec | 1.0 % | brotli against zlib, both with a dictionary |
The dictionary is worth more than the other three together, and the ordering is stable across every family measured. Choosing a compressor is close to the least important decision in the system.
Same documents, same 32 kB dictionaries, so only the algorithm differs:
| no dictionary | with a dictionary | |
|---|---|---|
| brotli -q11 | 739 B | 240 B |
| zlib -9 | 867 B | 242 B |
| zstd -19 | 884 B | 256 B |
brotli wins, but by one per cent over zlib — not the ten per cent we quoted before measuring it properly. zlib's decoder is a third the size and its format carries a dictionary-identity check that brotli's does not, which makes it the better choice for an embedded reader and the worse one for nothing in particular.
Zstandard trails both by about seven per cent. We expected the gap to be brotli's built-in 120 kB dictionary of ordinary web vocabulary, and tested it by compressing structure-stripped streams that contain far less of that. The gap narrowed by 1.5 points. The hypothesis was wrong, and whatever gives brotli its lead is something else.
Two designs carry structured health data through a QR code today. The EU Digital COVID Certificate deflates a CBOR token and writes it in Base45. SMART Health Cards deflates a signed token, writes it in base64url, and maps each character to two digits so the symbol can use numeric mode. Neither uses a dictionary.
136 held-out documents, seven payload families, error correction level L, QR versions read back from the rendered symbol rather than computed from a table.
| median QR characters | fits in one symbol | |
|---|---|---|
| Uncompressed | 3,062 | 57 / 136 |
| SMART Health Cards | 2,541 | 126 / 136 |
| EU Digital COVID Certificate | 1,450 | 128 / 136 |
| Plain deflate + Base45 | 1,427 | 128 / 136 |
| hZqr | 746 | 132 / 136 |
Uncompressed, 58 % of these documents do not fit in a QR code at all. That is the baseline every one of these designs exists to move.
On HL7 FHIR JSON specifically, hZqr reaches QR version 9 where both deployed designs reach version 22 — 36 modules a side against 105, which is the difference between a code that scans across a room and one that does not.
A compressing QR format has four places to spend effort. Measured separately they look like they should sum; crossed against each other, they do not.
| worth | note | |
|---|---|---|
| The dictionary | 67.5 % | more than the other three combined |
| The structure layer | 18.3 % | on top of a dictionary; 35.9 % on its own, 8.3 % with a codec that decodes |
| The codec | 1.0 % | brotli over zlib; 6.9 % over zstd |
| The alphabet | 3.0 % | Base45 to a packed base-44 bitstream |
The interaction is the useful part. The better a structure layer performs alone, the more of its work the dictionary has already done. An elaborate encoding that types every value — constants as nothing, enums as an index, dates as integers — beats simply omitting the field names by ten points when there is no dictionary, and loses to it by four points when there is one. Sixty-nine per cent of what it achieves has already been collected.
The reason is not subtle once you see it. A dictionary is shared knowledge about bytes; a schema is shared knowledge about structure; and in a document whose structure is repeated bytes, those are two descriptions of the same redundancy. Worse, the clever layer damages the dictionary: replacing enum strings with indices removes exactly the byte sequences the dictionary was built from.
So with a dictionary present, build the simplest structure layer, not the cleverest. That is the opposite of the intuitive answer, and it saves an entire subsystem.
Three were measurements that flattered the thing being measured. The fourth was different in kind, and it reached this page.
The structure layer: 35 % → 18.3 % → 8.3 %. The first number left out the dictionary the layer would be competing with. The second used a one-way proxy that emits the values and assumes the receiver already knows the shape — true only if the shape never varies, and in FHIR it varies in every document. A codec that actually decodes has to send the shape, and that costs 46 bytes of a 211-byte payload. The code never got worse. The measurement got honest.
A summary row that contradicted its own experiment. The table above used to say the structure layer was worth "6.7 % on top of a dictionary, 18.3 % on its own". Both labels were wrong, and the 6.7 % had no measured source anywhere — it appeared only in summary rows, never in an experiment. 18.3 % is the figure for the structure layer on top of a dictionary, measured twice independently; without a dictionary it is 35.9 %. The row is corrected above, and recorded here rather than quietly fixed, because the first three errors were caught by measuring more honestly and this one was caught only by reading our own experiment against our own summary of it.
The corpus: 31.0 % → 24.8 %. It was never deduplicated. An audit found 92 byte-identical duplicates, one test document with an identical twin in training, and a news feed harvested twice under two addresses that compressed 15,218 bytes to 24. Two families were near-copies of themselves — and they were precisely the two reporting the best savings. Bicycle-share feeds fell from 90.7 % to 8.3 %. Weather went from 55.8 % to not measurable at all: after excluding near-copies it had no test documents left.
zlib: "10 % behind brotli" → 1.0 %. The old figure compared brotli with a dictionary against zlib without one. Measured properly — same documents, same dictionaries — zlib is one per cent behind, at a third of the decoder footprint and with a dictionary-identity check built into its format that brotli does not have.
A compression result measured on a harvested corpus without deduplication should be assumed inflated until shown otherwise.
Converting to hexadecimal first makes everything bigger. All 2,560 documents tested, across two corpora and three codecs, by 20–35 %. Hexadecimal doubles the number of symbols while halving the information in each, which pushes every match length and back-reference into longer codes and destroys the byte alignment the compressor's modelling assumes. As a transport alphabet it costs another third of the code's capacity.
The instinct behind it was half right. A table mapping field names to short codes is worth having — but the saving comes from the table, not from hexadecimal.
CBOR buys nothing once you compress. 1,450 characters against 1,427 for plain minified JSON through the same compression — very slightly worse. CBOR removes the quoting that the compressor removes for free, and adds length prefixes that do not compress.
Naming dictionaries after document types loses to measuring them. A library of 71 dictionaries clustered by what documents actually contain beat a library of 1,000 named after document types — 330 bytes against 662, at a quarter of the storage — and still won on the named library's own ground, 486 against 590.
81 dictionaries, 2.5 MB, chosen by greedy selection over measured savings on held-out documents, with a floor so that a narrow but highly compressible family is not starved by a large one. 30 of them carry a structure transform that was chosen by measurement rather than assumed; 50 carry none, because none was measured to be better.
Across 33 payload families it takes the median payload from 920 to 728 bytes.
Prose is where it stops helping: Markdown gains about 12 %, plain text essentially nothing. Structure is what pays, and a document that is mostly unique sentences has none to share.
Each dictionary is capped at 32 kB. The number came from a comment in our own source attributing it to brotli's compression window. Brotli's window is 4 MB, so the cap was a third of a figure that was already wrong.
Raising it costs storage and nothing else — no format change, no new code — and across 17 payload families it is worth a median 9.8 % and a mean of 18.5 %. FHIR JSON improves by 56 %. And it reverses the paragraph above: with a big enough dictionary, plain text becomes the best earner per kilobyte, because what drives the gain is document size, not structure.
The honest complication is that there is no single right size. The point where a family stops benefiting ranges from 48 kB to 2,048 kB — a factor of 43 — so one global cap is the wrong instrument at any value. A rule that scales with how much material a family has, clamp(5 % of available, 32 kB, 256 kB), buys a median 1.9 % for 2 MB of dictionaries, and beats allocating greedily at the same storage.
None of this is shipped yet. It is the largest unclaimed gain we have measured.
A QR code is readable by anyone with a phone. Carrying a prescription needs encryption, under a constraint the channel sets: the payload must not grow, because a symbol that no longer fits one code has lost the point.
That rules out RSA. An RSA ciphertext is the size of the key whatever goes in, its padding costs 66 bytes before anything else, and the only key size big enough to hold a typical payload directly caps the message below our median. What works at zero cost is a one-time key as long as the payload, combined with a length-preserving permutation.
Both layers are needed, and this is why:
| what an attacker does to the printed code | key alone | permutation | both |
|---|---|---|---|
| flips one bit | 90 of 293 accepted | 0 of 293 | 0 of 293 |
| flips eight bits | 0 of 293 | 0 of 293 | 0 of 293 |
A one-time key is unbreakable but perfectly malleable — flipping a bit in the code flips exactly that bit in the document, so someone who cannot read a prescription can still change a dose from 10 to 11, and in 31 % of real cases the reader accepted it. The permutation makes any change randomise the whole document, and then it fails to decode.
How hard is it to break? Three very different answers:
| the attacker has | work |
|---|---|
| neither the code nor the key | impossible, not merely hard |
| the password but not the key | impossible — the password helps not at all |
| the key but not the password | 2 042 GPU-years at 50 bits; 7.5 days on 100 000 GPUs |
The first two are not "very expensive". For a 504-byte payload there are more possible keys than there are plausible documents by an enormous margin, so every possible document is equally consistent with the code and there is nothing to choose between them. More computing power does not help.
What no amount of cleverness provides is proof of who wrote it. Anyone with the key can make a code that decodes perfectly, so a pharmacy cannot tell a forgery from a genuine prescription. A signature is the fix and it cannot be free: RSA-2048 with a signature costs 544 bytes, which cuts the largest document a QR code can hold from 2 929 to 2 385 bytes. For clinical use that is the right trade. Which signature algorithm is set by what the reader's certificate chain can check: SITHS end-entity certificates are documented as RSA 2048–4096, giving the 544 bytes above, while mobile SITHS also documents ECDSA on P-256, whose signature is about 72 bytes instead of 256. We could not establish what eIDAS qualified certificates require, so the RSA figure is the conservative one and a cheaper path may well be available.
Encryption is no longer only designed. An encrypted code is a fifth payload type, HZ1:E<KEYID>:, and the key id replaces the codec letter and the profile id together, because the codec, profile and dictionary move into the key record the decoder fetches.
| the same FHIR bundle | characters |
|---|---|
| profile code, readable | 318 |
| the same, encrypted with a key record | 317 |
| the same, encrypted fetch-free, needing no server at all | 325 |
The Base45 body is character for character identical in all three — that is what length-preserving means. Only the header differs, and the two encrypted forms differ in opposite directions.
The key-record form moves the codec, profile and dictionary off the wire into a record the decoder fetches, so its header is one character shorter than the readable profile code, and a bystander can no longer tell a prescription from a train ticket by looking at the symbol. It costs a fetch on every read, and the code dies if the key server does.
The fetch-free form does the opposite: the envelope stays on the paper with a per-code salt, so the reader needs the paper and the password and nothing else — offline, with the server gone, for as long as the paper lasts. Seven characters, and the document kind is visible again. Proven by stopping the server and reading the code anyway.
The password belongs to the profile, not the code. A reader is given it once; the memory-hard half of the derivation is salted by the profile and cached, so the second code of a profile costs one HMAC instead of another 150–400 ms on a phone.
Encryption is not part of the profile, and that is deliberate. A profile is public, shared and immutable; a key is per code, secret and revocable. A profile may demand encryption, and then the encoder refuses to produce a readable code for it — but the key and the password never live in it.
Three suites, differing in what can be taken back: the password alone, with no secret stored on the server at all; the password plus a server-held key that can be deleted, which revokes every code under it permanently; and the password plus a one-time matrix that can be destroyed on first read. The password is what protects the content. The key record has to be public, or no decoder could resolve it, so the server key and the matrix do not keep the content from someone who scanned the code and has a network. Encryption without a password is obfuscation plus revocation, and the encoder refuses it.
The working report is the short version — what was measured, what is broken, what comes next. The paper is the argued version, with threats to validity. Each experiment in research/ states the claim it tested, where its corpus came from, the result, what it does not show, and the commands that reproduce it.