When measuring a bolt, it’s best to use calipers and a thread checker. You can probably work it out with a metric ruler though.

For example, if you were looking at an M8-1.25 x 50mm:

The bolt size is M8. You determine this by measuring the diameter of the shaft in mm to come up with the "M8" value. The socket wrench the bolt uses does not determine the bolt size. This is a common mistake.

The bolt length is measured from the end of the threads to the bottom of the bolt head. That's the length of the shaft, excluding the head. In the example it is 50mm long.

The thread pitch is the distance between threads measured in millimeters along the length of the bolt. Determining the thread pitch can be difficult without a thread checker tool. The bolts on this sight use the standard thread pitch per size. I’m sure there are some odd balls out there but generally speaking, bicycles and bicycle parts use bolts with these thread pitches.

M5=0.8 thread pitch
M6=1.0 thread pitch
M7=1.0 thread pitch
M8=1.25 thread pitch