The Headstock is the top part of a guitar. The headstock's main purpose is to form a point where the strings can be secured, opposite of the bridge, so they can have tension to form distinct pitches. The tuning heads are attached to the headstock.
The headstock is at the top of the neck of a guitar. The shape of the headstock is often a signature element of guitars, especially acoustic ones. The tuning heads (if they are there, as Spanish models wrap them around a rod that is directly spun to tune the string) typically face outward, and the apparatus on the other side of the headstock allows a tuning key to rotate it. Strings are "wrapped" in a particular fashion to allow for the easiest way to tune strings, and keep them from coming loose.
Aside from the shape of the headstock being signature, the arrangement of the heads is also a signature aspect of its design. Heads are placed near the edge of the headstock. Heads are commonly arranged in 6-in-line (such as the Telecaster or Explorer) or 3-a-side (such as the Les Paul or most the SG).
The headstock of the bass guitar is often much larger in proportion to the neck than the guitar's headstock is to its neck. This is mainly to maintain stability, as bass strings are larger, and must stay in tune under great tension.
The nut of the guitar is the separating point between the neck and the headstock, and it allows the strings to all remain equal, regardless of the arrangement of the tuning heads.
Inlays, model types, artist signatures, and brand names are often placed on the headstock as well. If a guitar features binding on the body and neck, it is often also featured here, as well.
The headstock may be straight, parallel to the neck, or bent at the nut. Acoustic guitar use bent headstocks, and many electric guitars also use bent headstocks (the most notable exception being Fender). Using straight headstock reduced the amount of lumber used in making necks, and therefore allows guitars to be sold cheaper.
Companies such as Fender and Martin are very protective of their headstock designs. Fender has copyrighted their Stratocaster headstock design, which keeps other companies, such as ESP or Kramer. Martin had a legal dispute with Takamine in the mid 80's regarding models that used an identical style of the signature Martin rectangluar headstock. They went to court, and forced Takamine to create their own headstock design and lettering pattern that did not follow theirs as closely.