A QR code is a picture of text
The text might be a web address, a Wi-Fi password or a payment request. Inside the code it's characters turned into ones and zeros, drawn as a square grid of dark and light squares called modules. A dark module is a 1, a light module is a 0.
A lot of the grid isn't your text. Fixed patterns let a camera find the code from any angle, a few bits describe how the code was built, and spare error-correction bits let a phone repair damage. The playground above draws all of it live, with the same encoder our free QR code generator uses.
That's also the difference from an ordinary barcode, which stores a short number in one direction as the widths of vertical bars. A QR code stores data across and down, holds up to a few thousand characters, and carries the spare bits to repair damage.
Making a code takes five steps, and reading one runs them backwards.
The parts of a QR code
Every QR code, from the smallest 21×21 grid to the largest 177×177, is built from the same parts:
- Finder patterns. The three big squares in the corners. Each one is a dark 7×7 square ring, a light ring, then a dark 3×3 centre. Read straight across, the stripes are always in the ratio 1:1:3:1:1, from any direction, which is what a camera looks for.
- Separators. A one-module light border around each finder, so the finders never touch the data.
- Timing patterns. Two dotted lines, one across and one down, joining the finders. They work like the marks on a ruler: a scanner counts them to know where each row and column is.
- Alignment patterns. Smaller 5×5 squares that appear from version 2 up. They give the scanner extra known points to correct for tilt and curves.
- Format information. 15 bits, stored twice, saying which error-correction level and which mask the code uses.
- Version information. On version 7 and larger, two blocks of 18 bits spell out the version number.
- The dark module. A single module beside the bottom-left finder that is dark in every QR code.
- Data and error correction. Everything else: your message and the repair bits calculated from it.
Point at any square in the code above to see which part it belongs to.
Step 1: your text becomes bits
First the encoder picks a mode, a way of packing characters into bits. The standard has four, and the encoder can switch between them inside one code to save space:
| Mode | What it can hold | How it packs them |
|---|---|---|
| Numeric | the digits 0–9 | 3 digits in 10 bits |
| Alphanumeric | 0–9, A–Z (capitals only), space and $ % * + - . / : | 2 characters in 11 bits |
| Byte | anything: lower case, emoji, any language | 8 bits per byte |
| Kanji | Japanese kanji and kana | 13 bits per character |
Each chunk of data starts with a 4-bit mode indicator (0001 for numeric, 0010 alphanumeric, 0100 byte, 1000 kanji) and a character count, so the scanner knows how much to read. Then come the characters themselves. After the last one, the encoder adds an end marker of up to four zeros, pads to a whole byte, and fills any space that's left with two padding bytes, 11101100 and 00010001, taking turns.
The mode decides how many bits your text costs (more in our guide to encoding modes). At error-correction level M, the 11 characters HELLO WORLD need 74 bits in alphanumeric mode, while hello world in lower case needs 100 bits, because lower-case letters force byte mode. Our link https://qrcodesforever.com takes 220 bits; the same address in capitals takes 156. Most generators, ours included, write text that isn't plain digits or capitals as UTF-8 bytes, which is what phone scanners expect today.
Try it · encoding
Byte mode · anything else, 8 bits per byte (UTF-8) · 26 bytes · 220 bits
“https://qrcodesforever.com”
Total: 220 of 224 data bits at version 2-M. The rest is filled with a short end marker and the padding bytes 11101100 and 00010001, repeated.
Step 2: error correction is added
Next, the encoder splits your data into 8-bit codewords and calculates extra Reed–Solomon codewords from them. Reed–Solomon is the same family of error-correcting codes used on CDs, DVDs and in deep-space radio. If some codewords are later misread, the scanner can use the extras to work out what they should have been.
You choose how many extras to add with the error-correction level:
| Level | Name | Roughly how much can be restored |
|---|---|---|
| L | Low | about 7% of the codewords |
| M | Medium | about 15% |
| Q | Quartile | about 25% |
| H | High | about 30% |
More repair bytes means less room for data, so the same message needs a bigger grid at a higher level. That's the trade-off you can see above. On a larger code, the codewords are split into several blocks, each with its own repair bytes, and the blocks are interleaved. That way a single scratch spreads its damage across many blocks instead of wiping out one.
Level M is a good default for most printed codes. If you're putting a logo in the middle, use H, which our generator does for you. There's more on choosing a level in our error-correction guide.
Try it · error correction
Step 3: the bits are laid out in a zigzag
Now the fixed patterns go down first: finders, separators, timing lines, alignment patterns, and space reserved for the format and version information. Every module left over is filled with the codewords, one bit at a time.
The path is always the same. It starts in the bottom-right corner and moves up a column two modules wide, zigzagging right-left, right-left. At the top it shifts two columns to the left and comes back down. Whenever it meets a fixed pattern it skips over it, and it jumps past the vertical timing line entirely. Data codewords go first, then the error-correction codewords. A few versions have up to 7 modules spare at the end; these remainder bits carry nothing.
Press play to watch the encoder's real order. Each shaded band is one codeword.
Try it · placement
Remainder bits
359 / 359 bits
Step 4: a mask breaks up bad patterns
Raw data can produce unlucky shapes: big blank areas, long stripes, or a cluster that looks like a finder pattern. Any of those can confuse a scanner. So the encoder masks the data by flipping some modules according to a simple formula. There are eight masks, numbered 0 to 7, each a different checkerboard-like pattern, for example "flip every module where row + column is even".
The encoder tries all eight and gives each result a penalty score using four rules from the standard:
- Runs of five or more same-coloured modules in a row or column.
- Every 2×2 block of a single colour.
- Anything that looks like the 1:1:3:1:1 stripes of a finder pattern.
- How far the code is from being half dark and half light.
The mask with the lowest score wins. Only the data and error-correction area is masked, never the fixed patterns. A scanner reads the mask number from the format information and flips the same modules back. You can pick a different mask below and see how its score compares, or read more about masking.
Try it · masking
Before
Mask 1
After
flip where i mod 2 = 0 (i = row, j = column)
- Runs of 5+ same-colour modules in a row
- 253
- 2×2 blocks of one colour
- 225
- Stripes that look like a finder pattern
- 0
- Too far from half dark, half light
- 0
Step 5: format and version information
Last, the encoder writes the format information: 2 bits for the error-correction level and 3 bits for the mask number, followed by 10 check bits so a misread can be caught and fixed. The 15 bits are combined with a fixed pattern (101010000010010) so they can never come out all light, and written twice, once around the top-left finder and once split between the other two.
Codes of version 7 and up also get 18 bits of version information, written twice near the top-right and bottom-left finders. On a small code a scanner can count the timing dots to find the size, but on a big one it's safer to spell it out.
Try it · format information
| Read from the code | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| XOR fixed pattern | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| Result | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 |
00 = level M (medium) · 001 = mask 1
How your phone reads a QR code
Reading is the same five steps, run backwards:
- Find the code. The camera image is turned into black and white, and the scanner looks along rows and columns for the 1:1:3:1:1 stripes of the finder patterns. Three of them mark three corners and show which way up the code is.
- Straighten it. From the finders, and the alignment pattern on bigger codes, the scanner works out how the code is tilted and warped, and maps a straight grid onto it.
- Read the setup. It reads the format information to learn the error-correction level and the mask, and on large codes the version.
- Read the bits. It samples the centre of every module, undoes the mask, and collects the bits in the same zigzag order, then sorts the codewords back into their blocks.
- Repair and decode. Reed–Solomon fixes any wrong codewords it can, and the modes and character counts turn the bits back into your text.
All of this happens on the phone. Scanning doesn't need the internet; only opening a link does. If you want to try it without a phone, our QR code scanner reads codes from your camera or a screenshot, right in the browser.
Why a damaged QR code still scans
Because of Reed–Solomon, a scanner doesn't need every module to be right. A block can repair up to half as many wrong codewords as it has repair codewords. A logo in the middle, a coffee stain, or a scratch across the corner of a sticker are all just wrong codewords to the decoder.
Two things it can't fix: a finder pattern that's been covered (the scanner can't find the code at all), and damage that's concentrated in more blocks than the repair bytes can cover. That's why logos go in the middle, and why it's worth testing a printed code before you print a thousand. Our contrast checker catches the other common failure: colours too close together for a camera to tell apart.
Slide the damage up and watch where it stops scanning. The test uses a real decoder on the exact picture shown.
Try it · damage
Share of the code's area under the logo.
Scanning…
- Wrong codewords
- 7 of 44
- Worst block
- 7 wrong, fixes 8
How much a QR code can hold
QR codes come in 40 sizes called versions. Version 1 is 21×21 modules, and each version adds 4 modules to each side, up to version 40 at 177×177. The encoder always picks the smallest version that fits your data at the level you chose. These limits come straight from our encoder (there's a full breakdown in QR code versions and capacity):
| Version | Grid | Digits (L) | Bytes (L) | Bytes (M) | Bytes (Q) | Bytes (H) |
|---|---|---|---|---|---|---|
| 1 | 21×21 | 41 | 17 | 14 | 11 | 7 |
| 2 | 25×25 | 77 | 32 | 26 | 20 | 14 |
| 5 | 37×37 | 255 | 106 | 84 | 60 | 44 |
| 10 | 57×57 | 652 | 271 | 213 | 151 | 119 |
| 25 | 117×117 | 3,057 | 1,273 | 997 | 715 | 535 |
| 40 | 177×177 | 7,089 | 2,953 | 2,331 | 1,663 | 1,273 |
So the most any QR code can hold is 7,089 digits, 4,296 alphanumeric characters, or 2,953 bytes. In practice, less is better. A shorter message means a smaller grid, and a smaller grid means bigger modules that scan from further away and survive cheap printing. Leave a blank margin around the code too, called the quiet zone; the standard asks for 4 modules. Our size calculator works out how big to print for the distance people will scan from.
Do QR codes expire?
A QR code itself can't expire. As you've seen, the message is drawn into the pattern, and any phone can read it with no server involved. A code for a Wi-Fi password or a plain web address will work for as long as the print lasts.
What does expire is a dynamic QR code. It holds a short link to the QR company's server instead of your link, and the server redirects each scan to your page. If the subscription lapses or the company shuts down, the redirect stops and the code goes dead while the printed pattern is still perfect. Codes made on this site are static, so what you type is exactly what the code holds. More on which QR codes expire and static vs dynamic codes.
Where QR codes came from
QR stands for Quick Response. Denso Wave, then a division of the Japanese car-parts maker Denso, announced the code in 1994. Masahiro Hara led the development with one other team member, and the goal was to track parts on factory lines faster than ordinary barcodes allowed. To make the position markers easy to find, they surveyed printed material for the black-and-white ratio least likely to turn up by chance. It was 1:1:3:1:1, the finder pattern in three corners of every code (Denso Wave's own history).
Denso Wave kept the patent but declared it would not exercise it, and the code became an international standard, ISO/IEC 18004, in 2000. That's why any app, phone camera or website can make and read QR codes without paying anyone. The history of the QR code has the longer story.
QR Code is a registered trademark of DENSO WAVE INCORPORATED. Every code and number on this page is generated live, in your browser, by the same encoder our generator uses, following ISO/IEC 18004.