There are two kinds of file compression: Lossy (referring to quality) and lossless compression.
Using lossless compression, the computer uses formulas to describe data more effectively, i.e. instead of writing repetitive information when describing a colour area in a picture (“white white white white white white white white white white”) “10 x white” is used. This way no information or quality is lost, the computer just has to do more calculation work when displaying the picture.
This method of compression is very effective in pictures with flat/solid colours or other files with repetitive information (like a political map or a comic).
Examples of lossless compression are LZW and ZIP compression (used in Photoshop, Acrobat etc.).
Lossy compression uses downsampling to reduce the amount of information in a picture. Pixels are grouped and replaced by larger blocks of colour. When saving the picture, the amount of compression and therefore quality loss can be adjusted. This compression is very efficient on photographs and pictures with tonal variations. JPEG is the most popular file type for this type of compression. For music files a similar method is used to save MPEG files. It is important to remember that each time a file is saved using jpeg (lossy) compression, some information is lost and quality reduced.
The two butterflies are saved as jpeg files, the file on the left was saved with medium quality, the file on the right was saved with maximum quality. On closer look the loss of detail on the left becomes obvious, as do patterns and artifacts in the background.