Image compression uses four stages to reduce file sizes: 1) transforming RGB pixels to the YCbCr color space, 2) applying discrete cosine transformation to concentrate pixel data into a few matrix elements, 3) quantizing pixel values to reduce their range, and 4) using Huffman coding to assign shorter bit codes to more common pixel values. This allows JPEG images to be compressed to smaller file sizes for storage and transmission while still maintaining good visual quality.