G code, sometimes called g-code, is a simple programming language for CNC machines.
Listed below are the codes that use the G word. These codes are preparatory commands.
This means that they set modes or prepare the machine for various actions.
We have put together a complete list of G codes for your reference.
Not all codes are used often.
Below is a list of G codes. They have been organized into group types based on how the machine reacts to the individual code.
If you are new to G code, you should review the code groups and compare the codes within a single group.
You will quickly see they handle the same function, such as one code to turn something on and one code to turn something off.
This makes learning the codes twice as easy.
CNC Movement and Travel
G17 - XY Plane Selection
The vast majority of movement in CNC programs will be relative to the XY plane. Plane selection affects how G02, G03, cutter compensation and some canned cycles are handled.
G18 - XZ Plane Selection
Plane selection affects how G02, G03, cutter compensation and some canned cycles are handled. G18 tells the machine you are machining radii around the Y axis.
G19 - YZ Plane Selection
Plane selection affects how G02, G03, cutter compensation and some canned cycles are handled. G19 tells the machine you are machining radii around the Z axis.
G76 - Fine Boring Canned Cycle
Bores a hole then stops the spindle, retracts the tool from the surface and rapid retracts the tool out of the hole.
G87 - Back Boring Cycle
Bores a hole from bottom to top. This is the reverse direction of the G86 code.
G88 - Boring Cycle with Dwell
Bores a hole and then dwells at the bottom for a set amount of time.
G89 - Back Boring Cycle with Dwell
The machine will feed to the bottom of the hole, pause for a set amount of time and then rapid retract out. The tool is not pulled away from the surface which can leave a tool mark on the hole.
G50 - Cancel Scaling
Turns off scaling mode.
Speeds and Feeds
G94 - Feed per Minute Mode
Sets the feed rate to units (inches/mm) per minute. The tool will move at a set rate.
G95 - Feed per Revolution Mode
Sets the feed rate to units (mm/inches) per revolution. The tool will move a set rate for every spindle rotation.
G96 - Constant Surface Speed
The spindle speed will vary to maintain the same surface speed of the material.
G97 - Constant Spindle Speed
The spindle will operate at a consistent RPM.
Lesser Used G Codes
G09 - Exact Stop Check (Non-modal)
Causes the machine to come to a stop after each command. Useful for making sharp corners. It causes the machine to stop after executing the current line.
G10 - Programmed Offset Input
Adjusts offset values. Can change work offset, tool length offset and/or cutter compensation offsets.
G22 - Stored Stroke Limit
Turns on a set safety zone that will cause the machine to alarm out if it enters.
G23 - Stored Stroke Limit Cancel
Turns off the stored safety zone.
G27 - Zero Return Check
Rarely used. This command checks to see that the machine has moved to the zero return position.
G29 - Return From Reference Position
The machine will move to the position referenced in the last G28 command. It will then move to the location referenced with the G29 command.
G30 - Second Position Zero Return
Similar to G28 the machine will move to a specified location and then will move to a secondary reference point in the machine such as a tool changer location.
G31 - Skip Function
Often used with probing, it is used to move the probe until it hits an object.
G44 - Negative Tool Length Compensation
Rarely used. Adjusts a tool’s location based on a specified height (H) offset in the opposite of the normal direction.
G45 - Single Offset Increase
G46 - Single Offset Decrease
G47 - Double Offset Increase
G48 - Double Offset Decrease
G51 - Scaling
Scales the machined part size by a scaling factor.
Scaling factors >1 make it bigger. Scaling factors <1 make it smaller.
G52 - Temporarily Shift Program Zero
Shifts the program zero location based on a location specified with the command.
G53 - Return to Machine Zero Position
Rapid moves the CNC to the machine reference position.
G60 - Single Direction Move
Forces the machine to approach each XY location from the same direction. Helps eliminate location errors caused by machine backlash.
G61 - Exact Stop Check (Modal)
The machine will come to a stop after each line of code.
G64 - Normal Cutting Mode
Cancels both G60 and G61 modes.
G65 - Custom Macro Call
A macro is similar to a subprogram but it allows you to use variables in the program.
G66 - Custom Macro Modal Call
Makes the machine call a macro, similar to G65, with every new location given until turned off.
G67 - Cancel Custom Macro
Cancels any active custom macro modal calls.
G68 - Coordinate Rotation Mode
Rotates the machine coordinates at a given angle around a specified location.
G69 - Cancel Coordinate Rotation Mode
Turns off coordinate rotation mode.
G92 - Program a Work Offset
Sets a work offset based on a specific location in the machine.
Frequently asked questions
How many G codes are there?
We listed 70 G codes in our list alone but in reality there are many more.
Some will have different meanings on lathes vs mills. Also, different CNC controller manufacturers will include their own special codes. For example, some will have codes such as G103 or they will switch the meaning of a code.
You should always know how your individual machine will react to a specific code.
Who needs to know G code?
Anyone who works with a CNC machine would benefit from understanding G code.
While it may not be a requirement for their job depending on where they work, these positions would benefit from understanding G codes:
- CNC operator
- CNC setup
- CNC programming
- CNC machinist
Is learning G code hard?
Learning G code can be a daunting task when there are so many codes to understand.
While it is true that there are a lot of codes that can be used, you should know that most shops will only use a small selection of codes which cuts down the number you need to understand before you are up to speed.
Don’t be overwhelmed. Figure out which codes are the most commonly used ones and start your learning there.