Data compression is a reduction in the number of bits needed to represent data. We can save storage, decrease the cost for storage hardware, and speed up the file transfer all by compressing data.
Imagine that you have a file of 150Mb. We could shrink it down to 30Mb, but we have to compress it with a compression ratio of 5. Likewise, If we have compressed 16Mb to 4Mb, it would have a compression ratio of 4 because the new compressed file is a 4th of the size of the original file. The higher the compression ratio, the more compression there is.
Lossy compression reduces the file size by removing unnecessary bits of information. It is generally used on images, audio files, and videos, in which perfect representation of media is not necessary.
Lossless compression allows the file to regain its original position without losing a single bit of information when the file is uncompressed. Lossless compression is used to compress data files (such as Numerical data, Executable code, Text files) because programs that process such data files cannot accept mistakes in the data.