# 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.

Source: https://useqr.app/glossary/mask-pattern · Last reviewed 2026-08-21 · UseQR is free forever, MIT licensed, no signup.

---

## 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.
