G and M Codes in CNC Programming

What is G-code

G-code is a programming language used to control CNC (Computer Numerical Control) machines. It provides a set of instructions that tells the machine how to move its tools, control its speed, and perform various operations such as cutting, drilling, milling, or 3D printing.

G Codes and Descriptions

G-CodeDescription
G0Rapid positioning
G1Linear interpolation
G2Clockwise circular/helical interpolation
G3Counterclockwise circular/Helical interpolation
G4Dwell
G10Coordinate system origin setting
G12Clockwise circular pocket
G13Counterclockwise circular pocket
G15/G16Polar Coordinate moves in G0 and G1
G17XY Plane select
G18XZ plane select
G19YZ plane select
G20/G21Inch/Millimetre unit
G28Return home
G28.1Reference axes
G30Return home
G31Straight probe
G40Cancel cutter radius compensation
G41/G42Start cutter radius compensation left/right
G43Apply tool length offset (plus)
G49Cancel tool length offset
G50Reset all scale factors to 1.0
G51Set axis data input scale factors
G52Temporary coordinate system offsets
G53Move in absolute machine coordinate system
G54Use fixture offset 1
G55Use fixture offset 2
G56Use fixture offset 3
G57Use fixture offset 4
G58Use fixture offset 5
G59Use fixture offset 6 / use general fixture number
G61/G64Exact stop/Constant Velocity mode
G68/G69Rotate program coordinate system
G70/G71Inch/Millimetre unit
G73Canned cycle – peck drilling
G80Cancel motion mode
G81Canned cycle – drilling
G82Canned cycle – drilling with dwell
G83Canned cycle – peck drilling
G85/G86/G88/G89Canned cycle – boring
G90Absolute distance mode
G90.1Absolute IJK mode
G91Incremental distance mode
G91.1Incremental IJK mode
G92Offset coordinates and set parameters
G92.xCancel G92 etc.
G93Inverse time feed mode
G94Units Per Min.
G98Rapid Height By Z Height
G99Rapid Height By R Height

What is M Code

In CNC (Computer Numerical Control) machining, M codes—often called miscellaneous codes—are commands that control various machine functions that aren’t directly related to the tool’s movement (which is typically handled by G codes). They are used to manage auxiliary functions of the machine, such as starting or stopping the spindle, turning the coolant on or off, pausing the program, and initiating tool changes.

M Codes and Descriptions

M CodeDescription
M00Mandatory Program Stop
M01Optional or Planned Program Stop
M02Program End
M03Spindle On Forward/Clockwise
M04Spindle On Reverse/Counterclockwise
M05Spindle Stop
M07Mist Coolant On
M08Flood Coolant On
M09Coolant Off
M10Pallet Clamp On
M11Pallet Clamp OFF
M13Spindle Clockwise and Coolant On
M19Spindle Orientation
M30Program End and Rewind
M48Enable Feed/Speed Overrides
M49Disable Feed/Speed Overrides
M52Unload last tool from spindle
M60Automatic pallet change
M98Subprogram Call
M99Return From Subprogram / Rewind