Skip to content

Compression and quality ​

The last lesson worked out that a 12-megapixel photo is about 36 MB of raw pixels, yet your phone stores it in 3 or 4 MB. This lesson shows how that works, what the Quality slider in every app really trades away, and how to make a photo small enough for email without making it ugly.

Two kinds of compression ​

Compression means storing the same thing in fewer bytes. There are two kinds.

KindWhat it keepsUndo it and you getExamples
LosslessEvery bitThe exact originalPNG, GIF, ZIP, FLAC, lossless WebP
LossyWhat you are likely to noticeSomething close, not identicalJPEG, lossy WebP, AVIF, HEIC, MP3, AAC, H.264 video

Lossless compression finds repetition and writes it more briefly. A row of 500 identical white pixels can be stored as "white, 500 times". That works well for screenshots and logos, with their large flat areas, and badly for photos, where neighbouring pixels are almost never exactly the same.

Lossy compression goes further: it throws away detail your eyes are bad at seeing, such as tiny changes of colour and very fine texture, and then compresses what is left. The loss is permanent.

The numbers, measured ​

These sizes come from one 3840 × 2160 photo of a woodland, full of fine leaves and flowers, saved in different ways:

Saved asFile size
Raw pixels (3 bytes each, no compression)24.9 MB
PNG, lossless15.8 MB
The original JPEG file3.7 MB
JPEG, quality 802.2 MB
WebP, quality 801.9 MB
JPEG, quality 401.1 MB

Lossless PNG only saved about a third. Lossy JPEG at quality 80 is about a tenth of the raw size.

A screenshot reverses the result. A 1280 × 720 screenshot of a settings page came out at 47 KB as PNG and 69 KB as JPEG quality 80, and the JPEG had smudges around every letter. Flat colour and sharp edges are what lossless compression is good at, and what JPEG is bad at.

What the quality setting does ​

Every lossy format has a quality setting, usually from 1 to 100. Higher keeps more detail and gives a bigger file.

text
quality   100 ──────────────── 80 ─────────── 60 ────────── 40 ─────── 20
size      largest                                                  smallest
looks     same as source     hard to tell     soft on zoom    blocky    very blocky

From the same woodland photo:

JPEG qualitySizeWhat you typically see at 100% zoom
954.2 MBSame as the source
802.2 MBHard to tell apart from the source
601.5 MBFine detail starts to soften
401.1 MBBlocks visible in smooth areas
200.7 MBClearly blocky, colour smears

Three things worth knowing:

  • Quality 95 was bigger than the original (4.2 MB against 3.7 MB). Saving at a higher quality than the photo was taken at does not add detail back; it spends bytes storing the existing flaws more carefully.
  • The middle of the range is where the savings are. Going from 95 to 80 halved the file; going from 80 to 60 saved much less, and the damage became visible.
  • The numbers are not a standard. Quality 80 in one app or format is not the same as quality 80 in another. Judge by eye and by file size, not by the number.

What JPEG damage looks like ​

JPEG works on small blocks of 8 × 8 pixels. At low quality you start to see:

  • Blocking: a grid of little squares in smooth areas such as sky or skin.
  • Ringing: faint halos or "mosquito noise" next to sharp edges and text.
  • Colour bleeding: colours smearing past their edges, especially strong reds.

Look for them by zooming to 100% on a face, a sky and any text.

Why re-saving a JPEG makes it worse ​

Each time you open a JPEG, change something and save it as JPEG again, the encoder throws away detail once more. This is called generation loss.

We measured it on the woodland photo. PSNR is a score for how close a copy is to the original, in decibels: higher is closer, and every 3 dB lower means roughly twice as much error.

SavesSame quality 75 each timeCropped by 1 pixel, then saved at 75, each time
132.8 dB32.8 dB
232.4 dB31.0 dB
531.7 dB28.1 dB
1031.5 dB25.8 dB

Re-saving with nothing changed loses a little each time. Editing between saves, such as cropping, rotating, filtering or switching apps, loses far more, because the 8 × 8 blocks no longer line up with the last save.

That is why a picture that has been screenshotted, posted, downloaded and re-posted many times looks smeared.

The habit that avoids it

Keep the original. Always make copies from the original, not from the last copy, and save the final version once, at the end.

Choosing between size and quality ​

You usually have a limit: an email attachment cap, a form that accepts 500 KB, a page that should load fast. There are three levers, in the order to try them:

  1. Make it the right number of pixels. A photo that will be seen on a phone or a laptop screen rarely needs more than 1600 to 2000 pixels on its longest side. Halving both width and height leaves a quarter of the pixels.
  2. Then lower the quality, to around 70 to 85 for photos.
  3. Then change the format, for example WebP instead of JPEG, if the place you are sending it accepts it.

Resizing first is the step people skip, and it matters most, as the next example shows.

Worked example: a photo for email ​

You want to email a 3840 × 2160 photo of 3.7 MB, and the copy should be under 1 MB.

Attempt 1: quality only. Keep all the pixels and lower the quality until it fits:

SizeQualityFile
3840 × 2160601.5 MB, too big
3840 × 2160401.1 MB, still too big, and blocky

To fit, you would need a quality below 40, which looks bad.

Attempt 2: resize, then a normal quality.

SizeQualityFile
1920 × 108080633 KB
1600 × 90080459 KB
1280 × 72080303 KB

At 1600 × 900 and quality 80 the photo is an eighth of its old size, looks clean on any screen, and leaves room for a second photo in the same email.

In CompressX, the Email (< 1 MB) preset in Image Compressor does this search for you: it finds the best JPG quality that fits under 1 MB, and scales the image down if even the lowest quality is too big. To control the size yourself, pick a Max dimension such as 1920 px and set Quality to 80. See Compress and convert images.

For a fixed limit on a web form, Reduce Image Size in Dhiva Tools takes a target such as 500 KB and gives you a JPG under it. See Reduce Image Size.

When a file does not get smaller, it was already compressed well. CompressX then keeps the original and says already optimized, original kept; DL Image Tools shows Saved as 0%. Resize instead of pushing the quality down.

Metadata and EXIF ​

A photo file holds more than pixels. Cameras and phones add metadata, information about the photo, in a block called EXIF (Exchangeable Image File Format). It can include:

  • the camera or phone make and model, and its settings (exposure, focal length);
  • the date and time the photo was taken;
  • which way up the camera was held (the orientation);
  • the GPS position where the photo was taken, if location was on in the camera app.

Here is the EXIF from a test photo, read with Python and the Pillow library:

bash
python3 -c "
from PIL import Image, ExifTags
exif = Image.open('photo.jpg').getexif()
for tag, value in exif.items():
    print(ExifTags.TAGS.get(tag, tag), value)
print('GPS', dict(exif.get_ifd(0x8825)))
"
text
Model Phone X
DateTime 2026:06:14 09:12:44
GPSInfo 102
Make ExampleCam
GPS {1: 'N', 2: (12.0, 58.0, 20.0), 3: 'E', 4: (77.0, 35.0, 40.0)}

The last line is a latitude and longitude in degrees, minutes and seconds: 12° 58′ 20″ N, 77° 35′ 40″ E. Type those into any map and you see where the photo was taken; a phone usually records it closely enough to pick out the building. For a photo taken at home, that is your address.

Removing the metadata does not touch the pixels. The same test photo went from 538,790 bytes to 536,403 bytes with all EXIF removed, and looked identical.

Stay safe ​

  • Check before you share photos publicly. Many social networks remove EXIF when you upload, but email attachments, cloud-drive links, chat apps sending "as a file" and many websites pass the original file on unchanged. Do not rely on someone else to strip it.
  • Remove it yourself when in doubt. In CompressX, turn on Remove metadata (EXIF) in Image Compressor. DL Image Tools removes EXIF from everything it compresses, converts, resizes or crops, and its Metadata tab shows Metadata (EXIF): Available or Not available for a JPG. See Metadata is removed.
  • Turn off location in the camera app if you never want it recorded.
  • Keep your originals in a private place. Compression is a one-way trip; you cannot recover the full-quality photo from a compressed copy.
  • Watch the "delete originals" settings. CompressX's Keep original files setting is on by default. If you turn it off, the image modules permanently delete each original after processing, and the files do not go to the trash. See Keep original files.

Good to know

If a photo appears sideways after its metadata was removed, the tool dropped the orientation tag without turning the pixels first. Rotate the copy (DL Image Tools has a Rotate/Flip tab) and keep going.

Check yourself ​

QuizCompression and quality

Question 1 of 6

Which of these is lossless?

Score: 0

What you learned ​

  • Lossless keeps every bit (PNG, ZIP, FLAC); lossy discards detail you are unlikely to notice (JPEG, WebP, MP3).
  • Quality settings trade size for detail; the middle of the range gives the best savings, and numbers differ between apps.
  • Every re-save of a JPEG loses a bit more, and edits between saves lose much more. Work from the original.
  • To shrink a photo, resize first, then lower the quality, then consider the format.
  • EXIF metadata can hold the exact place a photo was taken. Strip it before sharing publicly.

Next steps ​