Short answer: Lens hoods shade the front of your lens reducing unwanted lens flare.
Lens flare is caused by bright light hitting your lens. This creates artefacts in the image, such as the ring of speckled light in the above image, and glare across an image. Glare creates a washed out look with low-contrast.
In the above image the lens flare in the centre of the image mirrors the shape of the aperture.
What Does a Lens Hood Do?
The main purpose of a lens hood is to shade the front of your lens to reduce the chance of unwanted lens flare. For example, on a sunny day if you take a photo towards the direct of the sun but not at the sun, then the bright light still hit the front of your lens and cause lens flare. If you are using a lens hood, however, then lens flare should be prevented in this situation.
The same is true if you were taking a photo at night in the direct of a spotlight but not directly at the spotlight. A lens hood would also help you out there.
Protecting The Lens
Lens hoods also physically protect your camera lens by creating a barrier between the front the lens and the rest of the world. If you bump your camera against a wall or put it down heavily, the lens hood is going to stop the front element of the lens making direct contact with a hard surface. For this reason, most photographers will leave their lens hoods on all of the time.
Why Do Lens Hoods Come in Different Shapes and Sizes?
The lens hood is designed for the particular lens you use it with. When you bought your lens it may have come with the hood, or when you look to purchase one you will noticed that the hood is made for a particular lens or range of lenses.
The petal shape lens hood is used on wide angle lenses and zoom lenses. Essentially, sections have been taken out of a straight tube so that the lens hood does not get in a wide angle shoot. This won’t be as effective as a closed tubular lens hood, but the priority is to shade the lens without getting the hood in the shot.
A long prime lens and telephoto lenses are more likely to have a tube shape lens because this is more effective at providing shade. As long as the focal length is long enough then the hood won’t get into the shot so the petal shape is not required.
Check out this comprehensive video from SteeleTraining on YouTube: