Quick answer: For photos on the web, use WebP at quality 75–85 — it looks the same as a JPEG but the file is typically 25–35% smaller. Use PNG only for graphics with sharp edges, text, or transparency, and use AVIF when you can offer a JPEG or WebP fallback. The biggest win is almost always resizing the image to the size it will actually be displayed at.
Every image on a website is a trade-off between quality and file size. A single uncompressed photo can be larger than the rest of the page combined, and large images are the most common reason a page loads slowly. The good news is that you can usually cut an image to a tenth of its size with no visible difference — if you understand what compression actually does and pick the right format.
This guide explains how image compression works, how the four main formats (JPEG, PNG, WebP, and AVIF) differ, and how to shrink your images without anyone noticing.
What image compression actually does
An uncompressed image stores a colour value for every single pixel. A 12-megapixel photo has 12 million pixels, and at 3 bytes per pixel that is roughly 36 MB of raw data. Nobody ships images that way. Compression finds patterns in that data and stores it more cleverly.
There are two fundamentally different approaches, and everything else follows from them.
Lossless compression: smaller file, identical pixels
Lossless compression reorganises the data without throwing any of it away. When you open the image again, every pixel is exactly the same as the original. It works by finding repetition: large areas of flat colour, repeated patterns, and pixels that are similar to their neighbours can be described in fewer bytes. PNG and WebP's lossless mode work this way.
The catch is that a detailed photograph has very little repetition, so lossless compression can only shrink it by a modest amount — often just 10–30%. Lossless is perfect for logos, screenshots, and graphics with flat colours, and poor for photographs.
Lossy compression: smaller file, some data discarded forever
Lossy compression deliberately throws away information the human eye is least likely to notice. Once it is gone, it cannot be recovered, which is why you should always keep your original file and compress a copy.
Lossy methods exploit two facts about human vision. First, we notice brightness detail far more than colour detail, so the colour information can be stored at lower resolution than the brightness — a trick called chroma subsampling. Second, we are bad at spotting fine detail in busy or textured areas, so the encoder can smooth over tiny variations there. The result is a file that can be 5–20 times smaller than the original while looking identical at normal viewing size.
The skill in using lossy compression is knowing how far to push it. At quality 80, a JPEG is usually indistinguishable from the original. At quality 30, you will see blocky patches and smearing around edges. Somewhere between those extremes is the sweet spot for each image, and it is worth finding it rather than guessing.
How JPEG works
JPEG is the oldest format here — standardised in 1992 — and still the most widely supported image format on earth. It was designed for photographs and it shows.
Here is what happens when an image is saved as a JPEG:
- Colour conversion. The image is converted from RGB into a colour space that separates brightness (luma) from colour (chroma).
- Chroma subsampling. The colour channels are stored at half resolution (usually 4:2:0), because your eyes barely notice. This alone roughly halves the data.
- Block splitting. The image is divided into 8×8 pixel blocks.
- Frequency transform. Each block is converted from pixel values into frequencies using a discrete cosine transform (DCT). Smooth areas become a few low frequencies; fine detail becomes high frequencies.
- Quantisation. High-frequency detail is divided down and rounded off. This is the lossy step, and the quality setting controls how aggressive it is. Low quality means heavy rounding — and the visible blockiness JPEG is famous for.
- Entropy coding. What is left is packed efficiently using Huffman coding.
Strengths: universal support, excellent for photographs, small files, progressive loading (the image can appear blurry first, then sharpen).
Weaknesses: no transparency, no animation, quality degrades every time you re-save, and it is bad for images with sharp edges or text — the 8×8 blocks smear edges and make text look fuzzy.
How PNG works
PNG was designed in the mid-1990s as a patent-free replacement for GIF, and it is fully lossless. Instead of discarding detail, it predicts each pixel from the pixels already stored (usually the ones above and to the left), then stores only the difference between the prediction and the actual value. Those differences are small and repetitive, so they compress very well with the DEFLATE algorithm (the same one used in ZIP files).
Strengths: pixel-perfect quality, full transparency (an alpha channel), and razor-sharp edges and text. Ideal for logos, icons, screenshots, diagrams, and any graphic with flat colours.
Weaknesses: file sizes explode on photographs. A detailed photo saved as PNG can be 5–10 times larger than the same photo as a JPEG, because there is almost no repetition for the predictor to exploit. PNG has no lossy mode, so there is no quality dial to turn.
How WebP works
WebP, developed by Google, is a modern format that offers both a lossy mode and a lossless mode in a single format. Its lossy mode is based on the VP8 video codec: instead of JPEG's fixed 8×8 blocks, it predicts each block of pixels from the blocks around it, then stores only the prediction error. That prediction step is why WebP usually beats JPEG by a clear margin — in Google's own tests, WebP lossy images came out roughly 25–34% smaller than comparable JPEGs at the same visual quality.
Its lossless mode predicts pixels from their neighbours (similar in spirit to PNG) and then applies the same efficient packing, typically producing files about 25% smaller than PNG.
Strengths: smaller files than JPEG and PNG, supports transparency and animation, one format for almost everything, supported by every modern browser since Safari 14 (2020).
Weaknesses: slightly slower to encode than JPEG, and very old software or email clients may not display it — so keep a JPEG fallback for anything that leaves the browser.
How AVIF works
AVIF is the newest format, based on the AV1 video codec. It uses the same ideas as WebP — prediction plus a frequency transform — but with more powerful tools: larger and more flexible block sizes, better prediction modes, and more efficient entropy coding. The result is the best compression available today. In practice, an AVIF file is commonly around half the size of an equivalent JPEG, and noticeably smaller than WebP at the same quality.
AVIF also supports features the older formats cannot match: HDR (high dynamic range), a wide colour gamut, transparency, animation, and lossless mode, all in one format.
Strengths: the smallest files of any common format, excellent quality at low file sizes, HDR and wide colour support.
Weaknesses: encoding is slow, which matters if you generate images on the fly. Browser support is good but not universal — Chrome, Firefox, and Safari 16+ support it, but older browsers do not, so you still need a fallback. Some older image editors cannot open AVIF files yet.
JPEG vs PNG vs WebP vs AVIF: side by side
| Format | Compression | Transparency | Animation | Best for | Watch out for |
|---|---|---|---|---|---|
| JPEG | Lossy | No | No | Photographs, anywhere compatibility matters | Blocky artefacts at low quality; no transparency |
| PNG | Lossless | Yes | No | Logos, icons, screenshots, text graphics | Huge files for photographs |
| WebP | Lossy + lossless | Yes | Yes | Almost everything on the modern web | Very old browsers and email clients |
| AVIF | Lossy + lossless | Yes | Yes | Smallest files, HDR photos, quality-critical images | Slow encoding; needs a fallback for older browsers |
Which format should you use?
The format decision is easier than it looks. Work through these cases:
- A photograph on a website: WebP at quality 75–85. If you can serve a fallback, AVIF at quality 50–65 is even smaller. JPEG is the safe fallback.
- A logo, icon, or graphic with sharp edges: PNG if it must work everywhere, WebP lossless if it is only for the web. (If it is a vector logo, SVG is better than any of these.)
- A screenshot with text: PNG or WebP lossless. JPEG will blur the text.
- An image with transparency: PNG, WebP, or AVIF. Never JPEG — it has no transparency at all.
- An animation: WebP or AVIF. GIF only when you need maximum compatibility with ancient systems.
- An image in an email or a document: JPEG for photos, PNG for graphics. Many email clients still do not display WebP.
- An image for print: keep the high-resolution original, usually PNG or TIFF. Compression choices for the web do not apply to print.
When you are unsure, WebP is the best default for the web in 2026. And you do not have to choose just one format: the HTML <picture> element lets the browser pick AVIF if it supports it, fall back to WebP, and finally to JPEG. That gives every visitor the smallest file their browser can handle.
How to shrink an image without visible quality loss
Format choice is only half the job. Follow these steps in order — they are listed from the biggest win to the smallest.
1. Resize to the display size
This is the single biggest win, and the most commonly skipped. If an image will be displayed at 800 pixels wide, uploading a 4,000-pixel-wide original wastes roughly 95% of its pixels. Resize first, and the file often drops to a tenth of its size before you touch any quality setting. For sharpness on high-density ("retina") screens, export at twice the display size — not four times.
2. Pick the right format
Use the guide above. The most expensive common mistake is saving a photograph as a PNG: you pay a huge file-size penalty for quality nobody can see.
3. Find the quality sweet spot
For JPEG and WebP, start at quality 80 and look at the result at 100% zoom. If it looks clean, try 70. If you see blockiness or smearing, go up to 85. For most photos, the sweet spot is between 75 and 85 — below that, artefacts appear; above that, the file grows quickly for no visible gain. For AVIF, the equivalent range is roughly 50–65. Never save a JPEG at quality 100 for the web: it is typically twice the size of quality 90 with no visible difference.
4. Strip the metadata
Photos from phones and cameras carry EXIF data — camera settings, GPS location, thumbnails — that can add tens of kilobytes and also leaks your location. Most compression tools remove it automatically. Check that yours does, or strip it before uploading.
5. Use progressive JPEG for large photos
A progressive JPEG loads in stages — blurry first, then sharp — so the page feels faster even though the total file size is the same. It costs nothing and improves the perceived loading experience on slow connections.
6. Compare before you publish
Open the original and the compressed version side by side at full size. Check the places where compression damage shows first: text, sharp edges, smooth gradients (like skies), and faces. If you cannot tell them apart at 100% zoom, your visitors will not be able to either.
7. Serve responsive sizes
One file does not fit all screens. A phone on mobile data should not download the same 2,000-pixel image as a desktop monitor. Use srcset or the <picture> element to serve small, medium, and large versions, and let the browser pick.
A worked example: the same photo in every format
To make this concrete, here is what happens to a typical detailed landscape photograph, 2400 × 1600 pixels, when it is saved in each format. These are illustrative figures from a real-world-style test photo — your images will differ, but the pattern holds for almost any photograph.
| Version | File size | Compared with PNG |
|---|---|---|
| PNG (lossless) | ~4,200 KB | — |
| JPEG, quality 90 | ~620 KB | 85% smaller |
| JPEG, quality 80 | ~380 KB | 91% smaller |
| WebP, quality 80 | ~260 KB | 94% smaller |
| AVIF, quality 60 | ~180 KB | 96% smaller |
Two things stand out. First, simply switching from PNG to JPEG at quality 80 cuts this photo to less than a tenth of its size. Second, moving from JPEG to WebP saves another third, and AVIF saves half again — all three versions look the same at normal viewing size.
For the examples in this article, I used GetToolset's free compress-image-to-100kb and image-to-webp-converter tools, which run entirely in your browser — your photos are never uploaded to a server.
Common mistakes to avoid
- Uploading the original camera file. A 12-megapixel phone photo straight from the camera is 3–5 MB. Resize it before it ever touches your website.
- Saving photographs as PNG. PNG is lossless, which sounds better — but for a photo it means a file 5–10 times larger than necessary.
- Re-saving a JPEG over and over. Every save re-applies lossy compression, and the damage accumulates. Always edit the original and export a fresh copy.
- Using quality 100 "to be safe". It roughly doubles the file size versus quality 90, and nobody can see the difference.
- Using GIF for photographs. GIF is limited to 256 colours. Photos come out banded and blotchy — and usually larger than a JPEG.
- Forgetting the fallback. AVIF and WebP are excellent, but if you serve them with no JPEG fallback, visitors on older browsers see a broken image.
- Judging quality from a thumbnail. Compression damage hides at small sizes. Always check at 100% zoom before publishing.
Frequently asked questions
Is WebP better than JPEG?
For the web, yes. At the same visual quality, a WebP file is typically 25–35% smaller than a JPEG, and it also supports transparency and animation. JPEG is still the right choice when maximum compatibility matters — old email clients, desktop software, and anywhere the image might leave the browser.
Does compressing an image reduce its quality?
Lossy compression does discard data, but "reduced quality" and "visibly worse" are not the same thing. At sensible settings (JPEG or WebP at quality 75–85), the discarded detail is below what the human eye can notice. Lossless compression does not reduce quality at all — the pixels are identical, just stored more efficiently.
What is the best image format for a website in 2026?
WebP is the best default: small files, wide support, transparency and animation included. Offer AVIF first with a WebP or JPEG fallback via the <picture> element if you want the smallest possible files. Use PNG only for logos, icons, and screenshots with text.
Can I convert a PNG to JPG without losing quality?
Almost. A PNG of a photograph converted to JPEG at quality 85–90 will look the same and be far smaller. You do lose two things: transparency (JPEG has none — transparent areas become a solid colour) and the ability to re-edit losslessly. If the PNG is a logo or graphic with sharp edges, keep it as PNG or convert to WebP lossless instead.
What quality setting should I use?
For photographs: JPEG or WebP at 75–85, AVIF at 50–65. Start at 80 (or 60 for AVIF) and adjust: go lower if the image still looks clean, higher if you see blockiness, banding, or smeared edges. For graphics with text, use a lossless format instead of a quality setting.
Why is my PNG file so large?
Because PNG is lossless and photographs have almost no repeated patterns for it to exploit. A detailed photo saved as PNG can easily be 5–10 times larger than the same photo as a JPEG. If the image is a photograph, switch to JPEG, WebP, or AVIF — the PNG format is the wrong tool for that job.
Written by Jameel Khan. Last updated 30 November 2026.