Headspace is the space between the top of the food and the rim of the canning jar.
During processing, the heat causes the contents of the jar to expand. Air escapes around the two piece lid. To ensure proper sealing, only two piece lids should be used for home canning. One piece lids are designed for commercial canning equipment.
After Processing, the contents of the canning jar contract as they cool and the lid is pulled down tight and the jar seals itself.
If you don't have enough headspace, the food might seep under the lid as the food expands and interfere with sealing.
If you have too much headspace, the processing time specified in the recipe may not be long enough to dirve out the air. This can also interfere with proper sealing of the canning jar.
Good canning recipes specify the headspace, but a general rule of thumb is use 1 inch for low acid foods (such as vegetables), 1/2 inch for fruits, and 1/4 inch for jams and jellies.