← All articles

How to Compress PNG Files Without Losing Quality

PNG files are honest — what you put in is exactly what comes out. That honesty comes with a cost: PNG files are large, sometimes embarrassingly so. A 3MB screenshot that could be 400KB is not serving anyone.

The good news is you can compress PNG files dramatically without touching visible quality. The methods range from a two-click online tool to build pipeline automation. This guide covers all of them, with actual numbers so you know what to expect before you start.

Why PNG Files Are So Large

PNG uses lossless compression, which means every pixel is preserved exactly. The format applies the DEFLATE algorithm (same one ZIP uses) to pixel data, but DEFLATE alone can only do so much with photographic images that have thousands of unique colors.

Three factors drive PNG file size:

This is why PNG makes sense for logos, screenshots, and illustrations, but not for photographs. For photos, see the format comparison guide — JPEG or WebP will serve you better.

PNG Compression Methods Compared

Two fundamentally different approaches exist, and confusing them leads to bad results:

Lossless recompression strips metadata and re-encodes using more aggressive DEFLATE settings. Zero quality change. Typical savings: 10–30%.

Lossy quantization reduces the color palette (usually from 32-bit to 8-bit) before DEFLATE runs. Visible quality is usually preserved at 90%+ quality settings, but pixel values change. Typical savings: 40–70%.

Method Tool Speed Compression Quality Loss Best For
Lossless recompression OptiPNG, oxipng Slow 10–30% None Icons, logos, screenshots
Lossy quantization pngquant, Pixotter Fast 40–70% Minimal at high quality Photos, complex images
Format conversion WebP, AVIF Fast 60–85% Minimal Web images where format choice is open

The right method depends on whether you can accept any pixel-level change. For web assets where no one is comparing pixels with a magnifier, lossy quantization is almost always the right call.

Method 1: Compress PNG Online (Fastest)

Pixotter's compression tool handles PNG compression in-browser — no upload, no server round-trip. Your images never leave your machine.

  1. Go to pixotter.com/compress
  2. Drop your PNG files (single file or batch)
  3. Adjust the quality slider — start at 80, go lower until you see visible degradation
  4. Download the compressed files

The quality slider controls the lossy quantization level. At 80, most PNG files lose 50–65% of their size with no visible difference in a browser. At 60, you push toward 70% savings with minor color banding in gradients that most users will never notice.

Batch compression works the same way — drop 20 files and download them all at once. For a target file size like "compress to 100KB," check the compress to target size guide.

Method 2: Command Line Tools

Three tools cover the full range of CLI PNG compression.

pngquant (v3.0) — Lossy, Fastest

pngquant reduces color depth from 32-bit to 8-bit using a perceptual quantization algorithm. It's the fastest option and produces the biggest savings.

# Install (macOS)
brew install pngquant

# Install (Linux)
sudo apt install pngquant

# Compress a single file (quality range 65-80)
pngquant --quality=65-80 --output compressed.png input.png

# Compress in place (replaces original)
pngquant --quality=65-80 --ext .png --force input.png

# Batch compress all PNGs in a directory
pngquant --quality=65-80 --ext .png --force *.png

The --quality range (e.g., 65-80) tells pngquant to try for 80 quality and accept as low as 65 if it cannot hit 80 within that palette. Images where it cannot meet the minimum quality threshold are skipped — check exit codes in scripts.

OptiPNG (v0.7.8) — Lossless, Thorough

OptiPNG tries multiple DEFLATE compression levels and keeps the smallest result. Slow, but zero quality change.

# Install (macOS)
brew install optipng

# Install (Linux)
sudo apt install optipng

# Compress with optimization level 4 (good balance of speed vs savings)
optipng -o4 input.png

# Maximum compression (slow — use for production assets you compress once)
optipng -o7 input.png

# Batch compress
optipng -o4 *.png

Optimization levels run from 0 (fastest, least savings) to 7 (slowest, most savings). Level 4 is the practical default. Level 7 takes 5–10x longer for 2–5% extra savings — worth it for assets you compress once and serve forever.

oxipng (v9.1.1) — Lossless, Fast

oxipng is the modern Rust-based alternative to OptiPNG. Multithreaded, significantly faster, comparable or better compression.

# Install via cargo
cargo install oxipng --version 9.1.1

# Install via Homebrew (macOS)
brew install oxipng

# Compress with default settings
oxipng input.png

# Aggressive compression with metadata stripping
oxipng --opt 4 --strip all input.png

# Batch compress recursively
oxipng --opt 4 --strip all --recursive ./images/

The --strip all flag removes all metadata (Exif, ICC profiles, text chunks). This alone can remove 50–300KB from files that carry embedded profiles. Safe for web use — browsers don't need embedded color profiles when serving sRGB content.

Method 3: Build Pipeline Integration

For automated workflows, Sharp handles PNG compression in Node.js.

npm install [email protected]
const sharp = require('sharp');
const path = require('path');

async function compressPNG(inputPath, outputPath, quality = 80) {
  await sharp(inputPath)
    .png({
      quality,           // Lossy: reduces to 8-bit palette
      compressionLevel: 9, // DEFLATE level (0–9)
      adaptiveFiltering: true,
    })
    .toFile(outputPath);
}

// Usage
compressPNG('input.png', 'output.png', 80);

Sharp's PNG quality option (0–100) maps to pngquant's quantization. compressionLevel: 9 sets DEFLATE to maximum — it's CPU-bound but images are compressed once, not repeatedly.

For a full discussion of image size reduction strategies in production pipelines, see how to reduce image size effectively.

Lossless vs Lossy PNG Compression

Choose based on how the image will be used:

Use lossless (OptiPNG / oxipng) when:

Use lossy (pngquant / Pixotter) when:

A practical rule: if a stakeholder would complain about seeing a color change, use lossless. If they'd only notice the page loaded faster, use lossy.

How Much Can You Compress a PNG?

Compression ratios vary significantly by image type. These are real-world representative numbers:

Image Type Original Size After Lossless After Lossy (q=80) Best Savings
Screenshot (UI) 1.2 MB 820 KB (32%) 480 KB (60%) 60%
Logo / icon 80 KB 62 KB (23%) 28 KB (65%) 65%
Product photo (PNG) 3.8 MB 3.1 MB (18%) 1.1 MB (71%) 71%
Illustration (flat colors) 240 KB 180 KB (25%) 95 KB (60%) 60%
Photo with transparency 2.4 MB 2.0 MB (17%) 820 KB (66%) 66%

Product photos as PNG are the worst-case scenario — use WebP or JPEG instead. But if you're stuck with PNG (transparency requirement, workflow constraints), lossy quantization still delivers meaningful savings.

When to Convert Instead of Compress

If you're compressing a PNG for web delivery and you can accept lossy compression, converting to WebP or AVIF gives better results than lossy PNG quantization.

Output Format Typical Size vs Original PNG Transparency Browser Support
Lossy PNG (q=80) 35–50% of original Yes 100%
WebP (q=80) 20–35% of original Yes 97%
AVIF (q=80) 15–25% of original Yes 94%

WebP and AVIF both support transparency (alpha channel), so they're direct PNG replacements for web use. The only scenario where compressed PNG beats them is when you need 100% browser compatibility or the image goes into a context that doesn't support WebP (some email clients, older PDF tools, certain CMS pipelines).

For a detailed format comparison: PNG vs WebP covers the tradeoffs, and best image format for web covers when to use each format in a full project.

Frequently Asked Questions

Does compressing PNG reduce quality?

Lossless PNG compression (OptiPNG, oxipng) does not change any pixel — quality is mathematically identical. Lossy PNG compression (pngquant, Pixotter) reduces the color palette and does change pixel values, but at quality settings of 70 and above, the difference is not visible in a browser. The output is still a valid PNG file.

What is the best PNG compression level?

For lossless tools, OptiPNG -o4 and oxipng --opt 4 are the practical defaults — good compression in reasonable time. For lossy tools, start at quality 80 and reduce until you see degradation. Most images hold up well at 70–80. Drop below 60 only when file size requirements are strict and the image is viewed at small sizes.

Can I compress PNG to a specific file size?

pngquant doesn't target a specific file size directly, but you can binary-search quality settings to hit a target. Pixotter's online tool shows the output file size in real time as you adjust the quality slider. For a full walkthrough of compressing to a target size, see compress image to 100KB.

Is WebP better than compressed PNG?

For web delivery: yes, WebP is smaller at equivalent visual quality and supports transparency. A WebP at quality 80 is typically 30–50% smaller than a lossy PNG at the same quality setting. The only reason to prefer compressed PNG over WebP is compatibility — if your target environment doesn't support WebP. For modern browsers (Chrome, Firefox, Safari, Edge since 2020), WebP is the better choice.

How do I compress PNG files in bulk?

All three methods support batch processing. Pixotter accepts multiple files in one drop. pngquant and oxipng both accept glob patterns (*.png) and recursive directory flags. For build pipelines, Sharp processes files in parallel with Promise.all() across a directory listing. The CLI tools are fastest for one-time batch jobs; build pipeline integration is better for automated workflows where images are compressed as part of a deploy.