Searchable G-code and M-code reference for CNC machinists. Filter by control type, category, or search by code name. Covers Fanuc, Haas, Mazak, and Siemens with syntax examples and practical notes.
Last updated April 2026
| Code↑ | Description | Category | Syntax | Modal | Notes |
|---|---|---|---|---|---|
| G00 | Rapid positioning | Motion | G00 X_ Y_ Z_ | Yes | Moves at max traverse rate. NOT linear - axes move independently. Never use for cutting. |
| G01 | Linear interpolation (feed) | Motion | G01 X_ Y_ Z_ F_ | Yes | Straight line cutting move at specified feedrate. Requires F word. |
| G02 | Circular interpolation CW | Motion | G02 X_ Y_ R_ F_ or G02 X_ Y_ I_ J_ F_ | Yes | Clockwise arc. R format for arcs < 180 deg. I/J format for any arc including full circles. |
| G03 | Circular interpolation CCW | Motion | G03 X_ Y_ R_ F_ or G03 X_ Y_ I_ J_ F_ | Yes | Counter-clockwise arc. Same rules as G02. |
| G04 | Dwell | Motion | G04 P_ (milliseconds) or G04 U_ (seconds) | No | Pauses program execution for specified time. Haas uses P in seconds (P1.0 = 1 sec). Fanuc P in milliseconds (P1000 = 1 sec). |
| G05 | High-speed machining mode | Motion | G05 P10000 (Fanuc HPCC) | Yes | Activates look-ahead and smoothing. Implementation varies significantly by control.[Fanuc, Haas only] |
| G09 | Exact stop (non-modal) | Motion | G09 G01 X_ Y_ F_ | No | Decelerates to zero at endpoint of this block only. Contrast with G61 (modal exact stop).[Fanuc, Haas, Mazak only] |
| G10 | Programmable data setting | Setup | G10 L2 P_ X_ Y_ Z_ (work offset) or G10 L11 P_ R_ (tool offset) | No | Set work offsets or tool offsets from the program. L2=work offset, L10/L11=tool geometry/wear.[Fanuc, Haas, Mazak only] |
| G12 | CW circular pocket milling | Motion | G12 I_ Z_ Q_ F_ | No | Haas-specific. Cuts a circular pocket CW. I=radius, Q=step increment.[Haas only] |
| G13 | CCW circular pocket milling | Motion | G13 I_ Z_ Q_ F_ | No | Haas-specific. Cuts a circular pocket CCW.[Haas only] |
| G17 | XY plane selection | Plane | G17 | Yes | Default plane. Arcs in XY, tool length comp in Z. |
| G18 | XZ plane selection | Plane | G18 | Yes | Arcs in XZ plane. Used for lathe C-axis or mill side profiles. |
| G19 | YZ plane selection | Plane | G19 | Yes | Arcs in YZ plane. |
| G20 | Inch mode | Units | G20 | Yes | All coordinates and feedrates in inches. Always specify at program start. |
| G21 | Metric mode | Units | G21 | Yes | All coordinates and feedrates in millimeters. |
| G28 | Return to machine home (via intermediate) | Reference | G28 X0 Y0 Z0 or G91 G28 Z0 | No | Moves through intermediate point, then to machine home. Haas: G28 goes through the specified point. Fanuc: identical behavior. Always safe-Z first with G91 G28 Z0.[Fanuc, Haas, Mazak only] |
| G29 | Return from reference point | Reference | G29 X_ Y_ Z_ | No | Moves from machine home back through intermediate point set by previous G28.[Fanuc, Haas only] |
| G30 | Return to 2nd reference point | Reference | G30 Z0 | No | Goes to second machine reference point. Often used for tool change position.[Fanuc, Haas, Mazak only] |
| G40 | Cutter compensation cancel | Compensation | G40 | Yes | Cancels G41/G42. Should be on a move line to allow proper ramp-off. |
| G41 | Cutter compensation left | Compensation | G41 D_ G01 X_ Y_ F_ | Yes | Tool offsets to the left of programmed path (climb milling on OD). D = offset register number. |
| G42 | Cutter compensation right | Compensation | G42 D_ G01 X_ Y_ F_ | Yes | Tool offsets to the right of programmed path (conventional milling on OD). |
| G43 | Tool length compensation + | Compensation | G43 H_ Z_ | Yes | Applies positive tool length offset. H = offset register (usually same as tool number). |
| G44 | Tool length compensation - | Compensation | G44 H_ Z_ | Yes | Applies negative tool length offset. Rarely used in modern practice.[Fanuc, Haas, Mazak only] |
| G49 | Tool length compensation cancel | Compensation | G49 | Yes | Cancels G43/G44. Usually not needed if G28 Z0 is used. |
| G50 | Max spindle speed clamp (Lathe) | Lathe | G50 S_ (max RPM) | Yes | Sets maximum spindle RPM when using G96 (CSS). Critical safety code for facing operations.[Fanuc, Haas, Mazak only] |
| G52 | Local coordinate system | Work Offset | G52 X_ Y_ Z_ | No | Temporary shift applied on top of current work offset. G52 X0 Y0 Z0 to cancel.[Fanuc, Haas, Mazak only] |
| G53 | Machine coordinate system (non-modal) | Work Offset | G53 G00 X_ Y_ Z_ | No | Moves in machine coordinates for this block only. Common for tool change position: G53 G00 Z0. |
| G54 | Work coordinate system 1 | Work Offset | G54 | Yes | First work offset. Most commonly used. Set via G10 or manually. |
| G55 | Work coordinate system 2 | Work Offset | G55 | Yes | Second work offset. Common for second vise or fixture. |
| G56 | Work coordinate system 3 | Work Offset | G56 | Yes | Third work offset. |
| G57 | Work coordinate system 4 | Work Offset | G57 | Yes | Fourth work offset. |
| G58 | Work coordinate system 5 | Work Offset | G58 | Yes | Fifth work offset. |
| G59 | Work coordinate system 6 | Work Offset | G59 | Yes | Sixth work offset. Additional offsets available via G54.1 P1-P48 (Haas) or similar. |
| G61 | Exact stop mode (modal) | Motion | G61 | Yes | Machine decelerates to zero at every block end. Sharp corners but slower cycle time. Cancel with G64.[Fanuc, Haas, Mazak only] |
| G64 | Cutting mode / constant velocity | Motion | G64 | Yes | Allows corner rounding for smoother motion. Default mode. Siemens: G64 with ADIS for tolerance control. |
| G68 | Coordinate rotation | Transformation | G68 X_ Y_ R_ (rotation center and angle) | Yes | Rotates the coordinate system around a center point. Cancel with G69.[Fanuc, Haas, Mazak only] |
| G69 | Cancel coordinate rotation | Transformation | G69 | Yes | Cancels G68 rotation.[Fanuc, Haas, Mazak only] |
| G73 | High-speed peck drilling (chip break) | Canned Cycle | G73 X_ Y_ Z_ R_ Q_ F_ | Yes | Short retract peck drill. Q = peck depth. Retracts only enough to break chip, faster than G83. |
| G74 | Left-hand tapping cycle | Canned Cycle | G74 X_ Y_ Z_ R_ F_ | Yes | Reverse tapping cycle. Spindle runs CCW, reverses at bottom.[Fanuc, Haas, Mazak only] |
| G76 | Fine boring cycle | Canned Cycle | G76 X_ Y_ Z_ R_ Q_ F_ | Yes | Mill: oriented spindle stop at bottom, shift away, retract. Lathe (Fanuc): threading cycle.[Fanuc, Haas, Mazak only] |
| G80 | Cancel canned cycle | Canned Cycle | G80 | Yes | Cancels all active canned cycles (G73, G81-G89). Always cancel before rapid moves. |
| G81 | Drill cycle (no peck) | Canned Cycle | G81 X_ Y_ Z_ R_ F_ | Yes | Simple drill to Z depth and retract. No peck. Good for shallow holes < 3x diameter. |
| G82 | Spot drill / counterbore cycle | Canned Cycle | G82 X_ Y_ Z_ R_ P_ F_ | Yes | Drill to depth with dwell (P) at bottom. P in seconds (Haas) or milliseconds (Fanuc). |
| G83 | Deep hole peck drilling | Canned Cycle | G83 X_ Y_ Z_ R_ Q_ F_ | Yes | Full retract peck drill. Retracts to R plane between pecks for chip clearing. Q = peck depth. |
| G84 | Right-hand tapping cycle | Canned Cycle | G84 X_ Y_ Z_ R_ F_ (rigid tap) or G84 X_ Y_ Z_ R_ J_ | Yes | Rigid tapping. F = 1/pitch for inch (e.g., 1/20 = 0.05 for 20 TPI). Haas: feedrate auto-calculated from spindle speed and pitch. |
| G85 | Boring cycle (feed out) | Canned Cycle | G85 X_ Y_ Z_ R_ F_ | Yes | Bore to depth, feed out at same rate. Leaves good finish on bore wall.[Fanuc, Haas, Mazak only] |
| G86 | Boring cycle (spindle stop, rapid out) | Canned Cycle | G86 X_ Y_ Z_ R_ F_ | Yes | Bore to depth, spindle stops, rapid retract. Will leave a drag mark.[Fanuc, Haas, Mazak only] |
| G87 | Back boring cycle | Canned Cycle | G87 X_ Y_ Z_ R_ Q_ F_ | Yes | Oriented spindle stop, rapid to bottom, shift, spindle on, bore upward.[Fanuc, Haas only] |
| G90 | Absolute positioning mode | Positioning | G90 | Yes | All coordinates relative to work origin. Most programs use G90. |
| G91 | Incremental positioning mode | Positioning | G91 | Yes | All coordinates relative to current position. Common with G28: G91 G28 Z0. |
| G92 | Work coordinate offset / Threading (Lathe) | Work Offset | G92 X_ Y_ Z_ (mill offset) or G92 X_ Z_ F_ (lathe thread) | No | Mill: sets current position as specified coordinates (shifts all offsets). Lathe (Fanuc): threading canned cycle. Avoid G92 for work offsets in modern programming - use G54-G59 instead.[Fanuc, Haas, Mazak only] |
| G93 | Inverse time feed mode | Feed | G93 | Yes | F value = 1/time in minutes to complete move. Used in 5-axis and rotary machining. |
| G94 | Feed per minute mode | Feed | G94 | Yes | F = inches/min (G20) or mm/min (G21). Default for milling. |
| G95 | Feed per revolution mode | Feed | G95 | Yes | F = inches/rev or mm/rev. Default for lathe turning. Also used for mill tapping. |
| G96 | Constant surface speed (Lathe) | Lathe | G96 S_ (SFM or m/min) | Yes | Spindle adjusts RPM as diameter changes to maintain constant SFM. Always set G50 S_ first for max RPM clamp.[Fanuc, Haas, Mazak only] |
| G97 | Constant RPM mode (Lathe) | Lathe | G97 S_ (RPM) | Yes | Fixed spindle speed. Use for drilling, threading, grooving on lathe. Also cancels G96.[Fanuc, Haas, Mazak only] |
| G98 | Return to initial Z level | Canned Cycle | G98 | Yes | After canned cycle, retract to initial Z (where cycle was called). Use when clearing clamps/fixtures.[Fanuc, Haas, Mazak only] |
| G99 | Return to R plane | Canned Cycle | G99 | Yes | After canned cycle, retract only to R plane. Faster for multiple holes at same height.[Fanuc, Haas, Mazak only] |
58 G-codes shown. Click column headers to sort.
G-code is the programming language used to control CNC machines. G-codes control motion (rapid, linear, circular), coordinate systems, canned cycles, and other machine functions. M-codes control auxiliary functions like spindle, coolant, and tool changes.
G28 sends the machine to its reference (home) position. The machine moves through an intermediate point specified in the command. G91 G28 Z0 is the safe idiom to rapid the Z axis home from its current position.
G90 is absolute positioning where coordinates reference the work origin. G91 is incremental positioning where coordinates reference the current position. Most programs use G90 for the main code and G91 for specific moves like G28.