Chapter 1
Parts of a QR code
On this page
A QR code is a square grid of dark and light squares called modules. Most modules carry the encoded data, but some are the same in every QR code of a given size. These fixed parts let a scanner find the code, work out which way up it is and measure its grid, all before it reads a single bit of data.
QR codes come in 40 sizes, called versions. Version 1 is 21 modules across, and each version adds 4 modules to each side, up to 177 × 177 for version 40. In general, a version code is modules across.
The figure below shows the fixed parts of a QR code. It starts at version 7, the smallest version that has every kind of fixed part, and the examples in this chapter use version 7 too. Use the slider to see how the layout changes with the version. Point at a module to see which part it belongs to, or select a part in the list to pick it out. Rows and columns are numbered from 0, starting at the top left.
Point at a module to see which part it belongs to.
Modules in each part. Select a part to pick it out.
000111 110010010100The sections below go through the parts in the same order as the list.
Finder patternsLink to this section
The three large squares are the finder patterns. Each is 7 × 7 modules: a dark ring, a light ring and a dark 3 × 3 square in the middle. They sit right in the corners of the code, at the top left, top right and bottom left.
Any line through the centre of a finder pattern, at any angle, crosses dark, light, dark, light and dark modules in the proportions 1 : 1 : 3 : 1 : 1. That stays true however large the code is printed and however it is rotated, so a scanner can look for it to find QR codes in a camera image. Having three finder patterns also shows which way up the code is: the corner without one is the bottom right.
SeparatorsLink to this section
Each finder pattern has a strip of light modules, one module wide, along the two sides that face into the code. These separators keep the finder patterns apart from the rest of the code, so no dark module ever touches one. The outer sides don’t need separators, because the quiet zone (below) surrounds the code there.
Timing patternsLink to this section
Two lines of alternating dark and light modules run between the finder patterns: one along row 6, between the top two finder patterns, and one down column 6, between the two on the left. Both start and end with a dark module.
They let a scanner work out how densely the modules are packed and which version the code is, and they give it reference points for finding each row and column.
Alignment patternsLink to this section
The smaller squares are alignment patterns. Each is 5 × 5 modules: a dark ring, a light ring and a single dark module in the middle. They give a scanner reference points spread across the code. Rather than fitting one grid over the whole code, the scanner works out where the modules are one area at a time, between neighbouring finder and alignment patterns, so the grid can follow a code that is slightly distorted.
Version 1 has no alignment patterns, and larger versions have more of them. Their positions are listed in the QR code standard (ISO/IEC 18004): for each version it gives a short list of coordinates, and the same list is used for both rows and columns. An alignment pattern is centred at every combination of a row and a column from the list, except the three that would overlap a finder pattern.
For version 7 the list is 6, 22 and 38. That gives 3 × 3 = 9 combinations, and leaving out the three corners occupied by finder patterns leaves 6 alignment patterns. The first coordinate is always 6, the same row and column as the timing patterns, and the last is always the seventh row or column from the far edge. The standard spaces the rest as evenly as possible, and puts any unevenness in the gap between the first two.
| Versions | Coordinates in the list | Alignment patterns |
|---|---|---|
| 1 | none | 0 |
| 2–6 | 2 | 1 |
| 7–13 | 3 | 6 |
| 14–20 | 4 | 13 |
| 21–27 | 5 | 22 |
| 28–34 | 6 | 33 |
| 35–40 | 7 | 46 |
Move the slider in the figure to watch alignment patterns being added as the version grows.
Some alignment patterns sit on top of a timing pattern. They agree with it, module for module: every coordinate in the standard’s lists is even, and so the dark modules of an alignment pattern land on the timing pattern’s dark modules, which are also at even positions.
Dark moduleLink to this section
One module, in column 8 and row , is always dark. It sits beside the top-right corner of the bottom-left finder pattern. The standard describes it together with the format information, but it isn’t part of the format information or of any pattern: it simply has to be dark.
Quiet zoneLink to this section
Around the whole code there must be a light margin 4 modules wide, called the quiet zone, kept free of any other markings. It keeps the code apart from anything printed around it.
Format informationLink to this section
Two strips beside the finder patterns hold the format information: 15 bits, of which 5 record the error correction level and mask pattern the code uses, and 10 protect them against errors. A scanner needs these before it can read any data, so they are stored twice. One copy wraps around the top-left finder pattern, along row 8 and column 8, skipping the timing patterns. The other copy is split in two: 8 bits along row 8 beside the top-right finder pattern, and 7 bits down column 8 beside the bottom-left one.
Unlike the parts above, the format information depends on choices made when the code is created, so the figure leaves it blank. Chapter 2 explains what the bits mean and how they are protected against errors.
Version informationLink to this section
From version 7 up, the code also records its version number, in two blocks: one 6 modules tall and 3 wide, to the left of the top-right finder pattern, and the same block turned on its side, 3 tall and 6 wide, above the bottom-left finder pattern. Each block holds the same 18 bits: the version number in 6 bits, followed by 12 bits of error correction.
A scanner first estimates the version from the distance between the top two finder patterns, measured in modules. The standard’s reference decoder uses that estimate as the version if it is 6 or less; if it is 7 or more, it reads the version information instead. Move the slider below 7 and the version information disappears.
The version information depends only on the version, so the figure shows its real bits. For version 7 they are:
Chapter 2 shows how the 12 error correction bits are calculated.
Data areaLink to this section
Everything else, shown in grey, is the data area. It holds the encoded data and its error correction, as a sequence of bytes, each taking 8 modules. In version 1 the data area has 208 modules, exactly 26 bytes. In many versions a few modules are left over after the last whole byte; these are called remainder bits. Version 2, for example, has 359 modules: 44 bytes, with 7 modules to spare.
Chapters 3 to 6 cover how data is turned into bytes, how the error correction bytes are calculated, and how all of them are laid out in the data area.