PNG vs JPG vs WebP: When to Use Each Image Format
Lossy vs lossless compression, when transparency matters, and why WebP is replacing both PNG and JPG on the web.
A QR code packs up to 4,296 characters into a tiny grid of black and white squares. But how does a camera decode those squares back into a URL or a Wi-Fi password? The answer involves clever binary encoding, built-in error correction, and a layout designed so scanners can read codes at any angle — even when partially damaged.
Every QR code contains several structural elements that help scanners locate and orient the code before reading any data:
QR code structure (simplified):
┌─────────┐ ┌─────────┐
│ ███████ │ ─── │ ███████ │ ← Finder patterns
│ █ █ │ │ █ █ │
│ █ ███ █ │ │ █ ███ █ │
│ █ █ │ │ █ █ │
│ ███████ │ │ ███████ │
├─────────┤ └────┬────┘
│ Timing │──────────│ ← Timing pattern
├─────────┤ │
│ │ Data │
│ ███████ │ modules │ ← Data fills remaining space
│ █ █ │ │
│ █ ███ █ │ ┌──┐ │
│ █ █ │ │██│ │ ← Alignment pattern
│ ███████ │ └──┘ │
└─────────┴──────────┘QR codes support four encoding modes, each optimized for different content types:
| Mode | Characters | Bits per char | Max capacity |
|---|---|---|---|
| Numeric | 0-9 | 3.3 | 7,089 digits |
| Alphanumeric | 0-9, A-Z, space, $%*+-./: | 5.5 | 4,296 chars |
| Byte | Any (UTF-8) | 8 | 2,953 bytes |
| Kanji | Japanese characters | 13 | 1,817 chars |
The QR encoder automatically selects the most efficient mode for the input data. A URL like https://example.com gets encoded in byte mode (8 bits per character), while a phone number uses numeric mode (just 3.3 bits per digit). This is why QR codes for short numbers are noticeably smaller than codes for long URLs.
One of QR's most impressive features is Reed-Solomon error correction. The encoded data includes redundant codewords that let the scanner reconstruct missing or damaged portions — even if part of the QR code is torn, stained, or obscured.
| Level | Recovery | Overhead | Best For |
|---|---|---|---|
| L | ~7% | Low | Clean digital displays |
| M | ~15% | Medium | General purpose (default) |
| Q | ~25% | High | Printed materials |
| H | ~30% | Highest | Harsh environments, logos |
QR codes use a square grid because the finder patterns need to be detectable from any rotation. The three corner squares create a unique geometric relationship that cameras can identify instantly — they determine position, size, and angle in a single scan pass. A rectangular code would need different detection logic for landscape vs. portrait orientation.
The “version” of a QR code determines its size. Version 1 is 21×21 modules, and each version adds 4 modules per side, up to Version 40 at 177×177 modules. Higher versions hold more data but require higher-resolution printing and scanning.
QR codes survived a decade of “that'll never catch on” skepticism because the engineering is genuinely brilliant: self-orienting, self-correcting, and backwards compatible from Version 1 to Version 40.
Lossy vs lossless compression, when transparency matters, and why WebP is replacing both PNG and JPG on the web.
What happens when you drag the quality slider, how DCT transforms photos, and why screenshots compress differently.
Grid vs freeform composition, how canvas APIs stitch images together, and DPI considerations when combining images.