Skip to content
UseQR
ESC

Jump to

↑↓MOVE↵OPEN50 places

Glossary

Mask pattern

A mask pattern is one of eight XOR patterns applied to a QR code's data area to avoid large blocks of one colour and false finder-like shapes. The encoder tries all eight, scores them, and keeps the best.

View as MarkdownPaste this page into any AI assistant. It is plain, portable Markdown.

Why masking exists

Raw encoded data can, by chance, produce a big white region, a big black region, or a 1:1:3:1:1 run that looks like a finder pattern. Any of those confuse a decoder. Masking XORs the data area with a regular pattern to break up such structures.

The eight patterns

Each is a formula over the module's row i and column j:

Mask Condition
0 (i + j) mod 2 = 0
1 i mod 2 = 0
2 j mod 3 = 0
3 (i + j) mod 3 = 0
4 (⌊i/2⌋ + ⌊j/3⌋) mod 2 = 0
5 (i·j) mod 2 + (i·j) mod 3 = 0
6 ((i·j) mod 2 + (i·j) mod 3) mod 2 = 0
7 ((i+j) mod 2 + (i·j) mod 3) mod 2 = 0

Penalty scoring

Each masked candidate is scored on four rules: runs of five or more same-coloured modules, 2 × 2 same-coloured blocks, finder-like 1:1:3:1:1 runs, and overall dark/light imbalance. Lowest total wins. The chosen mask number is recorded in the format information so the decoder can undo it.

This is why two generators can produce visibly different-looking codes for identical data, if their penalty implementations differ slightly, they pick different masks. Both are valid.

  • Format information, Format information is the 15-bit block next to the finder patterns that records the error-correction level and mask pattern. It is stored twice and…
  • Finder pattern, The three large concentric squares in the corners of a QR code are finder patterns. A scanner locates them first to work out where the code is, how big it…
  • Module, A module is one square cell of a QR code: the smallest unit of the pattern. Codes are measured in modules, not pixels or millimetres, because the module…