That is what a "lossy compression" means. Instead of encoding the original image, you look for a similar image, that can be losslessly encoded into a smaller file.
In PNG, you look for an image with 100 - 200 colors (so that colors repeat more often) and losslessly encode it with DEFLATE.
In JPG, you look for an image with with a reduced description through DCT, and losslessly encode it with Huffmann trees.