JPEGs are originally designed to compress full-color or gray-scale images of natural, real world scenes.
JPEGs also use lossy compression algorithm.
The way that lossy compression algorithm works for JPEGs is that when you create a JPEG or convert an image of another format to JPEG, it asks you what quality you would like for the image.
The highest quality results in the largest file so there is a trade off you need to make between image quality and file size. The lower the quality, the greater the compression, and the greater the degree of information loss.
Essentially, JPEG compression is treated as 24 bit data and 8 bit data for grayscale regardless of colors in the image. That being said, if one does compress a 24 bit to an 8 bit, the JPEG understandably loses quality. One should also keep in mind that JPEG compression involves bringing noise into solid color areas which can blur images.
You can find more information about this here:
The lossy compression works in the following way. It’s also shown here:
This is a visual for the answer that can help make more sense:
These are the source links I used for this answer: