How compression works
Compression finds what's predictable in data and writes it down more briefly. Lossless methods give back every byte; lossy ones, used for photos, sound and video, throw away what you won't notice. Type below or pick a sample: each method runs on it now, in your browser.
LZ77 walks through the text and, whenever the next few characters already appeared, writes "go back d, copy l" instead. Highlighted characters below are copies; plain ones are written out. Hover a highlight to see its instruction.
A good compressor's output looks random, and random data has nothing left to predict. Compress the result again and it gets slightly bigger, because the container adds a header and bookkeeping. There are more possible files of n bytes than of n − 1 bytes, so no method can shrink every input; some must grow.
No. Lossless compression (ZIP, PNG, FLAC) perfectly preserves all data. Lossy compression (JPEG, MP3, H.264) permanently removes some data to achieve higher compression ratios.
It varies hugely. Text files can compress to 10% of original size. Already-compressed files (JPEGs, MP3s) may only reduce by 1-5%.
Lossless compression does not affect quality. Lossy compression reduces quality, but modern algorithms make the loss nearly imperceptible at reasonable settings.
For documents: ZIP or 7Z. For images: WebP or AVIF. For audio: AAC or OGG. For video: H.264 or H.265.
JPEG, MP3, MP4, and ZIP files are already compressed. Trying to compress them again yields little benefit.