What is JPEG / JPG? DCT Math, Lossy Artifacts, and Chroma Subsampling
Explore the mathematics behind JPEG compression: RGB to YCbCr conversion, 4:2:0 chroma subsampling, Discrete Cosine Transform (DCT), and quantization.
Zero-Upload Client Architecture Research
Joint Photographic Experts Group (JPEG/JPG) is a standardized lossy raster image compression format created in 1992 (ISO/IEC 10918-1). JPEG compresses photographic images by converting RGB data into luminance and chrominance (YCbCr), subsampling human-insensitive color details (typically 4:2:0), and applying the Discrete Cosine Transform (DCT) to discard imperceptible high-frequency visual frequencies, shrinking file size by 80–90%.
1. What JPEG Stands For and Why It Dominated Photography
Before JPEG was published in 1992, saving a 24-bit photographic scan required megabytes of storage on floppy disks holding only 1.44 megabytes. The Joint Photographic Experts Group devised an algorithm based on human psycho-visual perception: our retinas possess vastly more rod cells (sensitive to luminance/brightness) than cone cells (sensitive to color chroma).
By aggressively stripping color information that the human brain cannot resolve while preserving edge luminance, JPEG allowed high-resolution photographs to be shared over dial-up internet connections.
2. The 4 Stages of JPEG Compression
Stage A: Color Space Conversion (RGB to YCbCr)
Standard computer displays represent colors as Red, Green, and Blue. JPEG decoders immediately transform RGB coordinates into YCbCr space:
- Y (Luminance): The brightness signal (black-and-white grayscale).
- Cb (Chroma Blue): The difference between blue and luminance.
- Cr (Chroma Red): The difference between red and luminance.
Stage B: Chroma Subsampling (4:4:4 vs. 4:2:0)
Because human vision is relatively blind to high-frequency color variations, encoders discard 50% to 75% of the Cb and Cr samples. In 4:2:0 subsampling, color is sampled only once for every 2×2 grid of 4 luminance pixels, cutting the raw color payload in half before mathematical compression even begins.
Stage C: Discrete Cosine Transform (DCT) & Quantization
The image is sliced into 8×8 pixel blocks. Each 64-pixel block undergoes the Discrete Cosine Transform (DCT), converting spatial pixel values into 64 frequency amplitudes:
- The top-left coefficient represents the block's baseline average brightness (DC coefficient).
- The remaining 63 values represent progressively higher frequency texture and sharp edge details (AC coefficients).
Next comes Quantization—the lossy step. High-frequency coefficients are divided by numbers from a quantization table and rounded to the nearest integer. Most high-frequency numbers become zeroes, discarding imperceptible noise.
Stage D: Entropy Huffman Encoding
The remaining non-zero numbers are ordered via a diagonal "zig-zag" scan, generating long runs of trailing zeroes that are packed compactly using run-length encoding (RLE) and variable-length Huffman binary trees.
3. Why Compression Artifacts Occur (Ringing and 8×8 Blockiness)
When you lower JPEG quality below 75%, quantization tables divide high frequencies by very large numbers. This leads to two signature artifacts:
- 8×8 Blockiness: When adjacent 8×8 blocks lose subtle edge gradients, their boundary seams become visible as a grid pattern.
- Ringing / Mosquitos: Near high-contrast boundaries (such as black text on a white background), truncated cosine frequencies create ripples and smudged noise around the letters. This is why text should never be saved in JPG format.
4. Why JPEG Cannot Support Transparency
The JPEG specification defines strictly 3 color channels (YCbCr). There is no fourth alpha transparency channel defined in ISO/IEC 10918-1. If you attempt to save an image with a transparent background as a JPEG, the encoder must composite the pixels against a solid matte color (usually black or white).
Convert and Compress JPEG Assets with Squeeze
- Convert JPG to PNG when you need lossless editing or transparent overlays.
- Convert JPG to WebP to save an additional 30% file size for modern web pages.
- Compress JPG files with real-time perceptual SSIM quality protection.
Authoritative References
Ready to convert or compress images with 100% privacy?
Experience zero server uploads. All WebP, PNG, JPG, SVG, and multi-resolution ICO conversions run entirely inside your browser using sandboxed Web Workers.