A lens hood is a lens accessory which helps block out unwanted light from “landing” on the glass of your lens.
When unwanted light lands on the glass you will often see a colored hexagon or octagon shaped “flare.”
Lens flare is most often caused by light, such as the sun, hitting the lens directly. Light, or sun, coming from a side angle will rarely have the same affect.
The lens hood helps prevent lens flare by blocking as much light as possible from hitting the lens glass, depending on how extreme your angle to the sun, or light, is.
There are photographers who choose to keep a lens hood on the lens most of the time. The reasoning is that it helps protect the glass and the end of the lens from accidental damage.