Camera lenses can be sensitive to light sources that are placed just outside the frame. Light coming from certain angles can generate flaring and ghosting on pictures.
A lens hood is a device that attaches to the front of the lens and “shades” it from those light sources and their undesirable effects. Hoods can be purchased for almost any lens diameter.
Hoods come either bowl-shaped, like an expanding tube, or petal-shaped. Petal-shaped lens hoods are generally lighter.
Many higher quality lenses come with a hood at purchase. Some companies offer them as accessories on all lenses. They can also be purchased from third-party manufacturers. A hood provided with a lens can usually be reversed to fit backwards on the lens when not in use.
Rubber and metal lens hoods
Rubber hoods are useful because they collapse for storage. They can be collapsed while on a lens when the hood itself is not needed.
Metal hoods are sturdier but heavier. They may provide some protection if the lens is bumped or dropped.
One caveat is that lens hoods make polarizing filters more difficult to operate.Table Bay yacht by Damien du Toit used under the Creative Commons license