Complete CNC g code list with m-codes for milling in the Fanuc, LinuxCNC, GRBL, and Haas CNC machines dialects. We give a quick definition for all g codes along with a link to tutorials and examples of how to use it in CNC programming. Click the g-code link (if any) to visit a tutorial from our popuplar Online Free G-Code Training that shows examples and teaches how to program CNC machines using the g-code commands. This page is your ideal g-code reference.
G Codes and CNC G-Code List
Code
Category
Function
Notes
Motion
g00 rapid: Move in a straight line at rapids speed.
XYZ of endpoint
Motion
Move in a straight line at last speed commanded by a (F)eedrate
XYZ of endpoint
Motion
Circular Interpolation: Clockwise circular arc at (F)eedrate
XYZ of endpoint IJK relative to center R for radius
Motion
Circular Interpolation: Counter-clockwise circular arc at (F)eedrate
XYZ of endpoint IJK relative to center R for radius
Motion
Dwell: Stop for a specified time.
P for milliseconds X for seconds
G05
Motion
FADAL Non-Modal Rapids
Motion
Compensation
Coordinate
Turn Polar Coordinates OFF, return to Cartesian Coordinates
Coordinate
Coordinate
Select X-Y plane (Plane Selection)
Coordinate
Select X-Z plane (Plane Selection)
Coordinate
Select Y-Z plane (Plane Selection)
Coordinate
Program coordinates are inches
Coordinate
Motion
Motion
Motion
Return from the reference position
Motion
Return to the 2nd, 3rd, and 4th reference point
G32
Canned
Constant lead threading (like G01 synchronized with spindle)
G40
Compensation
Tool cutter compensation off (radius comp.)
G41
Compensation
Tool cutter compensation left (radius comp.)
G42
Compensation
Tool cutter compensation right (radius comp.)
G43
Compensation
Apply tool length compensation (plus)
G44
Compensation
Apply tool length compensation (minus)
G49
Compensation
Tool length compensation cancel
Compensation
Reset all scale factors to 1.0
Compensation
Coordinate
Local workshift for all coordinate systems: add XYZ offsets
Coordinate
Machine coordinate system (cancel work offsets)
Coordinate
Work coordinate system (1st Workpiece)
Coordinate
Work coordinate system (2nd Workpiece)
Coordinate
Work coordinate system (3rd Workpiece)
Coordinate
Work coordinate system (4th Workpiece)
Coordinate
Work coordinate system (5th Workpiece)
Coordinate
Work coordinate system (6th Workpiece)
Other
G62
Other
Automatic corner override
G63
Other
Tapping mode
G64
Other
Best speed path
Other
Coordinate
Coordinate
Cancel Coordinate System Rotation
Canned
High speed drilling cycle (small retract)
G74
Canned
Left hand tapping cycle
G76
Canned
Fine boring cyle
Canned
Canned
G82
Canned
Drilling cycle with dwell (counterboring)
Canned
Peck drilling cycle (full retract)
G84
Canned
Tapping cycle
Canned
Boring cycle, no dwell, feed out
Canned
Boring cycle, spindle stop, rapid out
G87
Canned
Back boring canned cycle
G88
Canned
Boring canned cycle, spindle stop, manual out
G89
Canned
Boring canned cycle, dwell, feed out
Coordinate
Absolute programming of XYZ (type B and C systems)
Coordinate
Absolute programming IJK (type B and C systems)
Coordinate
Incremental programming of XYZ (type B and C systems)
Coordinate
Incremental programming IJK (type B and C systems)
Coordinate
Offset coordinate system and save parameters
G92 (alternate)
Motion
Clamp of maximum spindle speed
S
G92.1
Coordinate
Cancel offset and zero parameters
G92.2
Coordinate
Cancel offset and retain parameters
G92.3
Coordinate
Offset coordinate system with saved parameters
G93
Motion
Inverse Time Feed Mode. For use with rotary axes
G94
Motion
Units per minute feed mode. Units in inches or mm.
G95
Motion
Units per revolution feed mode. Units in inches or mm.
Motion
Motion
Canned
Return to initial Z plane after canned cycle
Canned
Return to initial R plane after canned cycle
M Code List to Control Machine Functions
M Codes
Category
Function
Notes
M00
M-Code
m00 Program Stop (non-optional)
M01
M-Code
Optional Stop: Operator Selected to Enable
M02
M-Code
M-Code
M-Code
M-Code
M-Code
M-Code
M-Code
M-Code
M17
M-Code
FADAL subroutine return
M29
M-Code
Rigid Tapping Mode on Fanuc Controls
M30
M-Code
End of Program, Rewind and Reset Modes
M-Code
M-Code
M-Code
M-Code
M-Code
M-Code
M-Code
Sets coordinates for the axes: x axis, y axis, z axis and a axis.
Some Thoughts on G and M Codes
G and M Codes are the basic programming language used by most CNC Machines. These same g codes are probably the ones used by your CNC machine.
Most cnc programming of G and M codes is done using Computer Aided Manufacturing (CAM) Software. If you are able to program directly in G and M codes, you can do things that CAM software cannot. These things will make you a more productive CNC'er. Being able to control cnc machines at this level is one thing that can give machine shops competitive advantage.
Bonus: Check Out our Other CNC Cookbooks for More In-Depth CNC Information!
If you're a CNC Beginnner, check out our CNC Beginner's Cookbook. It'll get you up to speed with a solid CNC foundation fast.
We also have Cookbooks for Feeds and Speeds, G-Code Programming, CNC Manufacturing and Shop Management, DIY CNC, and don't forget the CNC Cookbook Blog-with over 4 million visitors a year it's the most popular CNC blog by far on the web.
More Resources
G Code Commands FAQ
How many G codes are there in cnc machining?
There are about 100 g code commands, give or take. There are may dialects of g-code, and some have proprietary g-codes.
What are G Codes in CNC Machines?
This page lists all the G code commands used in CNC programming and tells what they do. It also gives links to tutorials and examples. G codes are single-letter commands that tell the CNC machine what to do. They may command motion (i.e. tell the machine where to cut) or do things like turn the spindle on or off.
Is learning G-Code hard?
Learning g-code isn't very hard. We have a complete free online g-code tutorial to teach you and a g-code simulator that makes learning easy.
Why are G Codes used?
G Codes make CNC Machines programmable, which gives them the flexibility to make almost any part.
What is the difference between G codes and M codes?
The G in G-Codes stands for Geometry, which means giving the CNC Machine directions on how and where to move. The four simplest motion-related g codes are:
- G00: Move at the machine's fastest speed in a straight line to the commanded coordinates.
- G01: Move at the last commanded feedrate (commanded by the "F" word) in a straight line to the commanded coordinates.
- G02: Move in a clockwise arc to the commanded coordinates at the last commanded feedrate.
- G03: Move in a counterclockwise arc to the commanded coordinates at the last commanded feedrate.
M Codes are about Machine functions on the CNC machine.
Do all CNC machines use G-code?
Not all CNC machines use G-Code. Some CNC machines may have both g-code and other ways of programming, for example, alternate languages such as Mazak's Mazatrol or Conversational Programming. Others may have an alternate language and no ability to execute g-code at all.
Be the first to know about updates at CNC Cookbook
Join our newsletter to get updates on what's next at CNC Cookbook.