However, general rules tend to break down rather quickly on the web. Every choice involves a trade-off of some sort. This brief article is just a basic introduction to choosing the best format for website images. For a really great, in-depth, book on this subject check out the link at the bottom of this article. The important concept here is to understand the basic differences between the two major formats and how they affect your images.
Compression is achieved by selectively removing parts of the image.
A photographic image can be subjected to a very high degree of compression without noticable degradation. GIF compression is based on mathmatically describing the horizontal color runs in the image. Again, there are trade-offs. Horizontal color runs compress very well, vertical bands are no where near as efficient. The images below demonstrate some of the differences.