Image

How to Compress Images for the Web Without Losing Quality

March 10, 20266 min readNebulaTool

Large images are the single biggest contributor to slow page loads on the web. The median webpage now ships over 1 MB of image data, and most of that weight can be cut in half, or more, through proper image compression. This guide covers the practical techniques that reduce file sizes while keeping visual quality indistinguishable from the original.

Lossy vs. Lossless Compression

Image compression falls into two categories, and choosing the right one depends on what you are optimizing for.

Lossless compression reduces file size without discarding any pixel data. The decompressed output is identical to the original, bit for bit. This is ideal for screenshots, technical diagrams, and any image where precision matters. PNG and WebP (lossless mode) both support this approach. Typical savings range from 10% to 40%.

Lossy compression achieves much larger reductions by permanently removing data that the human eye is unlikely to notice. JPEG and WebP (lossy mode) use this technique. At the right quality settings, a lossy-compressed photo can be 70% to 90% smaller than the original with no visible difference on screen. The trade-off is that re-compressing a lossy file degrades quality further each time, so always compress from the original source file.

For most web use cases, lossy compression is the better choice for photographs and complex images. Lossless compression is the better choice for graphics with sharp edges, text overlays, or transparency.

JPEG vs. PNG vs. WebP: Choosing the Right Format

Each format has a specific strength. Picking the wrong one can double your file size for no benefit.

FormatBest ForTransparencyTypical Size (1200px photo)
JPEGPhotographs, gradientsNo80 - 150 KB
PNGScreenshots, logos, text overlaysYes300 - 800 KB
WebPBoth photos and graphicsYes50 - 120 KB

JPEG remains the default for photographs. It handles continuous tones and gradients well but does not support transparency. Avoid JPEG for images with text or sharp geometric shapes, as compression artifacts become visible around hard edges.

PNG is the right choice when you need transparency or pixel-perfect reproduction. It excels at flat-color graphics, icons, and screenshots. The downside is large file sizes for photographic content because PNG uses lossless compression only.

WebP, developed by Google, supports both lossy and lossless compression with transparency. It consistently produces smaller files than JPEG and PNG at equivalent quality. Browser support now covers over 97% of users globally. Unless you need to support very old browsers, WebP should be your default format for new projects.

Quality Settings: Finding the Sweet Spot

The quality slider in any compression tool controls the trade-off between file size and visual fidelity. Here is a practical reference for JPEG and WebP lossy compression:

  • Quality 90 - 100: Virtually no visible loss. File size reduction of only 10 - 20%. Rarely worth it for web delivery.
  • Quality 75 - 85: The optimal range for most web images. File size drops 60 - 75% compared to the uncompressed original. Differences are imperceptible at normal viewing distances.
  • Quality 50 - 70: Noticeable softening begins, especially in areas of fine detail. Acceptable for thumbnails and background images.
  • Quality below 50: Visible artifacts. Only suitable for placeholder images or heavily blurred backgrounds.

A concrete example demonstrates the impact. A 1920x1080 photograph exported from a camera at full quality:

Quality SettingFile SizeReduction
Original PNG3.2 MBBaseline
JPEG at 100820 KB75% smaller
JPEG at 80210 KB93% smaller
WebP at 80165 KB95% smaller
WebP at 6098 KB97% smaller

The difference between JPEG at 100 and JPEG at 80 is almost never visible to the human eye, yet the file is nearly four times smaller. Start at quality 80 and only increase if you spot artifacts in areas that matter.

Batch Compression for Real Projects

Compressing images one at a time does not scale. Most websites have dozens or hundreds of images, and every new upload needs consistent optimization.

For individual files or small batches, the NebulaTool Image Compressor handles compression directly in your browser. Drop multiple images at once, adjust quality per format, and download the optimized results without uploading anything to a server.

For automated pipelines, consider these approaches:

  • Build tools. Vite, Webpack, and Next.js all have image optimization plugins that compress assets at build time. This ensures every deployed image is optimized without manual intervention.
  • CDN-level optimization. Services like Cloudflare Images and Imgix compress and resize on the fly based on the requesting device. This offloads the work entirely from your build process.
  • CI/CD checks. Add a step to your deployment pipeline that flags images above a size threshold. This catches unoptimized uploads before they reach production.

The key principle: automate compression so it happens by default, not as an afterthought.

How Image Size Affects Core Web Vitals

Google uses Core Web Vitals as a ranking signal, and image optimization directly impacts two of the three metrics.

Largest Contentful Paint (LCP) measures how quickly the largest visible element loads. On most pages, that element is an image. An unoptimized hero image of 2 MB can push LCP well beyond the 2.5-second threshold that Google considers "good." Compressing that same image to 200 KB, combined with proper lazy loading and responsive srcset attributes, can cut LCP by several seconds.

Cumulative Layout Shift (CLS) measures unexpected layout movement. Images without explicit width and height attributes cause the page to reflow as they load. This is not strictly a compression issue, but it is worth noting because image optimization and proper HTML attributes go hand in hand.

According to the Google PageSpeed Insights documentation, serving properly compressed images is one of the highest-impact optimizations available. Every 100 KB saved translates to measurable improvements in load time, especially on mobile connections.

When to Use Which Format: A Decision Framework

Use this as a quick reference when exporting images for the web:

  1. Photograph or complex image with no transparency needed: Use WebP lossy at quality 75 to 80. Fall back to JPEG at quality 80 if you need broader compatibility.
  2. Logo, icon, or graphic with transparency: Use WebP lossless. Fall back to PNG if WebP is not an option.
  3. Screenshot or diagram with text: Use PNG for pixel-perfect clarity, or WebP lossless for smaller file sizes.
  4. Thumbnail or preview image: Use WebP lossy at quality 60 to 70. The smaller dimensions hide most compression artifacts.
  5. Hero or banner image: Use WebP lossy at quality 80 to 85. This is the image most likely to affect LCP, so balance quality and file size carefully.

For any format, always resize images to the actual display dimensions before compressing. Serving a 4000px image that displays at 800px wastes bandwidth regardless of how well it is compressed.

Frequently Asked Questions

Does compressing an image always reduce quality?

Not necessarily. Lossless compression reduces file size without any quality loss. Lossy compression does discard data, but at quality settings above 75, the difference is invisible to most viewers on standard displays.

How much smaller can images get with compression?

Photographic images typically shrink by 60% to 90% with lossy compression at quality 75 to 85. PNG graphics with flat colors can drop 20% to 50% with lossless optimization through tools that remove unnecessary metadata and optimize encoding.

Should all images on a website be converted to WebP?

WebP is the best general-purpose format for web delivery today, but it is not universally required. If your existing JPEG and PNG images are already well-optimized and your site performance is within acceptable limits, converting everything may not be worth the effort. For new projects, default to WebP.

Does image compression affect SEO?

Indirectly, yes. Faster page loads improve Core Web Vitals scores, which Google uses as a ranking signal. Compressed images also reduce server bandwidth costs and improve the experience for users on slow connections, both of which contribute to lower bounce rates.

What is the difference between resizing and compressing an image?

Resizing changes the pixel dimensions of an image (for example, scaling from 4000x3000 to 1200x900). Compressing reduces the file size by encoding the same pixel data more efficiently or by discarding imperceptible detail. Both techniques reduce file size, and combining them yields the best results.


Compress your images directly in the browser with the NebulaTool Image Compressor, with no uploads, no signups, and full control over quality settings.

Related Articles


Ready to try it yourself?

Open Image Compressor