JPEG File Size Variations


Today’s Question: In a recent answer you said about JPEG file sizes: “with variation based on the actual contents of the image”. What do you mean by that? Wouldn’t the file size be based only on the pixel dimensions and the quality setting used.

Tim’s Quick Answer: The file size of a JPEG image is primarily determined by the pixel dimensions and the quality setting. However, the specific file size result will vary based on the complexity of information in the image file. In other words, the more variation there is in pixel values, the larger the file size is likely to be.

More Detail: JPEG compression operates by dividing the image up into blocks of pixels and simplifying the information within each block. For example, an image would typically be divided into blocks of 256 pixels (16×16 pixels in a block). Within each block, the pixel values are simplified.

For example, let’s assume that in a given block all 256 pixels are pure white. With no compression at all, you essentially would need to say “white” 256 times to describe the contents of the block. But it would be much more efficient to simply say “256 white pixels”.

In a similar way, JPEG compression will alter the pixel values within each block in order to be able to describe the pixel values more efficiently, resulting in a smaller file size.

For my example of 256 white pixels, the information can be described with great efficiency, so that block would represent a smaller file size. If, on the other hand, there was tremendous variation within a block of pixels, it isn’t as easy to simplify the contents of that block without further degrading image quality. That would result in a larger file size.

So, with an image at a particular size in terms of pixel dimensions, and with a specific quality setting for the JPEG compression, the file size can still vary considerably for different photos based on the actual contents of the image.