This guide shows the industry standards associated with measuring fasteners. Once you know this, you can work out the diameter, length, and pitch of any standard fastener.
In general, fasteners are measured by refering to the diameter and the length of the component.
If a fastener head sits above the material being fixed (e.g. in the image of a hexagon setscrew above), the measurement of the length is taken from the bottom of the head.
If a fastener head sits flush with the material being fixed (e.g. in the image of a socket countersunk screw above), the measurement of the length is taken from the top of the head.
One of the main exceptions to these rules is shoulder screws. Firstly; to avoid any confusion or ambiguity, it's best to specify both the thread diameter, and the shoulder diameter when identifying shoulder screws. The shoulder is larger than the thread diameter, so an example of this might be: "M10 x 12mm" - i.e. M10 thread, with a 12mm shoulder.
Another exception to the typical rules with shoulder screws is that the length only refers to the length of the shoulder, not the whole screw (see diagram below).