A QR code carries more than your message. It also carries spare data computed from the message, so that a scanner which misreads a few squares can work out what they should have been. That spare data is error correction, and it is the reason a scratched, smudged or logo-covered code still opens the right page.
The four levels
When you make a code you pick one of four error-correction levels. Each reserves a different share of the code for repair data.
- L (low) 7%
- M (medium) 15%
- Q (quartile) 25%
- H (high) 30%
- L (low) can repair about 7% of the codewords. For screens and very large signs that will never be touched.
- M (medium) repairs about 15%. The default for most printed codes.
- Q (quartile) repairs about 25%. For codes that will get dirty: workshops, outdoors, kitchens.
- H (high) repairs about 30%. For a logo in the middle, or the harshest conditions.
The letters are not in order of strength, which trips people up. From weakest to strongest they run L, M, Q, H.
What 15% actually means
The percentage is not a share of the picture. It is a share of codewords. A codeword is a group of 8 modules, the smallest unit the repair maths works on.
Take a version 1 code, 21 modules across. It has 441 modules, but only 208 of them carry codewords; the rest are finder patterns, timing lines and format bits. Those 208 modules form 26 codewords. At level M, 16 of the 26 hold your text and 10 are repair codewords. Ten repair codewords can fix up to 5 wrong codewords, and 5 of 26 is a little under 20%. The nominal 15% is an average across all 40 versions.
Now the catch. One wrong module spoils its whole codeword. If a speck of dirt covers 5 modules that happen to sit in 5 different codewords, you have used 5 of your 5 repairs. Damage is far more forgiving when it is one solid blob than when it is scattered, because a blob hits fewer codewords per module.
In practice
Error correction repairs the data area only. The finder patterns in the corners, the timing lines that join them and the format bits beside them have almost no protection. Keep logos, stickers and folds away from those.
Why a logo needs level H
A logo in the middle of a code is deliberate damage. Every module it covers is a module the scanner cannot read. At level M a logo covering 15% of the area would spend the whole budget on itself and leave nothing for a smudge or a bent corner. At level H the same logo spends half the budget and the other half is still there for real-world wear.
Three cases from practice:
- A café’s table code with a small round logo. Logo covers about 12% of the area. Level H, so a coffee ring on the edge is still survivable.
- A product label on cardboard that will be handled. No logo, but scuffs are certain. Level Q.
- A code on a conference slide. Nothing will touch it and it is a metre wide on screen. Level L, which keeps the modules large and easy for a camera at the back of the room.
The trade-off against size
Repair codewords take the place of data codewords. The same message at a higher level needs a bigger version, and a bigger version means smaller modules for the same print size.
The two figures above show it. A 43-character link fits version 3 at level L and needs version 5 at level H. Printed at 2.5 cm wide, the level L code has modules of about 0.68 mm and the level H code about 0.56 mm. Both scan easily at that size. Shrink the print to 1.5 cm and the level H code is the first to fail.
So the honest rule is: use the lowest level that covers the damage you expect. If nothing will cover the code, level M. If a logo will, level H, and then print larger to give the modules back.
Common mistake
Choosing level H for everything “to be safe”. On a small label with no logo it makes the modules smaller for no benefit, and the smaller modules are what fail first.
▸Errors, erasures and the block structure
The repair maths is Reed–Solomon coding over 8-bit symbols. With r repair codewords a block can correct r/2 codewords whose positions are unknown, or up to r codewords whose positions are known (called erasures). Scanners treat misread modules as unknown errors, so the practical limit is half the repair count. Larger versions split the data into several blocks, each with its own repair codewords, and interleave them so that a scratch across the code lands on many blocks a little rather than one block a lot. Version 5 at level M uses 2 blocks; version 40 at level H uses 81. The masking and Reed–Solomon article explains how the repair codewords are computed.
Try it yourself
Paint over a real code with your finger and watch the moment it stops decoding at each level. Then move the same damage onto a finder pattern and see it fail at once.