Introduction
JPEG is the most common format for photographs. It is named after the Joint Photographic Experts Group, whose 1992 standard (ITU-T T.81, ISO/IEC 10918-1) defines the compression. The compression is lossy: it divides the image into 8 by 8 blocks, keeps the detail the eye notices most and discards the rest, so files are small and the quality setting trades size against artefacts.
The standard defines the compressed data but not a complete file. The file around it
comes from JFIF, the JPEG File Interchange Format, or from Exif, which cameras use to add
the date, exposure, orientation and location. Both use the same extensions:
.jpg, .jpeg, .jpe and .jfif.
Structure
A JPEG file is a sequence of segments, each starting with a marker: the byte
FF and a code. Most markers are followed by a 2-byte big-endian length that
counts itself but not the marker. The file starts with SOI (FF D8) and ends
with EOI (FF D9).
Between them, application segments carry metadata: APP0 for JFIF and
APP1 for Exif and XMP. Quantisation tables (DQT), the frame
header (SOF0 for baseline, SOF2 for progressive) and Huffman
tables (DHT) follow. The start of scan (SOS) is followed by the
compressed image data, in which any FF byte is written as
FF 00 so it cannot be mistaken for a marker.
0SOI start of imageFF D82 bytes2APP0 JFIF or APP1 Exif metadatavaries…DQT quantisation tablesvaries…SOF0 or SOF2 size, precision and componentsvaries…DHT Huffman tablesvaries…SOS start of scan, then the compressed datavaries…EOI end of imageFF D92 bytes
The file explorer on this site shows the segments, the Huffman and quantisation tables, every 8 × 8 block of baseline, extended and progressive images, and pictures of the transform. Drop a JPEG on any page to see it.
Reference
- Markers and segments – every marker code, the segment layout and their order
- Frame header – SOF, the size, components, sampling, blocks and MCUs
- Quantisation tables – DQT, byte by byte, and the zig-zag order
- Huffman tables – DHT, how the codes are made, and what the symbols mean
- Scan – SOS, the entropy-coded data, byte stuffing and restart markers
- How the coding works – from pixels to bits, step by step
- Progressive JPEG – spectral selection, successive approximation and end-of-band runs
- Application segments – JFIF, Exif, XMP, ICC, MPF, Photoshop and Adobe
Arithmetic coding and the lossless and hierarchical processes are left out of these pages, and JPEG XL and JPEG 2000 are separate formats.
Not described
The pages follow ITU-T T.81 for Huffman-coded DCT images, JFIF 1.02 and the Exif tag lists. The parts below are not yet described, or not yet decoded by the file explorer, which labels them in its tree and views and shows their bytes instead of guessing.
Known, not yet covered
- Reference and viewer: arithmetic coding (SOF9, SOF10, SOF11, SOF13 to SOF15 and the QM-coder of T.81 annex D). The frame headers, DAC and TEM segments are read, but the pages do not explain the coder or the DAC conditioning values, and the explorer does not decode the scan, so it shows no blocks for these files.
- Reference and viewer: the lossless processes (SOF3, SOF7, SOF11, SOF15; T.81 annex H): the predictors, the point transform and the Huffman coding of differences. The frame header and the SOS predictor field are named, but the scan is shown as bytes and no picture is made.
- Reference and viewer: the hierarchical process (DHP, EXP, the differential frames SOF5 to SOF7 and SOF13 to SOF15; T.81 annex J). The segments are named and their fields listed, but the pyramid of frames, the up-sampling between them and the way differences are added are not described, and the explorer takes only a single frame apart.
- Reference and viewer: 12-bit DCT images (SOF1, SOF2 with 12-bit samples). The explorer takes their blocks apart and draws the transform pictures, but no browser draws the image itself, and the pages cover the larger Huffman categories only in a sentence.
- Reference and viewer: JPEG-LS (SOF55 and the LSE preset parameters segment, ITU-T T.87). The marker is named and the LSE body is shown as bytes; the format is a different standard, and the scan is not decoded.
- Viewer: images whose height comes from a DNL segment. The height is shown, but no picture is drawn, because browsers do not read DNL and the shared decoder does not either.
- Viewer: files with more than four components, or with 2 components, are drawn by the shared decoder, which handles Huffman-coded images only; the block views (DC terms, each component, bits per block) take frames of up to four components.
- Viewer: the Exif maker note (tag 927C) is shown as a count of bytes. Each maker lays it out differently, and the viewer reads none of those layouts. Exif tags that have no name in the viewer’s lists are shown by number.
- Viewer: ICC profiles are read as far as the header, the tag table and the description; the contents of the other tags (curves, matrices, lookup tables) are shown as bytes. A profile split over several segments is shown in its pieces, not joined.
- Viewer: Photoshop image resources are named by ID, but only the IPTC records, thumbnails, JPEG quality and the digest are read; the other resources (paths, guides, layer state, print settings and so on) are shown as bytes.
- Viewer: XMP is shown as its text, not as a tree of properties.
- Viewer: the Ducky segment’s comment and copyright text, and any Ducky tag other than quality, are shown as bytes.
- Viewer: application segments the explorer does not recognise are shown as their identifier and bytes. These include APP3 (Kodak Meta), APP4, APP5 (Ricoh RMETA), APP6 (GoPro and EPP), APP7, APP8 (SPIFF), APP10 (PhotoStudio comment), APP11 (JUMBF and JPEG XT), APP15, APP2 FlashPix, vendor APP1 segments other than Exif and XMP, and the private data some cameras and editors keep in APP0 to APP15.
Unknown
- Reference and viewer: the layouts of vendor application segments and maker notes that no maker has published. They are shown as labelled bytes.
- Reference and viewer: the reserved markers (
FF 02toFF BF) and the markers JPG, JPG0 to JPG13, which T.81 reserves for extensions. Files that use them are shown with the marker named and the body as bytes.
Links
Software
- Adobe Photoshop – Adobe’s image editor, which opens and saves JPEG (Windows, macOS)
- Adobe Lightroom – Adobe’s photo organiser and editor, which exports JPEG (Windows, macOS, mobile)
- GIMP – free image editor that opens and saves JPEG (Windows, macOS, Linux)
- Paint.NET – free image editor that opens and saves JPEG (Windows)
- IrfanView – image viewer and converter (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
- darktable – free photo editor and raw developer that exports JPEG (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert and edit JPEG (Windows, macOS, Linux)
- Squoosh – Google’s image compressor that runs in the browser (web)
Developers
- libjpeg-turbo – the common library for reading and writing JPEG (C)
- MozJPEG – encoder built on libjpeg-turbo that makes smaller files (C)
- Pillow – imaging library that reads and writes JPEG (Python)
- sharp – fast image processing that reads and writes JPEG (Node.js)
Reference
- ITU-T T.81 – the JPEG compression standard, hosted by the W3C
- JPEG File Interchange Format 1.02 – the JFIF file format, hosted by the W3C