All articles
Guides8 min18 October 2026

How Does File Compression Work? A Simple Explanation

File compression makes files smaller by describing the same information in fewer bytes. Some compression only rewrites the data more efficiently and gives back an exact copy (**lossless**); some also throws away detail you won't notice (**lossy**). This guide explains, in plain language, how compression algorithms work, why some files shrink a lot and others barely at all, and what actually happens when you compress a JPEG, a PNG or a PDF.

The basic idea: say the same thing with less

Computers store everything as numbers, and most files contain a lot of repetition. Compression looks for that repetition and replaces it with something shorter.

Imagine the text "AAAAAABBBCCCCCCCC". Instead of storing 17 letters, you could write "6A3B8C" — six characters that mean the same thing. That simple trick is called run-length encoding, and it's one of the oldest compression methods. Real compressors use smarter versions of the same idea.

How lossless compression algorithms work

Most lossless compressors, including the DEFLATE algorithm behind ZIP, gzip and PNG, combine two techniques.

1. Finding repeated sequences (LZ77). As the compressor reads the file, it remembers what it has already seen. When a sequence repeats — a word, a line of code, a row of pixels — it writes a short reference such as "copy 12 bytes from 300 bytes back" instead of the bytes themselves.

2. Giving common symbols shorter codes (Huffman coding). Normally every character takes 8 bits. Huffman coding gives frequent symbols shorter codes and rare symbols longer ones, like Morse code giving "E" a single dot. On average the file takes fewer bits.

Newer compressors such as 7-Zip's LZMA, Zstandard and Brotli use the same principles with larger memory windows and better modelling, which is why they usually beat ZIP. Decompression simply follows the instructions in reverse and rebuilds the original exactly.

How lossy compression works

Lossy compression adds one more step before the lossless part: it removes information people are unlikely to notice.

A JPEG encoder splits a photo into 8×8-pixel blocks, converts each block into a set of patterns from smooth to fine detail, and then rounds off the fine detail that eyes barely register. It also stores colour at lower resolution than brightness, because we notice brightness changes more. The quality setting controls how aggressive the rounding is. What remains is then packed losslessly.

Audio formats like MP3 drop sounds that are masked by louder ones, and video codecs store only what changes between frames. The result is files 5–20 times smaller — but the removed detail can't be recovered. Read lossless vs lossy compression for when to use each.

Why some files compress well and others don't

Compression works by removing redundancy, so the result depends on how much redundancy there is.

Compress well: plain text, CSV files, code, uncompressed images (BMP, TIFF), screenshots with large flat areas, and PDFs with high-resolution embedded images.

Barely compress: JPEG photos, MP4 videos, MP3 audio and ZIP files. These are already compressed, so there's little repetition left to find. That's why zipping a folder of photos saves almost nothing — and why making a JPEG smaller means re-encoding it with lossy compression rather than zipping it.

What happens when you compress an image or a PDF

JPEG: the photo is re-encoded at a chosen quality (MiniFiles uses 80% by default), which usually cuts the size by 50–80% with no visible change. Try it with the JPEG compressor.

PNG: the image is rebuilt with a smaller colour palette and then packed with lossless DEFLATE. Screenshots and logos shrink a lot; photos saved as PNG less so. See Compress PNG.

GIF: each frame is optimised and the colour palette reduced while keeping the animation — see Compress GIF.

PDF: a PDF is a container of text, fonts, vector drawings and images. Text and vectors are already compact; the weight is almost always in the images. A PDF compressor such as MiniFiles' Compress PDF resamples those images to a lower resolution (150 DPI on the free Balanced preset) and recompresses them, while text stays perfectly sharp.

Compression ratio: how much smaller will my file get?

The compression ratio compares the original size with the compressed size: a 10 MB file compressed to 2 MB has a 5:1 ratio, or an 80% reduction. Typical results:

  • Text and CSV files zipped: 60–90% smaller.
  • JPEG photos re-encoded at 80%: 50–80% smaller.
  • PNG screenshots with palette reduction: 50–80% smaller.
  • Scanned PDFs: 70–90% smaller.
  • PDFs that are mostly text: 0–30% smaller.
  • Already-compressed files zipped: 0–5% smaller.

Is it safe to compress files?

Lossless compression is completely safe for your data: you always get the original back. Lossy compression is safe as long as you keep the original when full quality matters.

The bigger risk is where you compress. Most online compressors upload your file to their servers. MiniFiles runs the compression engines inside your browser, so images and PDFs are compressed on your own device and never uploaded. More detail in what does compressing a file actually do.

Key takeaways

  • File compression makes files smaller by describing repeated information in fewer bytes; lossless compression rebuilds the original exactly, lossy compression also removes detail.
  • DEFLATE, used by ZIP, gzip and PNG, combines LZ77 (references to repeated sequences) with Huffman coding (shorter codes for frequent symbols).
  • JPEG compression splits images into 8×8 blocks, rounds off fine detail and stores colour at lower resolution than brightness.
  • Already-compressed files such as JPEG, MP4, MP3 and ZIP barely shrink when zipped.
  • MiniFiles compresses JPEG, PNG, GIF, WebP and PDF files in the browser without uploading them; PDF compression resamples embedded images while keeping text sharp.

Frequently asked questions

How does file compression work in simple terms?

It finds repetition in a file and describes it in fewer bytes — for example writing "500 × white" instead of 500 identical pixels. Lossy compression also removes detail people are unlikely to notice.

How do compression algorithms work?

Lossless algorithms like DEFLATE (used by ZIP and PNG) replace repeated sequences with short references and give frequent symbols shorter codes. Lossy algorithms like JPEG first round off fine detail, then pack the result losslessly.

Why don't JPEGs get smaller when I zip them?

JPEGs are already compressed, so there's almost no repetition left for ZIP to remove. To make a JPEG smaller, re-encode it at a lower quality with an image compressor.

Does compression reduce file quality?

Lossless compression never does. Lossy compression removes some detail, but at sensible settings the difference is usually invisible.

What is a good compression ratio?

It depends on the content: text often shrinks by 60–90%, photos re-encoded at 80% by 50–80%, while already-compressed files barely shrink at all.

Try it now — free

Compress PNG, JPEG, and PDF files in your browser. No upload, no installation.

Compress files