Your camera understands black and white and all the shades of grey between them (the tonal range). The histogram is a graph that interprets the tonal distribution in your pictures. Every DSLR today provides histograms in their LCD preview mode. So a histogram is a graphical representation of the pixels exposed. The left side of the graph represents the blacks or shadows, the right side represents the highlights or bright areas, and the middle section represnts the mid-tones (18% grey).
How high the peaks reach the top represent the number of pixels in that particular tone. Each tone from 0-255 (0 being black and 255 being white) is one pixel wide on the graph, so imagine the histogram as a bar graph all squished together with no spaces between each bar.
A histogram for a well exposed image will look like a hill going evenly from left to right with its peak's in the middle i.e. without spaces on the sides of the graph, and isn’t going up one side or the other. In an ideal world, it should just touch the left and right edges, and not spill up the sides, with a nice arch up in the center.
Having a dark subject in the picture will have a histogram shifted to the left. It doesn't mean that this is wrong. This might be a black car on the dark street. But when your graph is shifted too far in one direction or the other so that it does not even touch the other edge or it fills one edge completely – that means you can safely shift your exposure to cover more of the tonal range.
The graph to the rightt shows an overexposed image, notice the gap on the left side indicating a lack of any blacks represented. It also means you will lose lots of detail in the white areas that may not be recoverable (white tones are flat i.e. no details in them). In this case shift your exposure needle left to give your image less exposure and shoot the scene again.
The opposite is also true. A gap on the right side of the histogram indicates that there are no whites represented. The image is too dark or underexposed. You should consider more exposure until you see the histogram just touch the right edge of the graph.
After you press that shutter, review your picture on site to see if you have spikes in your histogram. Spikes up the left or right edge indicate “clipping” of that tone, and loss of detail in that area. Clipped areas are often unrecoverable, especially in the highlight area (whites are washed out) but it is generally advised to expose so you your graph just touches the right edge and keep your highlight details. It is usually easier to recover some shadow detail and retain a decent image, than to create highlight details that aren't there on the file.
In some cases it may not be possible to keep the graph within an acceptable range. If you are photographing a scene with extreme contrasts such as a sunset.
Most cameras today have a setting called “highlight warning”. It will make any overexposed highlights “flash” or blink when you preview your images on your LCD. Many people call this, “the blinkies”. Check your camera’s manual to wee where to activate it.
Histograms are very much usefull when and if you post-process your images like me. I always shoot in RAW and use Lightroom to post-process. Keep in mind that if you shoot in JPG, having a right exposure out of the camera nailing is even more crucial. But if you are like me and you shoot RAW, you have some leeway to make adjustments later, but it’s still a better idea to get it right in the first place. When it comes to creativity however, there is no right or wrong to the above. It’s how you want your subject to be interpreted that matters. Sometimes the best pictures have no mid-tones in their histogram.