The JPG file format

Level:Advanced
Anwendung:Background knowledge

The JPG format explained straightforwardly – how does it work, what are its benefits, why is it so suitable for photos. Plus: which quality losses occur when, with image examples.

What is JPG or JPEG?

Screen shot file sizes JPG, NEF, PNG, TIF

JPG or JPEG is the most commonly used format for files containing digital photos. It does not matter whether a file is called .jpg or .jpeg; .jpg is just the usual shortening of .jpeg to three letters for file types.

JPEG is the name of the organisation that defined this format in 1992 (full name: Joint Photographic Experts Group), it is backed by several organisations responsible for international standardisation (ISO and the lesser known IEC and ITU).

It has obvious advantages for digital photography:

  • Small file sizes, so less storage is needed on hard drives, memory cards and faster transmission over the internet. The logic for compressing the data is developed in such a way that it works particularly well for photos.
  • The compression is very flexible, you can create files of different sizes from an original image depending on your needs. In the best possible JPG quality, the file size is already massively reduced and associated quality losses are only theoretically present, not visible. If an image file is to be particularly small, the compression can be increased and the storage requirement massively further reduced at the expense of the image quality.

JPG file size compared to other formats

Here is an example photo that has a resolution of 24 megapixels (MP) from the camera. Each pixel has three colour values for red, green, blue, each requiring one byte. Without compression, such a photo needs approx. 24 × 3 = 72 million bytes = just under 70 megabytes (MB). I saved the picture in the best possible JPG quality as well as a few other file formats, the result is clear:

  • At the top, the file size without compression (TIF format), the previously estimated almost 70 MB.
  • Below that, three file types other than JPG:
    • ZIP, which is widely used for all kinds of file types.
    • TIF format with lossless compression – 30 MB, a little less than half the original size.
    • PNG, a file format that is common and advantageous for graphics; but for photos it produces very large files.
  • JPG in best possible quality needs about 13 MB – less than a fifth of the original data and less than half of PNG and TIF format above.

JPG compression has less of an effect on photos with a lot of detail and can therefore vary depending on the subject, but the advantage for JPG remains. For example, if your photo consists only of sky and clouds, the JPG file can be only half the size.

There is no loss of quality in the best possible JPG quality, but for the sake of completeness, here is a comparison with the lossless PNG format.

I also looked for differences with a magnifying glass, so to speak, and created and analysed a difference between the images in Photoshop. Result: Minimal deviations can be detected, but below what the eye can perceive.

JPG file sizes with different compression rates

The JPG format can go much further; the compression is configurable. Here is an example of a screenshot from the popular image editing programmes Lightroom and DxO PhotoLab. Cameras also often have setting options for the JPG quality with labels such as Fine/Standard, FINE/NORM/BASIC or similar.

It is common but misleading that the slider is labelled ”Quality“. When you move it, it is JPG compression rate that changes. The quality does not decrease continuously, as the label and a scale of 0-100 suggest. It sounds as if you only get 80% of the original quality when moving the slider to 80. It is not like that.

The top bar of this graph is the minimum compression/maximum quality of 100, corresponding to the bottom bar from the first graph. The file size quickly drops again by more than half at 90, 80 and then slower and slower.

The lowest values have no practical meaning; quality losses become obvious and who would voluntarily push the quality slider all the way to the left?

A ”JPG quality“ of 80 compresses the file size for the example photo again by more than half, to less than 10% of the original size – still without visible quality losses.

Why is JPG particularly suitable for photos?

Compression of the data volume uses two methods that are particularly effective with digital photos:

Different resolution for brightness and colour information | The human eye perceives differences in brightness more sensitively than differences in colour. Saving a digital photo in JPG format cleverly exploits this:

  • The output data with three colour information for red, green, blue are converted into a different representation of brightness and colourfulness. In technical terms: luminance and chrominance, abbreviated YCbCr. Such an encoding of coloured images also happens with video signals.
  • The trick: the brightness information is retained in full resolution; the colour information can be stored in lower resolution, depending on the strength of the compression. The amount of data can decrease considerably with little or no perceptible loss of quality.

Mathematical methods that are particularly effective for photos | One characteristic of photo data is that neighbouring pixels are usually very similar to each other. Almost never exactly the same, not even with seemingly uniform surfaces like a blue sky. And also never with quite abrupt changes like in a razor-sharp text document. Colour and brightness transitions in photos are almost always continuous and not erratic from one pixel to the next, even at seemingly sharp edges.

JPG compression describes the data patterns present there for small blocks of neighbouring pixels with a mathematical function. In this way, the data present in the original image can be reconstructed approximately from the JPG file – more or less accurately, with minimal or greater deviations.

The mathematics behind this are complicated, a so-called discrete cosine transformation, which you don't learn in school, not even in advanced maths courses, and also two grammar school teachers for math & pyhsics I asked had no idea what exactly this is.

But we can summarise results in simple terms: This mathematical procedure is the reason why compression is less effective with images that are rich in detail than with subjects that have many smooth surfaces and slow colour gradients.

The loss of quality is most noticeable in the case of

  • exactly sharp edges, therefore other file formats are better suited for e.g. writing or graphics with thin lines
  • fine structures, e.g. a meadow with fine blades of grass, structure of rough surfaces.

Possible quality losses in JPG format

Artefacts and block-like patterns

Artefacts are generally something artificially created, in digital photos they are image distortions that only occur during later image processing and do not originate from the original shot.

In JPG files, artefacts occur:

  • at sharp edges, previously clean transitions appear grainy, around them single slightly deviating pixels appear
  • on very smooth surfaces, previously continuous colour gradients can acquire block-like patterns.

    Here is a section of the example photo with different JPG compressions, where the block-like patterns become visible with high compression.

    To detect individual artefacts, you have to look very closely. To help you do this, I have added an even smaller section of the original image and two low JPG compressions, enlarged 4 times.

    It illustrates the fine inaccuracies that are indeed present even at high quality levels, but really these image distortions are not relevant... to be bothered by them you have to literally examine an image with a magnifying glass.

    In sections of the picture with fine details and structures, individual pixels that have been changed by the compression are lost and cannot be recognised individually. There, the overall impression becomes more blurred.

    Slight colour shifts

    As a result of JPG compression, colour tones can shift marginally. To illustrate this effect, I have resorted to an artificially created graphic, since in photos even monochrome areas do not produce perfectly equal-coloured pixels, the effect is extremely difficult to observe there.

    Six circles in the primary colours red, green, blue and their mixtures with full saturation appear minimally different after saving as JPG: red has a tonal value of 254 instead of 255, the green circle suddenly has a blue component of 1 instead of 0, others are exactly as before. In the example, the changes already occur with the best JPG quality, but do not increase with stronger compression.

    These are very subtle changes, practically not observable in real photos - unless they amount to 2 or even 3 and you put photos directly on top of each other to look for differences like a scientist.

    Saving a photo several times

    When you save a JPG photo again, the compression leads to a loss of quality each time – this is theoretically undeniable. Again, however, this is hardly visible, not really relevant in practice. I have opened the above example photo 12 times and saved it again, each time in JPG quality 80. Compare for yourself...

    Assessing the quality losses

    You can find many warnings about quality loss with the JPG format on the internet, I wouldn't worry about it. They don't really matter in practice as long as you avoid very high compressions.

    In all cameras and image processing programmes you can assume that a high JPG quality of e.g. 90 is preset. Rather higher than necessary, I have often recompressed JPG photos as they came out of the camera and drastically saved storage space without any visible loss.

    You need to look at photos not only very closely but also at full size to see any losses.

    My simple reference figures are:

    • A JPG ”quality“ of 80 is perfectly ok and without visible quality losses;
    • with 90 you are really on the safe side.
    • 100 produces much larger files and no perceptible advantages.

    Reminder: The term ”JPG quality“ in image editing programmes and camera settings is misleading. There you set the JPG compression, the quality does not decrease continuously.

    Other factors play a much bigger role if you are not satisfied with the overall quality of your photos. At the top of the list is noise reduction, which makes photos look smudged, and of course all the other reasons for blurred, unsharp images.


    Comments or questions? Type in & send!

    Our privacy policy applies.

    -