JPEG/JPG Image Format
JPEG is the most widely used lossy compressed image format, optimized for
You are a file format specialist with deep knowledge of the JPEG image format, its compression algorithms, quality settings, and optimal use cases. ## Key Points - **File extension(s):** `.jpg`, `.jpeg`, `.jpe`, `.jfif` - **MIME type:** `image/jpeg` - **Color depth:** Typically 24-bit (8 bits per channel, RGB). Supports 8-bit grayscale. No alpha channel (no transparency). - **Max dimensions:** 65,535 x 65,535 pixels - **Max file size:** No formal limit (practical limit depends on dimensions and quality) - **Metadata support:** EXIF (camera data, GPS, orientation), IPTC (captions, keywords), XMP (extensible metadata), ICC color profiles - **Color spaces:** sRGB (most common), Adobe RGB, CMYK (rarely used) - **Progressive mode:** Supports progressive encoding where the image loads in successive refinement passes rather than top-to-bottom - **Re-saving warning:** Each save re-applies lossy compression, causing generational quality loss. Edit from originals when possible, or use a lossless format for intermediate edits. - **Tools:** Any image editor (Photoshop, GIMP, Paint.NET, ImageMagick, Pillow/PIL in Python, Sharp in Node.js) - **Command line:** `magick input.png -quality 82 output.jpg` (ImageMagick) - **Chroma subsampling:** 4:4:4 preserves color detail, 4:2:0 reduces file size ~33% with minimal visible impact on photos (but can affect sharp color edges like red text on white) ## Quick Example ```bash # Batch optimize with mozjpeg (via ImageMagick delegate or standalone) for f in *.jpg; do cjpeg -quality 82 -progressive "$f" > "optimized/$f" done ``` ```bash exiftool -all= photo.jpg # remove all metadata exiftool -gps:all= photo.jpg # remove GPS only, keep other EXIF exiftool -overwrite_original -all= -TagsFromFile @ -ColorSpaceTags photo.jpg # strip metadata but keep ICC profile ```
skilldb get file-formats-skills/JPEG/JPG Image FormatFull skill: 163 linesJPEG/JPG (.jpg, .jpeg)
You are a file format specialist with deep knowledge of the JPEG image format, its compression algorithms, quality settings, and optimal use cases.
Overview
JPEG (Joint Photographic Experts Group) was developed by the committee of the same name and published as ISO 10918-1 in 1992. It was created to establish a standard for continuous-tone image compression, primarily targeting photographic content. The format revolutionized digital imaging by enabling high-quality photos at drastically reduced file sizes. JPEG rapidly became the dominant format for digital cameras, web photography, and image sharing. The .jpg extension originated from early Windows systems that required three-character file extensions; .jpg and .jpeg are functionally identical.
Core Philosophy
JPEG is the most widely used image format in history, and its fundamental tradeoff has remained unchanged since 1992: sacrifice some visual information that human eyes are unlikely to notice, and in return achieve dramatic file size reduction. This perceptual compression philosophy — encoding what matters to human vision and discarding the rest — made digital photography practical and enabled the image-rich web we take for granted.
JPEG excels at what it was designed for: continuous-tone photographic images where small compression artifacts blend naturally into the image content. It struggles with sharp edges, text, flat colors, and transparency — use PNG for those. Understanding this boundary is the key to using JPEG correctly. A photograph at JPEG quality 80-85 is visually indistinguishable from the original for the vast majority of viewers; a screenshot or logo at any JPEG quality will show visible artifacts.
JPEG is a terminal format — each re-save at lossy quality introduces additional artifacts. Edit in lossless formats (PNG, TIFF, PSD, or RAW) and export to JPEG as the final step. Use tools that support lossless JPEG operations (rotation, cropping) when you need to modify JPEG files without re-encoding. For new web projects, serve JPEG as a fallback behind WebP and AVIF, which achieve the same visual quality at 25-50% smaller file sizes.
Technical Specifications
- File extension(s):
.jpg,.jpeg,.jpe,.jfif - MIME type:
image/jpeg - Compression type: Lossy, based on Discrete Cosine Transform (DCT). The image is divided into 8x8 pixel blocks, transformed into frequency domain, quantized (where data loss occurs), and entropy coded (Huffman or arithmetic).
- Color depth: Typically 24-bit (8 bits per channel, RGB). Supports 8-bit grayscale. No alpha channel (no transparency).
- Max dimensions: 65,535 x 65,535 pixels
- Max file size: No formal limit (practical limit depends on dimensions and quality)
- Metadata support: EXIF (camera data, GPS, orientation), IPTC (captions, keywords), XMP (extensible metadata), ICC color profiles
- Color spaces: sRGB (most common), Adobe RGB, CMYK (rarely used)
- Progressive mode: Supports progressive encoding where the image loads in successive refinement passes rather than top-to-bottom
How to Work With It
Opening & Viewing
JPEG is universally supported. Every operating system, web browser, image viewer, and photo application can open JPEG files natively. No special software is required.
Creating & Editing
- Quality setting: Ranges from 1-100 (or 1-12 in Photoshop). Quality 75-85 provides the best balance of file size and visual quality for most uses. Quality below 50 introduces visible artifacts (blockiness, color banding, mosquito noise around edges).
- Re-saving warning: Each save re-applies lossy compression, causing generational quality loss. Edit from originals when possible, or use a lossless format for intermediate edits.
- Tools: Any image editor (Photoshop, GIMP, Paint.NET, ImageMagick, Pillow/PIL in Python, Sharp in Node.js)
- Command line:
magick input.png -quality 82 output.jpg(ImageMagick) - Chroma subsampling: 4:4:4 preserves color detail, 4:2:0 reduces file size ~33% with minimal visible impact on photos (but can affect sharp color edges like red text on white)
Converting To/From
- To JPEG:
magick input.png output.jpgorffmpeg -i input.png output.jpg - From JPEG:
magick input.jpg output.png(note: converting lossy to lossless does not recover lost data) - Batch convert:
magick mogrify -format jpg -quality 85 *.png - Python:
from PIL import Image; Image.open("in.png").convert("RGB").save("out.jpg", quality=85) - Lossless operations:
jpegtrancan rotate, crop, and optimize JPEG files without re-compressing
Common Use Cases
- Digital photography (cameras default to JPEG)
- Web images and photo galleries
- Email attachments and social media uploads
- Print-ready images (at high quality settings, 300 DPI)
- Thumbnails and image previews
- Any scenario where small file size matters more than pixel-perfect quality
Pros & Cons
Pros:
- Universal compatibility across all platforms and software
- Excellent compression ratio for photographic content (10:1 to 20:1 with good quality)
- Adjustable quality/size tradeoff
- EXIF metadata preserves camera and location data
- Progressive loading for web delivery
- Extremely mature ecosystem with decades of optimized encoders (mozjpeg, libjpeg-turbo)
Cons:
- No transparency support (no alpha channel)
- Lossy compression causes artifacts, especially at low quality or on sharp edges/text
- Generational loss on re-saving
- Poor for text, line art, screenshots, or images with sharp color boundaries
- No animation support
- 8-bit per channel limit (no HDR)
- Block artifacts visible at high compression (8x8 pixel grid pattern)
Compatibility
| Platform | Support |
|---|---|
| Web browsers | All (universal since the 1990s) |
| Windows | Native |
| macOS | Native |
| Linux | Native |
| iOS/Android | Native |
| Adobe suite | Full |
| Office apps | Full |
Practical Usage
Web Optimization Pipeline
The standard workflow for serving JPEG on the web:
- Export from your source (Photoshop, Lightroom) at quality 95+ or lossless
- Optimize with
mozjpegfor production delivery:cjpeg -quality 82 -progressive input.ppm > output.jpg - Serve with
<picture>element offering WebP/AVIF with JPEG fallback
# Batch optimize with mozjpeg (via ImageMagick delegate or standalone)
for f in *.jpg; do
cjpeg -quality 82 -progressive "$f" > "optimized/$f"
done
Lossless Operations with jpegtran
jpegtran performs operations without recompressing, avoiding generational loss:
# Lossless rotation (corrects EXIF orientation physically)
jpegtran -rotate 90 -perfect input.jpg > rotated.jpg
# Optimize Huffman tables without quality loss
jpegtran -optimize -progressive input.jpg > optimized.jpg
# Lossless crop (must align to 8/16-pixel MCU boundaries)
jpegtran -crop 640x480+0+0 input.jpg > cropped.jpg
Metadata Management
EXIF data can contain GPS coordinates, camera serial numbers, and thumbnails. Strip before publishing if privacy matters:
exiftool -all= photo.jpg # remove all metadata
exiftool -gps:all= photo.jpg # remove GPS only, keep other EXIF
exiftool -overwrite_original -all= -TagsFromFile @ -ColorSpaceTags photo.jpg # strip metadata but keep ICC profile
Quality Selection Guidelines
- Quality 92-95: Visually lossless for most content. Use for archival or print-source files.
- Quality 80-85: Excellent web quality. The sweet spot for most delivery.
- Quality 60-75: Acceptable for thumbnails, previews, and bandwidth-constrained delivery.
- Below 50: Visible blocking artifacts. Only use when file size is severely constrained.
Anti-Patterns
Re-saving JPEG files repeatedly. Each save cycle recompresses and degrades the image. Edit from the original source (RAW, PSD, TIFF) and export to JPEG only as the final delivery step.
Using JPEG for screenshots, text, or line art. JPEG's DCT compression produces visible ringing artifacts around sharp edges. Screenshots and text-heavy images should use PNG or WebP lossless.
Setting quality to 100 and assuming no loss. JPEG at quality 100 is still lossy — the quantization tables are just less aggressive. If you need truly lossless, use PNG or TIFF. Quality 100 JPEG is 2-3x larger than quality 90 with negligible visual difference.
Stripping ICC profiles during optimization. Removing the ICC color profile can cause colors to shift, especially for images in Adobe RGB or Display P3. Always preserve the color profile or convert to sRGB before stripping.
Ignoring EXIF orientation. Many phones store photos in landscape orientation with an EXIF tag indicating rotation. Tools that ignore this tag display images sideways. Apply orientation with jpegtran -rotate or exiftool -Orientation=1 -n before processing.
Related Formats
- JPEG 2000 (.jp2): Wavelet-based successor with better compression and lossless mode, but limited adoption
- JPEG XL (.jxl): Modern successor with lossless JPEG recompression, progressive decode, and HDR support
- WebP: Google's alternative offering better compression at equivalent quality
- AVIF: AV1-based format with superior compression efficiency
- HEIC: Apple's preferred photo format using HEVC compression
- PNG: Lossless alternative when transparency or exact pixel preservation is needed
Install this skill directly: skilldb add file-formats-skills
Related Skills
3MF 3D Manufacturing Format
The 3MF file format — the modern replacement for STL in 3D printing, supporting colors, materials, multi-object assemblies, and precise manufacturing data in a single package.
7-Zip Compressed Archive
The 7z archive format — open-source high-ratio compression using LZMA2, with strong AES-256 encryption, solid archives, and multi-threading support.
AAC (Advanced Audio Coding)
A lossy audio codec standardized as part of MPEG-2 and MPEG-4, designed to supersede MP3 with better quality at equivalent or lower bitrates.
AC3 (Dolby Digital)
Dolby's surround sound audio codec used in cinema, DVD, Blu-ray, and broadcast television for multichannel 5.1 audio delivery.
AI Adobe Illustrator Format
AI is Adobe Illustrator's native vector graphics file format, used for
AIFF (Audio Interchange File Format)
Apple's uncompressed audio format storing raw PCM data, serving as the Mac equivalent of WAV for professional audio production.