Whether you’re a CNC machinist, programmer, or manufacturer looking to optimize production, understanding M codes and G codes is non-negotiable. These two types of commands form the foundation of CNC programming, enabling precise control of machine operations like cutting, tool changes, coolant flow, and motion paths.
This article provides a comprehensive guide to common G and M codes, how they function, and where they're used—especially within FANUC-controlled CNC systems.
G Codes (Geometric Codes) define machine movement and tool paths.
M Codes (Miscellaneous Codes) handle machine functions such as turning on coolant, stopping the spindle, or tool changing.
Think of it this way:
G codes = How the machine moves.
M codes = What the machine does while moving (or before/after).
Both are essential for a successful CNC program.
G Code | Function | Description |
---|---|---|
G00 | Rapid positioning | Moves tool quickly from point to point without cutting |
G01 | Linear interpolation | Moves tool in a straight line at a set feed rate |
G02 | Circular interpolation (clockwise) | Cuts arcs or circles in a clockwise direction |
G03 | Circular interpolation (counter-clockwise) | Cuts arcs or circles counter-clockwise |
G04 | Dwell | Pauses the machine for a set time |
G17 | Select XY plane | Default plane for 2D machining |
G18 | Select ZX plane | Useful in turning centers |
G19 | Select YZ plane | For vertical or sidewall machining |
G20 | Inch units | Sets machine units to inches |
G21 | Metric units | Sets machine units to millimeters |
G28 | Return to machine zero | Sends tool to home position |
G40 | Cancel cutter compensation | Turns off tool radius offset |
G41 | Cutter compensation left | Offsets tool to the left of path |
G42 | Cutter compensation right | Offsets tool to the right of path |
G43 | Tool length compensation + | Compensates for tool height |
G49 | Cancel tool length compensation | Resets tool length offset |
G54 – G59 | Work coordinate systems | Allows multiple part setups |
G80 | Cancel canned cycle | Stops any active drilling cycle |
G81 | Drilling cycle | Basic vertical drilling operation |
G82 | Drilling with dwell | Pauses at bottom of drill before retract |
G83 | Peck drilling cycle | Breaks chips while drilling deep holes |
G90 | Absolute programming | Coordinates based on part origin |
G91 | Incremental programming | Coordinates based on last position |
G94 | Feed per minute | Feed rate in mm/min or in/min |
G95 | Feed per revolution | Feed rate based on spindle RPM |
Note: G codes can vary slightly depending on the machine type (mill vs. lathe) and the controller (FANUC, Siemens, Haas, etc.)
M Code | Function | Description |
---|---|---|
M00 | Program stop | Stops machine until manually restarted |
M01 | Optional stop | Stops only if optional stop is enabled |
M02 | Program end | Ends the program |
M03 | Spindle on (CW) | Starts spindle clockwise |
M04 | Spindle on (CCW) | Starts spindle counter-clockwise |
M05 | Spindle stop | Stops the spindle rotation |
M06 | Tool change | Automatically changes to next tool |
M08 | Coolant on | Activates coolant flow |
M09 | Coolant off | Stops coolant flow |
M30 | Program end and rewind | Ends program and resets to the top |
M98 | Call subprogram | Runs a separate subroutine |
References
NEXT
Related Funac Parts
WEITE INSIGHTS & BLOGWeite Welcomes Your Inquiries for More Fanuc Parts
Talk to Us
Quick Links
Need Fanuc Parts Details?
Weite Welcomes Your Inquiries for More Fanuc Parts
East side of the 2nd floor, Building B, No. 333, Heting Street, Qingshan Lake Street, Hangzhou
Weite Welcomes Your Inquiries for More Fanuc Parts
Talk to Us
Quick Links
East side of the 2nd floor, Building B, No. 333, Heting Street, Qingshan Lake Street, Hangzhou
fanucalex@gmail.com
+8613858013242
Need Fanuc Parts Details?
Weite Welcomes Your Inquiries for More Fanuc Parts
|