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.
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:
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:
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.
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.
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:
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
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:
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.
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.
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...
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:
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.