Glossary
Penalty score
The penalty score is how a QR encoder chooses among the eight mask patterns. Each candidate symbol is scored by four rules (long same-colour runs, 2 × 2 blocks, false finder patterns and dark/light imbalance) weighted 3, 3, 40 and 10, and the mask with the lowest total is used.
The four rules
After data placement, the encoder applies each mask pattern in turn and scores the result:
| Rule | Looks for | Penalty |
|---|---|---|
| N1 | Runs of 5+ same-colour modules in a row or column | 3 + (length − 5) |
| N2 | Every 2 × 2 block of one colour | 3 each |
| N3 | The 1:1:3:1:1 dark/light ratio of a finder, with 4 light modules beside it | 40 each |
| N4 | Deviation of overall darkness from 50% | 10 per 5% step |
Lowest total wins. N3's weight of 40 exists because a fake finder pattern in the data region is the most expensive defect possible: a scanner could lock onto the false corner and fail to find the symbol at all. The chosen mask number is then recorded in the format information.
Why identical data can yield different codes
The rules sound exact but are implemented unevenly: several major encoders score N3 without checking the four light modules the standard requires next to the 1:1:3:1:1 run, and a one-point difference flips which mask wins. Both results decode identically, the score only tunes scannability. This is a principal reason two generators produce visually different codes from the same input, and why "my code looks different" is not a bug report. The full scoring walkthrough lives at mask selection penalty scores; the exact per-mask formulas are in the mask pattern reference.
FAQ
What is a good penalty score for a QR code?
There is no target number. The score only ranks the eight mask candidates for one symbol against each other; the encoder simply keeps the lowest and discards the value.
Does the penalty score affect whether my QR code scans?
Marginally. Masking prevents pathological patterns (big single-colour areas and false finders), but any of the eight masks produces a valid, decodable symbol. Contrast, size and quiet zone matter far more.
Try it: free, no signup
Related
- 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…
- 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…
- 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…
- 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…