G-Code and M-Code List [ Easy To Use Examples & Tutorials ]
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
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 | End of Program | |||
M03 | M-Code | m03 Spindle ON clockwise | |||
M04 | M-Code | Spindle ON (CCW Rotation) | |||
M05 | M-Code | m05 Spindle Stop | |||
M06 | M-Code | Tool Change | |||
M07 | M-Code | Mist Coolant ON | |||
M08 | M-Code | Flood Coolant ON | |||
M09 | M-Code | Coolant OFF | |||
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 | |||
M97 | M-Code | Haas-Style Subprogram Call | |||
M98 | M-Code | Subprogram Call | |||
M99 | M-Code | Return from Subprogram | |||
F | M-Code | Set Feedrate | |||
S | M-Code | Set Spindle Speed | |||
T | M-Code | Select Tool for Tool Change | |||
X, Y, Z, and A | 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
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.
Recently updated on June 12th, 2024 at 08:05 am