G CODES: COMPLETE LIST AND GUIDE

G codes: Full list (Milling & Turning)

* Click the G Code to read the full explanation

What is a G code?

G-code is the common name for the most widely used CNC programming language. It was developed in the 1950s at MIT. The language is very “primitive” by today’s standards. All the commands are represented by codes (G01, G02, etc..) and not by meaningful words. Variables are represented by numbers(#500, #151, etc..) and not by words; conditional logic is very limited. Amazingly this 70-year-old language is still the industry standard. Several tool manufacturers developed higher-end Wizard-like languages such as Mazak – Mazatrol or Okuma – AOT, but none of them gained very high popularity.

The target of the code is to control the movements of a computerized controlled machine. The code basically “tells” the machine in what path to move from one coordinate to the next (Called “Toolpath”), and at what speed (Called “Feedrate”).

G code syntax

Sample short program

N10 O1000;
N20 T05;
N30 G01 A10 X40 Z60 F1.0 S1000;
N40 M05;

What does each letter in the program mean?

LetterRole
X,Y,Z,A,B,CCoordinates for Movement
FSpindle Speed – The speed at which the spindle should be rotating.
SSpindle Speed – The speed the spindle should be rotating.
I,J,KArc center for G02/G03
OProgram Number
NLine (Block) Number
MMiscellaneous function – See separate List
TSelect a tool from Magazine / Turret
PParameter Number

M Codes

“G” stands for Geometry; hence, the G-Code commands are responsible for the movements of the machine that create the geometry of the part. “M” stands for Machine (or Miscellaneous), and the M-Codes are responsible for Machine commands that cause particular operations of the equipment. Unlike G-codes, which can appear multiple times on the same line, M-Code is limited to one code per line.

List of M-codes

CodeDescriptionThe spindle will start to rotate in CW direction at the speed given in the S parameter.
M00Machine StopThe Machine will stop the operation in the middle of the program
M01Optional stopThe machine will stop in the middle of the program only if the optional stop button is “On”.
M02program EndEnd of Program
M03Spindle on CW directionThe spindle will start to rotate in CW direction at the speed given in the S parameter.
M04Spindle on CCW directionThe spindle will start to rotate in CW direction at the speed given in the S parameter.
M05Spindle stopThe spindle will stop rotating
M06Automatic tool change (ATC)The spindle will start to rotate in CCW direction at the speed given in the S parameter.
M07Mist (Shower) Coolant OnA spray of coolant fluid droplets
M08Flood Coolant OnAn overflowing of coolant fluid.
M09Coolant offShut down the coolant (Both M07 & M08)
M30End of ProgramThe spindle will start to rotate in CW direction at the speed given in the S parameter
M41 – M44Gear selectionSelect the gear suitable for the spindle speed (ON lathe Machines)
M48Feedrate override OnPlaced at the end of the subprogram and returns the control to the main program one line after the line it was called from.
M49Feedrate override OffOperator feedratee override is ignored.
M98Subprogram callPasses control to the subprogram number provided in parameter P
M99Subprogram endThe machine will change the tool and pick from the Turret/Magazine a new tool according to the “T” parameter.
Scroll to Top