Now, why and how is it important in the context of photography ??
Histogram of a typical underexposed frame (or a rightly exposed frame which has a lot of complete dark and shadow regions and absolutely no highlight).
Histogram of a rightly exposed frame. Neither too many pixels of complete dark nor any burnt out highlight. There might be a small dark region in the image as the distribution has a non-zero value at the left end but surely no highlight.
Histogram of a typical overexposed frame (or a rightly exposed frame which has a lot of pure white regions and no dark or shadow regions).
Many a times when the situation is not typical, rather a bit tricky, we do not see single peaked or center-peaked histograms. E.g. for a landscapes with bright sky and some shadow regions, the histogram would show two peaks (there might be some additional peaks too in between) at the left and right for the shadow regions and the bright sky respectively. As long as those peaks do not touch the ends we should not worry. But what if they touch the ends ? The image will have shadow regions as complete black without any detail and the sky will be blown out white showing no detail.... you do not like this type of an image, me too. We can't do here much in a direct manner - if one underexposes to get the details of the sky, the shadow region will be darker and if one wants to take care of the shadow regions by overexposing it a bit, the highlights will get worse. It's a limitation of the recording medium, termed as 'narrow dynamic range'. One needs to manipulate the image either in time of printing (for analog recording) or post-processing (for digital recording). The most important thing to remember here is that one can recover the details of the shadow regions by different manipulation methods but it's not possible to extract the details from the blown out regions. So the thumb rule to tackle these situations is "expose for the highlights" and then use some manipulation technique to get the details back in the shadow regions.
To summarize :
- The histogram is a handy graph that alerts you to the two extreme cases of underexposure and overexposure in your pictures.
- When the histogram touches the left end, you lose details in the shadows and when the histogram touches the right hand - it conveys blown highlights - you lose details in the highlights.
- There is no good or bad histogram, per se. As long as the histogram does not have peaks that touch the left or the right end, you are safe - the image will not have any underexposed or overexposed region.
- When the tails of the histogram extends to the ends, it ensures that the image has the complete available tonal variation - as desired often.