Skip to content

Technical Guides

Lossy vs Lossless Compression - When to Use Each for Web Images

Lossy compression makes photos much smaller by discarding visual data. Lossless compression keeps every pixel. Learn when to use JPEG, PNG, WebP, AVIF, and lossless formats on the web.

By · Editor

Last verified May 24, 2026

Lossy compression makes images smaller by permanently discarding data. Lossless compression makes images smaller without losing a single pixel. Use lossy for photos and complex visuals. Use lossless for screenshots, logos, text, diagrams, transparency, and source files you may edit again.

TL;DR: Use lossy compression for photos, product images, hero images, backgrounds, and thumbnails. JPEG, lossy WebP, and AVIF are built for this. Use lossless compression for screenshots, logos, UI mockups, diagrams, icons, transparent graphics, and source files. PNG, lossless WebP, and JPEG XL are built for that. Most websites need both, and an image CDN can choose the right output per image and browser.

Tip

Simple Rule

If the image is a real-world photo, use lossy compression. If the image contains text, sharp UI edges, logos, transparency, or anything you may edit later, use lossless compression until the final delivery step.

Tip

Automatic Compression Selection

BunnyCDN Optimizer can serve modern compressed formats from the same source image, so you do not have to manually choose AVIF, WebP, JPEG, or PNG for every browser. Use coupon THEWPX for $5 free credit through this BunnyCDN signup link.


What Is the Difference Between Lossy and Lossless Compression?

Lossy compression removes image data permanently. The encoder tries to remove details the human eye is less likely to notice, such as tiny color changes, high-frequency noise, and detail in busy areas. The result can look almost identical at normal viewing size, but it is not the original image anymore.

Lossless compression keeps the original image exactly recoverable. It finds repeated patterns, predicts pixel values, and stores the same data more efficiently. When you decode a lossless image, you get the same pixels back.

QuestionLossy compressionLossless compression
Does it discard data?YesNo
Can the original be perfectly restored?NoYes
Best forPhotos and complex visualsText, logos, screenshots, diagrams
Typical web formatsJPEG, lossy WebP, AVIFPNG, lossless WebP, JPEG XL
File-size savingsUsually much largerSmaller, but exact
Visible riskArtifacts, banding, blurred edgesLarger files
Editing workflowFinal export onlySource and intermediate files

The key point is not that one is better. The key point is that they solve different jobs.

Lossy compression is better when visual similarity is enough. Lossless compression is better when exact pixels matter.


How Does Lossy Compression Work?

JPEG is the easiest format to understand because it shows the classic lossy workflow.

1. The image is split into blocks

JPEG splits the image into small blocks, usually 8 x 8 pixels. The encoder then works on each block separately.

2. Pixel data becomes frequency data

JPEG uses the Discrete Cosine Transform. In simple terms, it separates slow visual changes from fine detail. Smooth color changes are low-frequency data. Tiny edges and texture are high-frequency data.

3. Quantization throws data away

This is the lossy step. The encoder reduces precision in parts of the image where the eye is less sensitive. Higher compression throws away more data. Lower compression keeps more.

4. The remaining data is compressed losslessly

After the lossy step, the remaining numbers are compressed with entropy coding. This part does not discard more image information.

WebP and AVIF use newer techniques, but the idea is similar: predict what the image should look like, keep the important visual signal, and spend fewer bytes on details that are less noticeable.

Google's WebP study found WebP files were 25-34% smaller than JPEG at equivalent SSIM quality. AVIF often goes smaller again for photos, especially when the output is generated once and cached. For the practical format comparison, read WebP vs AVIF vs JPEG.


How Does Lossless Compression Work?

Lossless compression does not decide what you can afford to lose. It looks for redundancy.

PNG is the classic web example. It uses filtering plus DEFLATE compression. The encoder predicts pixel values from nearby pixels, stores the difference, then compresses repeated patterns.

That works beautifully on images with flat areas and repeated shapes:

  • logos
  • screenshots
  • UI mockups
  • diagrams
  • icons
  • simple illustrations

It works less well on noisy photos because every nearby pixel may be slightly different. There is less repetition to exploit.

Lossless WebP improves on PNG in many cases. Google's WebP lossless and alpha study found WebP lossless was 23% denser than ZopfliPNG and 42% smaller than default libpng output in its tests.

That is why the best modern answer for web graphics is usually not "PNG forever." It is PNG as the compatibility baseline, and lossless WebP when your delivery setup supports it. The lossless image formats guide goes deeper into PNG, WebP lossless, AVIF lossless, and JPEG XL.


When Should You Use Lossy vs Lossless Compression?

Use the image content as the deciding factor.

Image typeUseBest formats
PhotosLossyAVIF, WebP, JPEG
Product imagesLossyAVIF, WebP, JPEG fallback
Hero imagesLossyAVIF or WebP
Blog imagesLossyWebP, JPEG fallback
ScreenshotsLosslessPNG, lossless WebP
UI mockupsLosslessPNG, lossless WebP
LogosSVG first, then losslessSVG, PNG, lossless WebP
Diagrams and chartsSVG or losslessSVG, PNG, lossless WebP
Transparent graphicsLossless or alpha-preserving modern outputPNG, WebP, AVIF
Source files for editingLosslessPNG, TIFF, PSD, RAW, JPEG XL

Use lossy compression when:

  • the image is photographic
  • tiny detail loss is acceptable
  • the image is only for final web delivery
  • page speed matters more than exact pixel recovery
  • the image will not be edited and saved again

Use lossless compression when:

  • the image includes text
  • sharp lines must stay sharp
  • brand colors need to stay exact
  • transparency matters
  • the image is a source file or intermediate edit
  • re-saving would happen multiple times

The most common mistake is using JPEG for screenshots. It may look fine at a glance, but zoom in and you will often see fuzzy text, ringing around icons, and dirty edges around buttons.


How Much Smaller Do Files Get?

There is no universal percentage because the image decides the result.

A noisy camera photo, a clean product shot, a screenshot, and a flat logo all compress differently. Still, the pattern is predictable:

ContentLossy resultLossless result
Real-world photoMuch smaller, usually the right choiceOften too large
Product photoMuch smaller, usually the right choiceToo large unless used as source
Screenshot with textCan create ugly artifactsUsually the right choice
LogoCan blur edges or shift colorsUsually the right choice
Transparent iconJPEG is not safePNG/WebP/AVIF can preserve alpha
IllustrationDepends on styleTest both if quality matters

HTTP Archive's 2024 Media chapter gives useful real-world context. On mobile images, it reported median bits per pixel of:

FormatMedian bits per pixel
WebP1.3
AVIF1.4
JPEG2.0
PNG3.8
GIF6.7

Lower bits per pixel usually means a more byte-efficient delivered image. But do not read that table as "WebP is always smaller than AVIF" or "PNG is bad." WebP and AVIF are mostly used for optimized delivery, while PNG is often used for graphics where exact edges matter.

The practical lesson: measure your own images. Convert a few photos with the JPEG to WebP converter, convert a few graphics with the PNG to WebP converter, and compare visual quality at the display size users actually see.


Which Image Formats Are Lossy and Lossless?

Some formats are fixed. Some support both modes.

FormatLossy?Lossless?Practical note
JPEGYesNoBest as photo fallback. Not for transparency or sharp text.
PNGNoYesExcellent for screenshots, transparency, and pixel-perfect graphics.
WebPYesYesPractical modern default. Use lossy for photos, lossless for graphics.
AVIFYesYesStrong lossy photo compression, slower encoding, good when cached.
GIFNo in normal useYes, but 256-color limitedUse mainly as legacy animation fallback.
SVGNot rasterNot rasterVector format for logos, icons, charts, and diagrams.
JPEG XLYesYesPromising for archival and future delivery, but weak browser support today.

Quick Note: WebP is both lossy and lossless. That is why "is WebP lossy or lossless?" has a frustrating answer: it depends on how the file was encoded.

For all major formats, see image formats explained.


What Happens When You Re-Compress a Lossy Image?

Lossy compression damage stacks.

If you open a JPEG, edit it, and save it as JPEG again, the encoder runs another lossy pass. It does not know the previous missing data. It compresses the already-compressed image again.

After several saves, you can get:

  • blocky areas
  • color shifts
  • smeared details
  • ringing around text
  • banding in gradients

This is called generation loss. It is why you should keep source files in a lossless or high-quality original format, then export lossy versions only for delivery.

Practical workflow:

  1. Keep the best original you have.
  2. Edit in a lossless or project-native format.
  3. Export JPEG/WebP/AVIF only at the final web delivery step.
  4. Do not use a compressed web image as your future editing source.

If you use an image CDN, upload high-quality originals and let the CDN generate delivery versions. That keeps the destructive step out of your source workflow.


Does Compression Affect Page Speed and SEO?

Yes, indirectly.

Google does not rank a page because the image says "WebP" or "AVIF." But image compression can affect Largest Contentful Paint, total page weight, mobile loading, and user experience. Those things matter.

AreaWhat compression changes
LCPSmaller above-the-fold images usually download faster
BandwidthModern lossy formats reduce transfer size for photos
CLSCompression does not fix layout shift; width and height attributes do
INPHuge images can add decode and rendering work
CrawlabilityExternal optimized image URLs keep HTML cleaner than inline base64 images

One important caveat: smaller is not always faster if decoding becomes the bottleneck. AVIF can save bytes but can also cost more CPU to decode than JPEG or WebP. On most slow networks, the byte savings win. On weaker devices with already-fast networks, you should test real LCP.

For the SEO side, read can image CDNs hurt SEO? and do image CDNs improve LCP?.


How Do Image CDNs Choose Lossy or Lossless?

An image CDN can simplify the whole decision.

The usual flow looks like this:

  1. You upload a high-quality source image.
  2. The browser requests the image and sends an Accept header.
  3. The CDN checks browser support for AVIF, WebP, JPEG, and PNG.
  4. The CDN generates the best derivative for that request.
  5. The derivative is cached at the edge.
  6. Future visitors get the cached optimized file.

For photos, the CDN will usually serve a lossy modern format such as AVIF or WebP. For graphics, it may keep PNG, serve lossless WebP, or preserve transparency depending on provider settings.

You can also do this manually with the <picture> element:

<picture>
  <source srcset="/images/photo.avif" type="image/avif" />
  <source srcset="/images/photo.webp" type="image/webp" />
  <img
    src="/images/photo.jpg"
    alt="Product photo"
    width="1200"
    height="800"
    loading="lazy"
  />
</picture>

That works, but it means generating and storing multiple files yourself. For a few images, fine. For a full site, an image CDN format conversion setup is easier.


Frequently Asked Questions

Is JPEG lossy or lossless?

JPEG is lossy in normal web use. It permanently discards image data during compression. That is why JPEG is small for photos, but it is also why repeated JPEG saves cause visible quality loss.

Is PNG lossy or lossless?

PNG is lossless. It preserves every pixel exactly, which makes it ideal for screenshots, UI images, transparent graphics, and sharp text. It is usually inefficient for large photos. The is PNG lossy or lossless guide explains this in more detail.

Is WebP lossy or lossless?

WebP can be either lossy or lossless. Lossy WebP is used for photos and often beats JPEG on file size. Lossless WebP is used for graphics and can be smaller than PNG while preserving pixels.

Can you convert a lossy image back to lossless?

You can save a JPEG as PNG, but that does not restore lost detail. It only stores the already-degraded pixels in a lossless container. Keep original source files if you need true quality preservation.

Which compression type is better for website images?

Neither is always better. Use lossy compression for photos and complex visuals. Use lossless compression for screenshots, logos, text, transparent graphics, and source files. Most websites should use both.

Does lossy compression hurt SEO?

Not when used properly. Good lossy compression can improve page speed and LCP by reducing image bytes. Over-compression can hurt user experience because images look bad, but the format itself is not an SEO problem.

Should I upload lossless originals to an image CDN?

Yes, when possible. Upload high-quality originals, then let the CDN create lossy or lossless delivery versions. That keeps your source clean and lets the CDN choose the right format for each browser.

Summing Up!

Use lossy compression when a visually close version is good enough. That means photos, product images, hero images, backgrounds, and thumbnails. Use lossless compression when exact pixels matter. That means screenshots, logos, UI images, diagrams, transparency, and editable source files.

The mistake is trying to force one compression type everywhere. A website usually needs both. WebP can handle both modes, AVIF is excellent for compressed photo delivery, JPEG remains the fallback, and PNG still matters for clean graphics.

For manual testing, use the JPEG to WebP converter and PNG to WebP converter. For production, use an image CDN so format and compression decisions happen automatically per image, browser, and device.

Free$5Credit
Live Offer

BunnyCDN · $0.01/GB

CodeTHEWPX
Claim