What's inside a QR code
A note on the machinery behind the speckled square. ← Workbench
Scan almost any speckled square today and it opens in a split second, at an angle, in bad light, sometimes half crumpled. That reliability is not luck — a QR code is a carefully engineered layout with redundant parts, and every block you see has a job.
The landmarks first
The three big squares in the corners are finder patterns. They tell the camera where the code is, how big it is, and which way it is rotated — which is why scanning works at any angle. A smaller alignment pattern (in larger codes) compensates for lens distortion, and the dashed timing pattern running between the finders lets the scanner work out the grid size. Around everything sits an empty margin, the quiet zone; cram a code flush against other graphics and scanners can lose it.
Your text is compressed before it is drawn
The data is not stored as raw characters. The encoder picks the
densest mode that fits: numeric packs three digits into
10 bits, alphanumeric squeezes two letters or digits into
11 bits, and ordinary text rides in byte mode at 8 bits
per character. A pure number like 20260830 therefore makes a
visibly finer code than the same characters as prose — fewer modules for
the same content.
Then comes the clever part: error correction
Before anything is drawn, the data gets backup copies woven in — Reed–Solomon codes, the same math that protected CD audio. You choose how much: levels L, M, Q, H can each repair roughly 7%, 15%, 25% or 30% of the code. This is why a QR code with a logo stamped over its middle still scans, why a scratched label at the bakery works, and why codes on freight survive rain and abrasion. The trade-off is density: higher repair capacity means a larger grid for the same text.
Why the speckles look random
A naive layout with clumpy black areas reads poorly. So the encoder tries eight different mask patterns — checkerboards, stripes, L-shaped flicks — XORs each one over the data region, and scores every result with penalty rules: long runs of one color, big blocks, accidental look-alikes of the finder squares, and an unbalanced dark/light ratio. The lowest-penalty result wins. That final scrambling is what gives QR codes their confetti look, and it is chosen, not random.
Size and capacity
QR codes come in 40 versions, from 21×21 to 177×177 modules. A small version-1 code at level L holds 17 characters; the largest configuration tops out around 7,000 digits. In practice, short content and a modest error-correction level produce chunky, easy-to-scan codes — which is exactly what you want on a business card or a flyer.
Next time a scan works despite a torn corner or a sticker half over the code, you know what to thank: the finders got the orientation right, and Reed–Solomon silently rebuilt what the camera couldn't see.
Want to see the anatomy live? The QR code generator here lets you toggle the error-correction level and watch the same text produce different densities — everything computed in your browser, nothing uploaded.