Headspace is the distance from the head of the cartridge to the face of the bolt. If there is not enough room, the gun won't function. The bolt won't close, or (in the case of a revolver) the cylinder won't turn all the way. This is "too little headspace".
When the cartridge is fired, before the bullet starts to move (remember the law of inertia - whatever is at rest tends to stay at rest, and the more mass it has, the harder it is to put into motion) the lighter brass case first expands out until it hits the chamber wall, and then it is slammed backwards until it hits the bolt (or, in the case of a revolver, the recoil shield). Once it has done that, the case can't move anymore, and the only thing that can move is the bullet, so it, finally, starts to move forward. If the distance between the head and the boltface (or recoil shield) is too great (this is referred to as excessive headspace) the case has farther to go before it stops, which allows it to build up more speed and more pressure before it hits, which can cause damage to the gun. Also, if the headspace is excessive, the firing pin may not be long enough to pop the primer, and you have misfires.
Cartridges "headspace" in different areas, depending on the design of the cartridge.
Rimmed cartridges headspace on the rim. That's why you can use both 38 and 357 in a 357 revolver. The 38's being shorter does not matter, since the rim is in the same spot on both rounds.
Belted magnums headspace on the belt. They work the same as a rimmed round, in that if the case is a little too short, it doesn't matter, since the belt is always in the same place.
Bottlenecked rimless rounds headspace on the shoulder. Like with the belted cases, it doesn't matter too much if the overall length is a little short, as long as the shoulder has not been blown forward or pushed back.
The last group is the straightwalled rimless cartridges. They headspace on the mouth. 45 ACP, 9mm, 40 S&W, etc. If you look in the chamber of most modern pistol rounds, you will see a little "step" in there. This gives the case mouth somewhere to sit. Without it, since the case is rimless, the entire cartridge could fall through the chamber. Because they headspace on the mouth, overall length of the cartridge is critical. Too long and the bolt won't close (too little headspace) and too short and the cartridge goes too far forward into the chamber (excessive headspace).
Some of the older revolvers don't have this step in them. The cylinder is bored straight through. There is no need for the step, since they headspace on the rim. Most modern revolvers have this step, though, but it is more of a safety issue than for headspace. The step will not allow you to chamber a 357 in a 38 special. Without the step, one might fit, with disastrous results.