Common CNC G Codes and Their Functions

IPWITHEASE | Blog,Programming & Software

What is CNC G code?

G code is a programming language used by CNC machines to control the functions and movements of the machine. 

Letters are used to call functions of the machine and the numerical values are used for setting values or selecting program identifiers.

What types of codes are used in CNC programming?

There are many different codes used in CNC programming. X, Y and Z identify locations in the machine. S controls the spindle speed. F controls the machines feed rate. The two largest groups of codes are G codes and M codes. 


G codes are preparatory functions. This means they prepare the machine for an action such as movement or set modes such as working in inches or millimeters.

M codes are miscellaneous functions, and they control machine functions such as turning the CNC spindle on or off as well as controlling the coolant of the machine.

Common G codes

G codes vary between machines, but the most common ones are usually found on all machines. We have covered the most frequently used G codes below out of the  complete list of G codes. 

Learning about the most common codes is the best way to get up to speed and be able to read the majority of your CNC program.

Movement G codes

CNC machines do a lot of movement as they position the cutting tool around the machine to remove material from the workpiece.

G00 is for rapid movement at the fastest possible machine speed. This is useful for moving the machine when not cutting.

G01 is for straight line movement at a controlled feedrate. G01 is used for straight line cutting.

G02 and G03 are for circular movements. They are also used for cutting motion. G02 is for a clockwise cutting motion and G03 is for a counterclockwise cutting motion.

Unit modes

The two unit modes for a CNC machine are G20 – inch mode and G21 – metric mode. 

Most CNC programmers will stick with a primary unit mode and convert any needed values to their primary units. This makes reading programs easier for those involved because they will always be working in the same units.

There is a big difference between 25 millimeters and 25 inches!

Positioning modes

Positioning modes also affect how the machine moves just like the unit modes.

G90 is for absolute mode. This means that the machine will read all location values as relative to a fixed zero location. Most often this is either the zero location for the workpiece or the zero (home) location of the CNC machine.

G91 is for incremental mode. When the machine is in incremental mode, it will read all location values as relative to the machine’s current location. 

Cutter compensation 

G41 and G42 are cutter compensation modes. They are used to account for the size of your cutting tool. There are times where you might want to run the same program with a different cutting tool to improve surface finish for instance. Using G41 and G42 to account for the size of your cutter will allow you to do that.

G41 shifts the tool to the left and G42 shifts the tool to the right. G41 is much more common but the best way to remember is that if you are climbing milling then you should be using G41 and if you are conventional milling you should use G42. 

Contrary to how it may sound, climb milling is more common than conventional milling.


Offsets are used by your machine for two reasons. One is to account for the length of your cutting tool and another is to identify the location of the work piece.

G43 is used to compensate for the cutting tool length. Just like the diameter of your cutting tool is adjusted for with G41/G42 cutter compensation, the length of the tool is adjusted by using G43. 

The other offset is the work or fixture offset. There are multiple work offset codes but the most common are G54 through G59. These g codes tell the machine the location of your work piece. Most commonly you will identify an XYZ zero location and store it with G54.

Imagine if you had a pallet of 6 pieces in your CNC machine. Setting each piece as a separate work offset with G54 through G59 would allow you to run the same program six different times in six different locations in the machine. Multiple work offsets give the CNC programmer and operators more flexibility when setting up the machine.


There are many different g codes to learn when programming CNC g code. The majority of those codes are rarely used. We have picked the most frequently used codes to speed up your comprehension.

Once you have mastered the common g codes, you should move on to learning about M codes. With a solid understanding of the most often used codes, you will be well on your way to reading CNC programs and will likely be able to understand the majority of code.

Continue Reading:

Compiler vs Interpreter vs Assembler

Operating Systems vs Processor: Detailed Comparison


Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart