Design is the combination of ALL these elements, not just a decision about images. The rules for jpegs vs. gifs is a simple rule with complex application. Let's start with gifs. Gifs are images where we get to tell the image how many colors to be. The name of the game is file size.
Images carry weight in the form of bytes.
These bytes equal download time, as the more bytes the image needs to display, the larger the file size. Gifs allow us to remove color from the image that we either aren't using or can live without. By removing colors, we bring down the file size, therefore creating a smaller image that takes less time to download. Generally, images that contain a great deal of flat color can be reduced without too much degradation of image quality, whereas if it was a human face with all of the color shifts that make up the curvature of the cheekbone etc., reducing the amount of colors would degrade the image too much to be acceptable. That's where jpegs come in.