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.
Table of Contents
ToggleCNC Movement and Travel
Moves the CNC around at the maximum possible speed. Often called rapid traverse.
Move the CNC in a straight line to a specific location. The speed of this movement is determined by the feed rate (F).
Move the CNC to specific location along along a specified arc or radius traveling clockwise. The speed of this movement is determined by the feed rate (F).
Move the CNC to a specific location along a specified arc or radius traveling counterclockwise. The speed of this movement is determined by the feed rate (F).
Tells the CNC not to move for a certain amount of time.
Plane Selection
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.
Unit Modes
All size and location commands will be in inches until changed.
All size and location commands will be in millimeters until changed.
Compensation Codes
Turns off any cutter compensation modes (G41 or G42).
Shifts the machine tool path to the left based on the radius of the cutting tool.
Shifts the machine tool path to the right based on the radius of the cutting tool.
Adjusts a tool’s location based on a specified tool height (H) offset.
Turns off the tool length compensation set by a G43 or G44 command.
Work Offsets
Sets a specific location in the CNC as the zero location for the program.
Sets a specific location in the CNC as the zero location for the program.
Sets a specific location in the CNC as the zero location for the program.
Sets a specific location in the CNC as the zero location for the program.
Sets a specific location in the CNC as the zero location for the program.
Sets a specific location in the CNC as the zero location for the program.
Canned Cycles
Peck drill a hole by repeatedly drilling, then retracting a small amount, then drilling deeper. Often used to break up chips when drilling.
A tapping cycle for left-hand or reverse threads. The spindle must be running in reverse during this cycle. The machine will feed to the bottom of the hole and then reverse the spindle direction and back out of the hole.
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.
Drills a hole then rapid retracts out of the hole.
Drills a hole, dwells at the bottom of the hole for a set amount of time and then rapid retracts out of the hole.
The machine will drill in pecks while rapid retracting out of the hole between each peck to help clear chips from the drill.
The standard tapping cycle with the spindle running clockwise. The CNC will feed to the bottom of the hole and then reverse the spindle direction and back out of the hole.
The machine will feed to the bottom of the hole and then rapid retract out.
The machine will feed to the bottom of the hole and then rapid retract out. The tool is not pulled away from the surface which can leave a tool mark on 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.
Cancel Codes
G50 - Cancel Scaling
Turns off scaling mode.
Cancels any active canned cycles for drilling, boring, tapping, etc.
Positioning Modes
All movement locations are relative to a fixed zero such as the work offset (G54, G55, etc.) or machine home location.
All movement locations are relative to the machine’s current position.
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.
Plane Return
After a canned cycle the tool will retract to the start of the canned cycle.
After a canned cycle the tool will retract to a specified location. Can be useful for avoiding workholding fixtures.
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.
The machine will move to a specified location and then to the zero return (home) 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
Rarely used.
G46 - Single Offset Decrease
Rarely used.
G47 - Double Offset Increase
Rarely used.
G48 - Double Offset Decrease
Rarely used.
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
Modal Call
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.