In most cartridges, it's the distance between the bolt face and the datum line of the shoulder of the cartridge. Thus cartridges such as the .30-06 are said to 'headspace on the shoulder'. In an ideal world, the cartridge should just fill the chamber, with the shoulder of the brass just touching the shoulder of the chamber - in that manner, the brass stretches very little when fired.
Other cartridges, such as the .338 W.M. are "belted"...and the cartridge headspaces on the belt. Most handloaders still strive to size belted brass such that it headspaces on the shoulder as well, to limit stretching and extend case life.
"Excessive headspace" is the condition where, for example, the rifle has been subjected to excessive loads, and perhaps the locking lugs have been damaged or worn...if there is 'slack' between the bolt face and the cartridge, the brass will stretch to fill the extra space. That will be visible as a bright ring around the brass near the reinforced 'web' (a short distance up from the base), or in some instances, case head separation. It also shows up as general signs of excessive pressure, with a load that is usually considered to be well under maximum.
A modest amount of excessive headspace can often be dealt with by careful adjustment of the sizing die (i.e. neck sizing)...but it is sometimes a sign of a damaged rifle that has been exposed to severe over loads.