Why does file compression make files smaller?
The short answer
Compression finds repetition and predictable patterns in data, then stores them in shorter forms. A lossless method can reconstruct the original data exactly after decompression.
For example, repeated text
If the same string appears many times, a compressor can store a reference such as “use the earlier string again” instead of copying every character. Other methods assign shorter codes to values that appear more often.
Not every file gets smaller
Already-compressed images and videos, or data that looks nearly random, may contain little repetition to remove. Such files may shrink very little or even become slightly larger because of compression metadata.