Main page > File formats > Images

JPEG / JFIF image file format

Typical file name extensions
.jpg
.jpeg
Magic bytes
0xff 0xd8 at file offset 0x00
MIME types
image/jpeg
image/pjpeg (for progressive JPEGs)
Image types
Continuous tone images (photos) with 5 or more bits per channel.
Most popular color types: grayscale, 8 bits (one channel) and YCbCr color, 24 bits (three channels). Also YCCK, 32 bits (four channels).
Popularity
Very high. Standard file format for the exchange of photos.
Other formats
JPEG (or at least a part of its compression types) can be used as compression type within TIFF. There are two numbers for it, old-style, and modern. Various other formats embed JFIF bitstreams, e.g. PDF.

Description

In 1990, the Joint Photographic Experts Group defined various methods to be used for photo image compression. They also defined a bitstream to store the various data structures and compressed image data.

Canadian company C-Cube Microsystems (acquired in 2001 by LSI Corporation) added a few details to make the interchange of JPEG bitstreams possible, including the color space. Their format was called JPEG File Interchange Format, or short, JFIF.

JPEG2000 is not an extension of JPEG but a completely new development.

A good introduction to JPEG is part of the JPEG FAQ.

File structure

A JPEG bitstream is a sequence of data chunks, each chunk starts with a marker value. A marker is a 16 bit integer value, stored in big endian byte order, with the most significant byte set to 0xff. The lower byte of the marker value determines its type. A marker is followed by a 16 bit integer value for the size.

Compression

JPEG defines a number of compression types to be used. However, only two of these types are in widespread use, Baseline DCT / Huffman and its progressive version. Both of these popular compression types are lossy (decompressing the compressed JPEG will thus not result in an identical copy of the original). There are lossless compression types, but they are rarely used, so the typical saying that JPEG is lossy isn't perfectly accurate, but true most of the time.

Optimizing JPEG compression for size

There are various options to choose from when saving an image file as JPEG, and a number of optimization tools. Some of the following steps can be performed by almost every application capable of saving images in JPEG format.

With the free command line tool jpegtran (see the Applications section below) some of the steps can be performed like this:

jpegtran -copy none -optimize -progressive < in.jpg > out.jpg

The copy none switch removes extra markers, which includes EXIF metadata. With optimize the resulting JPEG gets optimized Huffman tables while progressive turns on the progressive mode. Obviously, a command line program can be easily run in a script which you might be using anyway to export images for usage in a Web environment. The additional call to jpegtran can save some traffic in the long run.

Metadata

Software

Metadata libraries

Libraries

Applications

Literature

Websites