CNC Machining
CNC Machining
G code
G Code is used to control the path of the machine tool. There isn’t one universal list of all CNC G- and M-codes: G-codes vary by controller (Fanuc, Haas, Siemens, Mitsubishi, LinuxCNC, etc.), and M-codes are especially machine-builder-specific. Below is a comprehensive Fanuc/Haas-style reference covering the commonly encountered codes. Some codes have different meanings depending on the controller or machine.
CNC G Codes
| G Code | Function | Description |
|---|---|---|
| G00 | Rapid positioning | Moves the tool rapidly to a specified position |
| G01 | Linear interpolation | Cuts in a straight line at the programmed feed rate |
| G02 | Circular interpolation CW | Cuts an arc clockwise |
| G03 | Circular interpolation CCW | Cuts an arc counterclockwise |
| G04 | Dwell | Pauses for a specified amount of time |
| G05 | High-speed/high-precision mode | Controller-dependent; advanced contouring |
| G09 | Exact stop | Temporarily forces an exact stop at the end of a block |
| G10 | Programmable data input | Allows offsets/settings to be programmed |
| G11 | Cancel programmable data input | Cancels G10 mode |
| G12 | Circular pocket milling CW | Controller-dependent |
| G13 | Circular pocket milling CCW | Controller-dependent |
| G15 | Polar coordinates cancel | Cancels polar coordinate mode |
| G16 | Polar coordinate mode | Enables polar coordinate programming |
| G17 | XY plane selection | Selects XY plane for circular interpolation |
| G18 | XZ plane selection | Selects XZ plane |
| G19 | YZ plane selection | Selects YZ plane |
| G20 | Inch programming | Coordinates interpreted in inches |
| G21 | Metric programming | Coordinates interpreted in millimeters |
| G28 | Return to machine zero | Returns machine to reference/home position |
| G30 | Return to 2nd/other reference point | Returns to an alternate machine reference position |
| G31 | Skip/probe function | Used for probing or skip movements |
| G32 | Thread cutting | Synchronizes feed with spindle for threading |
| G33 | Thread cutting | Controller-dependent threading cycle |
| G40 | Cutter compensation cancel | Cancels tool-radius compensation |
| G41 | Cutter compensation left | Applies cutter compensation to the left of the programmed path |
| G42 | Cutter compensation right | Applies cutter compensation to the right |
| G43 | Tool length compensation + | Applies positive tool-length offset |
| G44 | Tool length compensation − | Applies negative tool-length offset; controller-dependent |
| G49 | Tool length compensation cancel | Cancels G43/G44 |
| G50 | Scaling/spindle speed limit | Meaning varies by controller; commonly cancels scaling or sets maximum spindle speed |
| G51 | Scaling | Enables programmable scaling |
| G52 | Local coordinate system | Establishes a temporary local coordinate shift |
| G53 | Machine coordinate system | Executes movement using machine coordinates |
| G54 | Work coordinate system 1 | Selects work offset #1 |
| G55 | Work coordinate system 2 | Selects work offset #2 |
| G56 | Work coordinate system 3 | Selects work offset #3 |
| G57 | Work coordinate system 4 | Selects work offset #4 |
| G58 | Work coordinate system 5 | Selects work offset #5 |
| G59 | Work coordinate system 6 | Selects work offset #6 |
| G54.1 P1–P48 | Extended work offsets | Additional work coordinate systems; availability varies |
| G61 | Exact stop mode | Commands exact stopping/precision behavior |
| G61.1 | High-precision contour control | Controller-dependent |
| G64 | Cutting/continuous mode | Cancels exact-stop behavior on controllers that support it |
| G65 | Macro call | Calls a custom macro/subprogram with arguments |
| G66 | Modal macro call | Calls a macro repeatedly in subsequent blocks |
| G67 | Cancel modal macro | Cancels G66 |
| G68 | Coordinate rotation | Rotates the coordinate system |
| G69 | Cancel coordinate rotation | Cancels G68 |
| G70 | Finishing cycle | Finishing cycle for turning |
| G71 | Rough turning cycle | Automatic roughing cycle |
| G72 | Facing roughing cycle | Rough-facing cycle |
| G73 | Pattern/peck drilling cycle | Meaning varies between mill and lathe |
| G74 | Left-hand tapping / peck drilling | Function depends on machine |
| G75 | Grooving/peck cycle | Commonly used for repetitive grooving on lathes |
| G76 | Threading cycle | Automatic multi-pass threading cycle |
| G80 | Canned cycle cancel | Cancels active drilling/boring cycle |
| G81 | Drilling cycle | Basic drilling canned cycle |
| G82 | Spot drilling/counterboring | Drilling cycle with dwell |
| G83 | Peck drilling | Deep-hole drilling with retracts |
| G84 | Tapping cycle | Right-hand tapping |
| G85 | Boring cycle | Boring with feed in and feed out |
| G86 | Boring cycle | Bores then stops spindle/retracts |
| G87 | Back boring cycle | Boring from the opposite side |
| G88 | Boring cycle | Controller-dependent |
| G89 | Boring cycle with dwell | Boring cycle with dwell |
| G90 | Absolute programming | Coordinates measured from the active work zero |
| G91 | Incremental programming | Coordinates measured from the current position |
| G92 | Coordinate/spindle setting | Meaning varies; often coordinate-system or spindle-speed limiting function |
| G94 | Feed per minute | Feed specified in distance per minute |
| G95 | Feed per revolution | Feed specified per spindle revolution |
| G96 | Constant surface speed | Automatically varies spindle RPM to maintain surface speed |
| G97 | Constant RPM | Cancels constant surface speed |
| G98 | Return to initial point | Canned cycle returns to initial Z position |
| G99 | Return to R point | Canned cycle returns to the R-plane |
Common Turning-Specific G Codes
| G Code | Function | Description |
|---|---|---|
| G20 | Inch mode | Programming in inches |
| G21 | Metric mode | Programming in millimeters |
| G32 | Thread cutting | Single-point threading |
| G50 | Spindle speed limit | Sets maximum RPM during CSS |
| G70 | Finishing cycle | Finishes a previously defined roughing profile |
| G71 | Rough turning | Removes material from OD/ID profile |
| G72 | Rough facing | Removes material from a facing profile |
| G73 | Pattern repeating cycle | Repeats a profile with controlled depth |
| G74 | Peck drilling | Common lathe drilling/pecking cycle |
| G75 | Grooving cycle | Repetitive grooving/pecking |
| G76 | Multiple-pass threading | Automatic threading cycle |
| G96 | Constant surface speed | Maintains programmed surface speed |
| G97 | Constant spindle speed | RPM remains fixed |
| G98 | Feed per minute | Feed specified in distance/minute |
| G99 | Feed per revolution | Feed specified in distance/revolution |
Common Milling-Specific G Codes
| G Code | Function | Description |
|---|---|---|
| G00 | Rapid | Rapid tool movement |
| G01 | Linear interpolation | Straight-line cutting |
| G02 | CW arc | Clockwise circular movement |
| G03 | CCW arc | Counterclockwise circular movement |
| G17 | XY plane | Standard milling plane |
| G18 | XZ plane | XZ circular interpolation |
| G19 | YZ plane | YZ circular interpolation |
| G40 | Cancel cutter compensation | Turns off G41/G42 |
| G41 | Cutter comp left | Tool compensation left of path |
| G42 | Cutter comp right | Tool compensation right of path |
| G43 | Tool length compensation | Applies H offset |
| G49 | Cancel tool length compensation | Cancels G43 |
| G54–G59 | Work offsets | Selects work coordinate system |
| G80 | Cancel canned cycle | Turns off drilling cycle |
| G81 | Drill | Standard drilling |
| G82 | Spot drill | Drill with dwell |
| G83 | Peck drill | Deep-hole drilling |
| G84 | Tap | Right-hand tapping |
| G85 | Bore | Feed in/feed out boring |
| G86 | Bore | Spindle stop before retract |
| G87 | Back bore | Back boring |
| G88 | Bore | Controller-dependent boring cycle |
| G89 | Bore with dwell | Boring with dwell |
| G90 | Absolute | Position from work zero |
| G91 | Incremental | Position from current location |
| G94 | Feed/minute | F value represents distance/minute |
| G95 | Feed/revolution | F value represents distance/revolution |
| G98 | Initial-point return | Canned cycle returns to starting Z |
| G99 | R-plane return | Canned cycle returns to R-plane |
M Code
CNC M-Codes
M-codes control machine functions rather than tool motion. Unlike G-codes, M-codes are heavily dependent on the machine builder and controller. The following are common Fanuc/Haas-style M-codes.
M Code | Function | Description |
|---|---|---|
M00 | Program stop | Stops program completely; operator must restart |
M01 | Optional stop | Stops only when optional-stop switch is enabled |
M02 | End of program | Ends program |
M03 | Spindle CW | Starts spindle clockwise |
M04 | Spindle CCW | Starts spindle counterclockwise |
M05 | Spindle stop | Stops spindle |
M06 | Tool change | Executes programmed tool change |
M07 | Mist coolant | Turns mist coolant on; machine-dependent |
M08 | Flood coolant | Turns flood coolant on |
M09 | Coolant off | Turns coolant off |
M10 | Chuck/clamp | Machine-dependent; commonly clamps |
M11 | Chuck/unclamp | Machine-dependent; commonly unclamps |
M13 | Spindle CW + coolant | Starts spindle CW and coolant |
M14 | Spindle CCW + coolant | Starts spindle CCW and coolant |
M19 | Spindle orientation | Orients spindle to a specified position |
M21 | Tailstock forward | Lathe-specific |
M22 | Tailstock reverse | Lathe-specific |
M23 | Chamfer/departure | Controller/machine-dependent |
M24 | Threading/chamfer function | Machine-dependent |
M30 | End and reset | Ends program and resets to beginning |
M31 | Chip conveyor forward | Starts chip conveyor; machine-dependent |
M32 | Chip conveyor reverse | Machine-dependent |
M33 | Chip conveyor stop | Machine-dependent |
M41 | Low gear | Selects low spindle gear |
M42 | High gear | Selects high spindle gear |
M48 | Override enabled | Enables feed/spindle overrides; controller-dependent |
M49 | Override disabled | Disables feed/spindle overrides |
M51 | Auxiliary output ON | Machine-builder dependent |
M52 | Auxiliary output OFF | Machine-builder dependent |
M60 | Pallet change | Executes pallet change on supported machines |
M61 | Fixture/clamp function | Machine-dependent |
M62 | Output ON | Turns programmable output on |
M63 | Output ON | Alternative programmable output |
M64 | Output OFF | Turns programmable output off |
M65 | Output OFF | Alternative programmable output |
M66 | Wait for input | Waits for an input signal; controller-dependent |
M67 | Analog output | Machine/controller-dependent |
M68 | Hydraulic chuck clamp | Common lathe function; machine-dependent |
M69 | Hydraulic chuck unclamp | Common lathe function; machine-dependent |
M70 | Mirror image | Controller-dependent |
M71 | Mirror image | Controller-dependent |
M72 | Mirror image cancel | Controller-dependent |
M73 | Mirror image cancel | Controller-dependent |
M80 | Auto door open | Machine-dependent |
M81 | Auto door close | Machine-dependent |
M88 | Through-spindle coolant ON | Turns TSC on |
M89 | Through-spindle coolant OFF | Turns TSC off |
M97 | Local subprogram call | Calls a local subprogram; common on Haas |
M98 | Subprogram call | Calls an external/local subprogram |
M99 | Subprogram return | Returns from subprogram; can also create a loop |
M101+ | Auxiliary functions | Machine-builder/controller dependent |
Important: M-codes vary significantly
For example, M10 and M11 can mean chuck clamp/unclamp on one machine but something completely different on another. Likewise, M08 is commonly flood coolant, but additional coolant functions such as through-spindle coolant can use different codes depending on the manufacturer.
The same applies to G-codes. For example, G73 can represent a drilling cycle on a mill but a completely different cycle on a lathe.
The most important codes to memorize
If you’re learning CNC programming, I’d start with these:
Movement
G00— RapidG01— Linear cutG02— CW arcG03— CCW arc
Coordinates
G20— InchG21— MetricG90— AbsoluteG91— IncrementalG54–G59— Work offsets
Tool compensation
G40— Cancel cutter compensationG41— Cutter compensation leftG42— Cutter compensation rightG43— Tool length compensationG49— Cancel tool length compensation
Drilling
G80— Cancel canned cycleG81— DrillG82— Drill with dwellG83— Peck drillG84— Tap
Spindle/cutting
G94— Feed per minuteG95— Feed per revolutionG96— Constant surface speedG97— Constant RPM
Machine functions
M00— Program stopM01— Optional stopM03— Spindle CWM04— Spindle CCWM05— Spindle stopM06— Tool changeM08— Coolant onM09— Coolant offM30— End/resetM98— Subprogram callM99— Subprogram return
Note: This is a practical reference, not a universal controller manual. For actual machining, the specific control’s programming manual (e.g., Haas NGC, Fanuc 0i/31i, Siemens SINUMERIK, Mitsubishi, LinuxCNC) should take precedence because unsupported or differently defined codes can cause unexpected machine behavior.
