How Do QR Codes Work? Modules, Patterns and Error Levels
How do QR codes work? Each square is a bit, three corner patterns orient the scanner, and error correction repairs damage. With capacity tables and steps.
Updated
A QR code stores data as a grid of dark and light squares called modules, where each module is one bit. Three large corner patterns tell the scanner where the code is and how it is rotated, and built-in error correction lets the data be recovered even if part of the code is damaged. To make one, type your text into the QR Code Generator and download the image.
The parts of a QR code
QR stands for Quick Response. The format was created in 1994 by the Japanese company Denso Wave to track car parts, and it is now an ISO standard. Every code is built from the same pieces:
- Modules: the small squares. Dark is 1, light is 0.
- Finder patterns: the three large squares in the top left, top right and bottom left corners. Each is 7 by 7 modules: a dark ring, a light ring and a dark 3 by 3 center.
- Alignment patterns: smaller squares inside larger codes that help the scanner correct for curved or tilted surfaces. The smallest code has none.
- Timing patterns: a row and a column of alternating dark and light modules running between the finder patterns. They let the scanner measure the module size.
- Format information: a short, heavily protected strip next to the finder patterns that records the error correction level and the mask used.
- Quiet zone: the empty margin around the code. The standard asks for 4 modules of clear space on every side.
- Data area: everything else. It holds your data and the error correction bytes.
Versions and size
QR codes come in 40 sizes, called versions. Version 1 is 21 by 21 modules, and each version adds 4 modules per side, so the side length is 17 plus 4 times the version number. Version 40 is 177 by 177.
A generator picks the smallest version that fits your data. More data means more modules, which means smaller squares at the same printed size and a code that is harder to scan from a distance.
How text becomes squares
- The generator picks an encoding mode. Numeric mode packs digits most tightly. Alphanumeric mode covers digits, uppercase letters and a few symbols. Byte mode handles everything else, including lowercase letters and UTF-8 text. Kanji mode covers Japanese characters.
- The data is turned into a bit stream and split into 8-bit codewords.
- Reed-Solomon error correction codewords are calculated and appended.
- The codewords are placed into the data area in a zigzag path, starting from the bottom right corner.
- One of eight mask patterns is applied, flipping some modules to avoid large blank areas and shapes that look like finder patterns. The generator tries all eight and keeps the one that scores best.
- Format and version information is written around the finder patterns.
Error correction levels
Reed-Solomon coding adds redundant data so that a scanner can rebuild missing or wrong codewords. There are four levels:
| Level | Recovers about | Use it for |
|---|---|---|
| L | 7 percent | Clean screens, maximum capacity, smallest code |
| M | 15 percent | General use |
| Q | 25 percent | Printed codes that may get worn |
| H | 30 percent | Harsh conditions, or a logo placed over the code |
Higher levels cost space. The same text needs more modules at H than at L. For example, https://gameparticles.com fits in a version 2 code (25 by 25) at level L but needs version 4 (33 by 33) at level H.
A logo in the middle of a QR code works only because of error correction. The logo destroys the modules beneath it, and the scanner rebuilds them. That is why codes with logos should use level H and keep the logo small.
How much a QR code can hold
Capacity in bytes, which is what ordinary text and URLs use:
| Version | Modules per side | Level L | Level M | Level Q | Level H |
|---|---|---|---|---|---|
| 1 | 21 | 17 | 14 | 11 | 7 |
| 2 | 25 | 32 | 26 | 20 | 14 |
| 5 | 37 | 106 | 84 | 60 | 44 |
| 10 | 57 | 271 | 213 | 151 | 119 |
| 20 | 97 | 858 | 666 | 482 | 382 |
| 40 | 177 | 2,953 | 2,331 | 1,663 | 1,273 |
The headline maximums for version 40 at level L are 7,089 digits, 4,296 alphanumeric characters or 2,953 bytes. In practice, keep content short. A URL under about 100 characters stays in the small versions that phones read instantly.
What the scanner does
A scanner runs the process in reverse. It finds the three finder patterns, straightens the perspective, reads the format information, samples each module, removes the mask and uses Reed-Solomon to fix errors. Then it decides what to do with the decoded text. A string starting with https:// opens in the browser. Prefixes such as WIFI:, mailto: and tel: trigger other actions.
That last step matters: a QR code itself is only text. There is no tracking and no expiry built into the pattern. See do QR codes expire for what that means in practice, and WiFi QR codes for an example of a special text format.
How to make a QR code
- Open the QR Code Generator and type or paste your content into the URL or Text box. The preview updates as you type, and a character count sits below the box.
- Choose the error correction level: L, M, Q or H. The generator starts on H. Switch to M for a simpler-looking code if you are not adding a logo.
- Pick a color preset or set your own Foreground and Background colors. Classic is black on white.
- Optionally change the Dot Style and Corner Style, or add a Center Logo and set its width and height. Adding a logo switches error correction to H.
- Click PNG or SVG to download, or Copy Image to put it on the clipboard.
Tips for codes that scan every time
- Keep strong contrast, with a dark foreground on a light background. Some scanners struggle with inverted codes, where the modules are lighter than the background, so test the dark presets before using them in print.
- Leave clear space around the code. The download has a narrow margin, so do not place text or borders tight against it.
- Use SVG for print. It is a vector file and stays sharp at any size. The PNG is 520 by 520 pixels, which suits screens and small prints.
Try it
Paste a link into the QR Code Generator, switch between error correction levels to watch the pattern grow and shrink, then download the code as SVG for print or PNG for the web.