QR code glossary · Encoding and capacity
Mask pattern
Also called: Data mask, Masking
Definition
A mask pattern is one of eight fixed patterns that a QR encoder combines with the data area, flipping selected modules, so the finished code avoids large solid blocks, long runs and shapes that look like finder patterns, all of which make a code harder to scan.
How it works
Raw data can come out lopsided: big white patches, long black lines, or by chance the 1:1:3:1:1 sequence of a finder pattern. Masking fixes that by inverting every data module where a simple formula of its row and column is true. Function patterns are never masked.
000
(i + j) mod 2 = 0
001
i mod 2 = 0
010
j mod 3 = 0
011
(i + j) mod 3 = 0
100
(⌊i/2⌋ + ⌊j/3⌋) mod 2 = 0
101
(ij) mod 2 + (ij) mod 3 = 0
110
((ij) mod 2 + (ij) mod 3) mod 2 = 0
111
((i + j) mod 2 + (ij) mod 3) mod 2 = 0
The encoder tries all eight and scores each result with four penalty rules from the standard: runs of five or more same-colored modules in a row or column (3 points, plus 1 for each extra module), each 2 × 2 block of one color (3 points), each finder-like 1:1:3:1:1 sequence with four light modules beside it (40 points), and how far the share of dark modules strays from 50% (10 points per 5%). The lowest score wins. Its 3-bit reference goes into the format information, and the scanner applies the same mask again to undo it. Micro QR codes use four of the masks.
Why it matters
Masking is automatic; there is nothing to set. It explains two things people notice. First, the same content can look different from two generators, because they may pick different masks or encode the content slightly differently. Both codes are valid. Second, changing one character changes the whole pattern, because a new mask may win.
It is also a reason not to edit modules by hand. Recoloring or removing individual modules spends error correction budget and can recreate the blocks and finder-like shapes the mask was chosen to avoid. Change the design through the generator and test the result.
Example
For the short link https://example.com/r/A7K2Q9, the open-source qrcode encoder picks mask 011 at levels L and M, mask 001 at level Q and mask 010 at level H: each time, the one with the lowest penalty score for that version and level.
Related terms
- Format informationFormat information is a 15-bit field printed twice in every QR code, beside the finder patterns, that tells the scanner which error correction level and which mask pattern the code uses, so it can be read before any of the data.
- Finder patternA finder pattern is one of the three large concentric squares in the top-left, top-right and bottom-left corners of a QR code, which a scanner uses to detect the code, measure its size and angle, and work out which way up it is.
- ModuleA module is a single square cell of a QR code, either dark or light, and the basic unit of the symbol: each one is a bit of data or part of a fixed pattern, and the printed width of one module decides how far away the code can be read.
- Encoding modesEncoding modes are the ways a QR code packs characters into bits: numeric mode for digits, alphanumeric mode for a 45-character set of capital letters, digits and a few symbols, byte mode for any data such as UTF-8 text, and kanji mode for Japanese Shift JIS characters.
- Micro QR codeA Micro QR code is a smaller variant of the QR code, defined in the same standard (ISO/IEC 18004), that uses a single finder pattern and a 2-module quiet zone to fit up to 35 digits in a symbol of 11 × 11 to 17 × 17 modules.
Learn more
- AI QR code art: Why reshaping the pattern needs a real decoder check.
Sources
Last updated . Written by the CirculateQR team; technical facts follow the sources listed above. Example codes and sizes are computed with the open-source qrcode encoder that CirculateQR uses. Spotted something wrong? Email support@circulateqr.com. QR Code is a registered trademark of DENSO WAVE INCORPORATED.
← Browse the full glossary