What do the numbers in screw sizes M3, M4 etc. mean?
There are a few more numbers for a complete description. It's pretty much a world-wide system described by several ISO standards, but there are occasional oddities (slight differences between ISO and DIN standard sizes on a few items for instance)
You asked about M3, M4, etc - that describes (only) the outside diameter of the screw - or the size of an unthreaded hole the screw would slip through.
A full description is like M6-1X25 Which describes the outer diameter (6) , the distance from one thread to the next (1) (pitch) and the length (25) (all in millimeters.)
An M6 could also be an M6-0.75 (fine thread pitch) X whatever length. When not specified, the coarse thread is generally assumed, but sometimes the assumption is wrong...
Coarse and Fine pitch for the sizes you asked about:

M3-0.50 and M3-0.35
M4-0.7 and M4-0.5
M5-0.8 and M5-0.5

Thread charts are easily found if you need to know about more sizes.