GameParticles
Images

Lossy vs Lossless Compression: How They Work and Differ

Lossy vs lossless compression explained: lossless rebuilds the exact original, lossy discards detail for smaller files. See which image formats use each type.

Updated

Lossless compression makes a file smaller without changing its contents: when you open it, you get back exactly what went in. Lossy compression makes a file much smaller by permanently discarding information people are unlikely to notice. PNG, GIF and ZIP are lossless. JPEG, and the usual modes of WebP and AVIF, are lossy.

This guide explains the mechanics. For a practical workflow with recommended settings, see how to compress images without losing quality.

How lossless compression works

Lossless compression finds redundancy and describes it more briefly. Nothing is removed, only rewritten. Three ideas do most of the work.

Repetition. Instead of storing the same thing many times, store it once and refer back to it. A row of 500 white pixels becomes the equivalent of "white, 500 times". Dictionary methods extend this to repeated patterns anywhere in the data.

Frequency. Values that occur often are given short codes and rare values long ones, the same principle as Morse code using a single dot for the letter E.

Prediction. For images, guess each pixel from its neighbors and store only the error. In a smooth area the errors are mostly zero or close to it, which the first two steps then compress very well.

PNG combines all three: a prediction filter on each row, followed by DEFLATE, the same algorithm used in ZIP files. Decoding reverses each step and the original pixels come back bit for bit.

The limit is the data itself. Flat, repetitive content such as screenshots, diagrams and logos compresses well. A photograph is full of sensor noise and fine texture, which is close to random, and random data has no redundancy to remove. Lossless compression of a typical photo often saves only around half.

How lossy compression works

Lossy compression changes the data so that it becomes easier to compress, choosing changes that human senses are poor at detecting. JPEG is the classic example and runs in four stages.

  1. Separate brightness from color. The image is converted from red, green and blue into one brightness channel and two color channels.
  2. Reduce color resolution. Eyes are much more sensitive to detail in brightness than in color, so the color channels are commonly stored at half resolution in each direction. This is called chroma subsampling.
  3. Transform into frequencies. Each block of 8 by 8 pixels is rewritten as a mix of patterns, from smooth gradients to fine checkerboard detail.
  4. Quantize. The amounts of fine-detail patterns are rounded off coarsely, and many become zero. This is where the information is lost, and it is what the quality slider controls.

The rounded result is then compressed losslessly. Because so many values are now zero, it packs down far more than the original pixels could. A photo can typically be reduced to about a tenth of its raw size before the damage becomes noticeable.

WebP and AVIF follow the same outline with newer techniques borrowed from video codecs, which is why they reach the same visual quality in fewer bytes.

Lossy vs lossless side by side

LosslessLossy
Original recoverableYes, exactlyNo
Typical photo sizeLargeSmall
Quality settingNone neededYes
Repeated savingNo effectDamage accumulates
Sharp edges and textPerfectCan show artifacts
Best forGraphics, screenshots, source files, dataPhotos, audio and video for delivery

Which formats are which

FormatTypeNotes
JPEGLossyA lossless variant exists in the standard but is almost never used
PNGLosslessAlways
GIFLossless, with a catchLimited to 256 colors, so converting a photo to GIF loses color first
WebPBothSeparate lossy and lossless modes
AVIFBothUsually used in lossy mode
HEICLossyAs produced by phone cameras
TIFFUsually losslessA container that can hold uncompressed, lossless or JPEG data
BMPUsually uncompressedLarge files with no compression at all
SVGNot applicableVector text, not pixels

The same split exists outside images. MP3 and AAC are lossy audio, FLAC is lossless audio. Common video formats such as H.264 are lossy. ZIP and gzip are lossless, which is why they are safe for documents and code, where a single changed bit would be an error.

What the quality setting means

The quality number in a lossy encoder, usually 1 to 100, controls how coarse the rounding in the quantization step is. Three things are worth knowing.

It is not a percentage. Quality 80 does not mean 80 percent of the information is kept or that the file is 80 percent of the original size. It is a position on a scale that the encoder defines.

It is not comparable across formats or tools. Quality 80 in JPEG, WebP and AVIF give different files and different visual results. Even two JPEG encoders can differ at the same number.

It is not linear. The first steps down from 100 remove a large share of the bytes with almost no visible change. Near the bottom of the scale, each step saves little and costs a lot.

Quality 100 in a lossy format is still lossy. To keep every pixel, use a lossless format.

Generation loss

Every lossy save runs the discard step again. Open a JPEG, make a small edit, save, and repeat: artifacts from each round are treated as real detail by the next, and the image slowly degrades. This is called generation loss.

The rules that follow from it:

  • Keep an original, in a lossless format or straight from the camera.
  • Do all editing on the original and export the lossy version once, at the end.
  • Converting between lossy formats, such as JPG to WebP, is also a new lossy generation. Convert from the original where possible.
  • Saving a lossy image in a lossless format stops further loss but restores nothing.

Choosing between them

Use lossless when the content has hard edges, text or flat color, when the file is a master copy you will edit again, or when exact values matter, as in medical, scientific or pixel art images.

Use lossy when the content is photographic and the file is for delivery: web pages, email, social media. The size difference is large, the visible difference at sensible settings is not. The format-by-format choice is covered in JPEG vs PNG and image file formats.

Seeing the difference yourself

The Image Compressor makes both kinds visible. With JPEG, WebP or AVIF selected as the output, the quality slider is a lossy control, and the before and after preview lets you drag across the image to find the point where artifacts appear. With PNG selected, the output is lossless: the slider then changes only how hard the tool works to shrink the file, and the pixels stay identical.

To move a batch of JPG or PNG files to lossy WebP, the WebP Converter shows the saving per file.

Try it

Drop a photo into the Image Compressor, choose JPEG and pull the quality down to 20 to see what lossy artifacts look like. Bring it back up until they vanish, then switch the format to PNG and compare the file size of the lossless version.

Tools in this guide

Frequently asked questions

Is JPEG lossy or lossless?

Standard JPEG is lossy. It permanently discards fine detail and some color information each time an image is saved, even at quality 100. The amount is controlled by the quality setting, and at high settings the loss is very hard to see.

Is PNG lossy or lossless?

PNG is lossless. Every pixel is restored exactly when the file is opened, however many times it is saved. Some PNG optimizers reduce the number of colors before saving, which is a lossy step applied before the lossless format.

Can you convert a lossy file back to lossless quality?

No. Saving a JPG as a PNG keeps the image exactly as it now looks, artifacts included, but the detail removed by the lossy step no longer exists. Converting to a lossless format only prevents further loss.

Which is better, lossy or lossless compression?

Neither is better in general. Lossless is right for text, data, source files and graphics with sharp edges, where every bit matters. Lossy is right for photos, audio and video delivered to people, where much smaller files matter more.

More images guides

JSON Formatter
Developer · Format, validate and minify JSON with syntax highlighting.
↵
Base64 Encode / Decode
Developer · Encode text to Base64 or decode Base64 back to plain text.
↵
URL Encoder / Decoder
Developer · Encode or decode URL components and query strings.
↵
Hash Generator
Developer · Generate MD5, SHA-1, SHA-256 and SHA-512 hashes.
↵
UUID Generator
Developer · Generate UUIDs v4 (random) in bulk with one click.
↵
Regex Tester
Developer · Test regular expressions against text with live match highlighting.
↵
Word Counter
Text · Count words, characters, sentences, paragraphs and reading time.
↵
Case Converter
Text · Convert text between UPPER, lower, Title, camelCase, snake_case and more.
↵
List Sorter
Text · Sort, reverse, deduplicate and shuffle lists of text.
↵
Markdown Preview
Text · Write Markdown and see a live rendered preview side by side.
↵
Percentage Calculator
Numbers · Calculate percentages, increases, decreases and what % one number is of another.
↵
Color Converter
Colors · Convert colors between HEX, RGB, HSL and HSV instantly.
↵
Snake
Arcade · Eat food, grow longer, don't hit the walls. A timeless classic.
↵
2048
Puzzle · Slide tiles and combine them to reach the legendary 2048 tile.
↵
Word Grid
Puzzle · Guess the hidden five letter word in six tries using color clues.
↵
Sudoku
Puzzle · Fill the 9x9 grid with logic. Four difficulties from easy to expert.
↵
Minesweeper
Strategy · Use number clues to clear the minefield. Classic logic, three levels.
↵
Breakout
Arcade · Smash every brick with paddle and ball. Power-ups, combos, endless levels.
↵
Typing Practice
Casual · Build your WPM and accuracy with timed drills from 30 seconds to 5 minutes. Find your weak keys.
↵
TypeRunner
Arcade · Multiplayer typing race. Race friends by link, beat computer runners, or chase your own ghost.
↵
Typing Blocks
Arcade · Type each word before its wooden block lands. Miss, and the pile climbs toward the line.
↵
Bubble Shooter
Arcade · Aim, bank shots off the walls, and pop groups of three or more bubbles.
↵
Road Rush
Arcade · Race seven rivals through traffic and punch your way to the front.
↵