What is the difference between G-code and M-code?

Updated

G-code, or preparatory code, directs the geometry, trajectory, and motion parameters of the cutting tool relative to the workpiece. G-code commands specify axis movement types, such as rapid positioning (G00), controlled linear cutting feed (G01), and clockwise or counterclockwise circular interpolation (G02 and G03). They also define fundamental machining states, including linear units (inches or millimeters), active machining planes, canned drilling cycles, and the selected work coordinate system. In essence, G-code controls where the tool moves, the path it follows, and the feed rate at which it cuts.

M-code, or miscellaneous code, governs auxiliary machine functions and physical hardware states rather than toolpath kinematics. M-codes act as electrical and mechanical switches that turn machine accessories on or off throughout the cycle. Common M-code functions include commanding spindle rotation and direction (M03 and M04), toggling flood or through-spindle coolant (M08 and M09), initiating automatic tool changes (M06), and signaling program ends or conditional stops (M00 and M30). In automated production cells, auxiliary M-codes also interface with pneumatic chuck valves to actuate clamping and unclamp cycles automatically.