CIRCULATEQR

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 eight masks over a 12 × 12 corner of the grid. Dark cells are modules the mask flips; i is the row and j the column, counted from 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.

Learn more

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