G-Code and M-Code Reference

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

CodeDescriptionCategorySyntaxModalNotes
G00Rapid positioningMotionG00 X_ Y_ Z_YesMoves at max traverse rate. NOT linear - axes move independently. Never use for cutting.
G01Linear interpolation (feed)MotionG01 X_ Y_ Z_ F_YesStraight line cutting move at specified feedrate. Requires F word.
G02Circular interpolation CWMotionG02 X_ Y_ R_ F_ or G02 X_ Y_ I_ J_ F_YesClockwise arc. R format for arcs < 180 deg. I/J format for any arc including full circles.
G03Circular interpolation CCWMotionG03 X_ Y_ R_ F_ or G03 X_ Y_ I_ J_ F_YesCounter-clockwise arc. Same rules as G02.
G04DwellMotionG04 P_ (milliseconds) or G04 U_ (seconds)NoPauses program execution for specified time. Haas uses P in seconds (P1.0 = 1 sec). Fanuc P in milliseconds (P1000 = 1 sec).
G05High-speed machining modeMotionG05 P10000 (Fanuc HPCC)YesActivates look-ahead and smoothing. Implementation varies significantly by control.[Fanuc, Haas only]
G09Exact stop (non-modal)MotionG09 G01 X_ Y_ F_NoDecelerates to zero at endpoint of this block only. Contrast with G61 (modal exact stop).[Fanuc, Haas, Mazak only]
G10Programmable data settingSetupG10 L2 P_ X_ Y_ Z_ (work offset) or G10 L11 P_ R_ (tool offset)NoSet work offsets or tool offsets from the program. L2=work offset, L10/L11=tool geometry/wear.[Fanuc, Haas, Mazak only]
G12CW circular pocket millingMotionG12 I_ Z_ Q_ F_NoHaas-specific. Cuts a circular pocket CW. I=radius, Q=step increment.[Haas only]
G13CCW circular pocket millingMotionG13 I_ Z_ Q_ F_NoHaas-specific. Cuts a circular pocket CCW.[Haas only]
G17XY plane selectionPlaneG17YesDefault plane. Arcs in XY, tool length comp in Z.
G18XZ plane selectionPlaneG18YesArcs in XZ plane. Used for lathe C-axis or mill side profiles.
G19YZ plane selectionPlaneG19YesArcs in YZ plane.
G20Inch modeUnitsG20YesAll coordinates and feedrates in inches. Always specify at program start.
G21Metric modeUnitsG21YesAll coordinates and feedrates in millimeters.
G28Return to machine home (via intermediate)ReferenceG28 X0 Y0 Z0 or G91 G28 Z0NoMoves 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]
G29Return from reference pointReferenceG29 X_ Y_ Z_NoMoves from machine home back through intermediate point set by previous G28.[Fanuc, Haas only]
G30Return to 2nd reference pointReferenceG30 Z0NoGoes to second machine reference point. Often used for tool change position.[Fanuc, Haas, Mazak only]
G40Cutter compensation cancelCompensationG40YesCancels G41/G42. Should be on a move line to allow proper ramp-off.
G41Cutter compensation leftCompensationG41 D_ G01 X_ Y_ F_YesTool offsets to the left of programmed path (climb milling on OD). D = offset register number.
G42Cutter compensation rightCompensationG42 D_ G01 X_ Y_ F_YesTool offsets to the right of programmed path (conventional milling on OD).
G43Tool length compensation +CompensationG43 H_ Z_YesApplies positive tool length offset. H = offset register (usually same as tool number).
G44Tool length compensation -CompensationG44 H_ Z_YesApplies negative tool length offset. Rarely used in modern practice.[Fanuc, Haas, Mazak only]
G49Tool length compensation cancelCompensationG49YesCancels G43/G44. Usually not needed if G28 Z0 is used.
G50Max spindle speed clamp (Lathe)LatheG50 S_ (max RPM)YesSets maximum spindle RPM when using G96 (CSS). Critical safety code for facing operations.[Fanuc, Haas, Mazak only]
G52Local coordinate systemWork OffsetG52 X_ Y_ Z_NoTemporary shift applied on top of current work offset. G52 X0 Y0 Z0 to cancel.[Fanuc, Haas, Mazak only]
G53Machine coordinate system (non-modal)Work OffsetG53 G00 X_ Y_ Z_NoMoves in machine coordinates for this block only. Common for tool change position: G53 G00 Z0.
G54Work coordinate system 1Work OffsetG54YesFirst work offset. Most commonly used. Set via G10 or manually.
G55Work coordinate system 2Work OffsetG55YesSecond work offset. Common for second vise or fixture.
G56Work coordinate system 3Work OffsetG56YesThird work offset.
G57Work coordinate system 4Work OffsetG57YesFourth work offset.
G58Work coordinate system 5Work OffsetG58YesFifth work offset.
G59Work coordinate system 6Work OffsetG59YesSixth work offset. Additional offsets available via G54.1 P1-P48 (Haas) or similar.
G61Exact stop mode (modal)MotionG61YesMachine decelerates to zero at every block end. Sharp corners but slower cycle time. Cancel with G64.[Fanuc, Haas, Mazak only]
G64Cutting mode / constant velocityMotionG64YesAllows corner rounding for smoother motion. Default mode. Siemens: G64 with ADIS for tolerance control.
G68Coordinate rotationTransformationG68 X_ Y_ R_ (rotation center and angle)YesRotates the coordinate system around a center point. Cancel with G69.[Fanuc, Haas, Mazak only]
G69Cancel coordinate rotationTransformationG69YesCancels G68 rotation.[Fanuc, Haas, Mazak only]
G73High-speed peck drilling (chip break)Canned CycleG73 X_ Y_ Z_ R_ Q_ F_YesShort retract peck drill. Q = peck depth. Retracts only enough to break chip, faster than G83.
G74Left-hand tapping cycleCanned CycleG74 X_ Y_ Z_ R_ F_YesReverse tapping cycle. Spindle runs CCW, reverses at bottom.[Fanuc, Haas, Mazak only]
G76Fine boring cycleCanned CycleG76 X_ Y_ Z_ R_ Q_ F_YesMill: oriented spindle stop at bottom, shift away, retract. Lathe (Fanuc): threading cycle.[Fanuc, Haas, Mazak only]
G80Cancel canned cycleCanned CycleG80YesCancels all active canned cycles (G73, G81-G89). Always cancel before rapid moves.
G81Drill cycle (no peck)Canned CycleG81 X_ Y_ Z_ R_ F_YesSimple drill to Z depth and retract. No peck. Good for shallow holes < 3x diameter.
G82Spot drill / counterbore cycleCanned CycleG82 X_ Y_ Z_ R_ P_ F_YesDrill to depth with dwell (P) at bottom. P in seconds (Haas) or milliseconds (Fanuc).
G83Deep hole peck drillingCanned CycleG83 X_ Y_ Z_ R_ Q_ F_YesFull retract peck drill. Retracts to R plane between pecks for chip clearing. Q = peck depth.
G84Right-hand tapping cycleCanned CycleG84 X_ Y_ Z_ R_ F_ (rigid tap) or G84 X_ Y_ Z_ R_ J_YesRigid tapping. F = 1/pitch for inch (e.g., 1/20 = 0.05 for 20 TPI). Haas: feedrate auto-calculated from spindle speed and pitch.
G85Boring cycle (feed out)Canned CycleG85 X_ Y_ Z_ R_ F_YesBore to depth, feed out at same rate. Leaves good finish on bore wall.[Fanuc, Haas, Mazak only]
G86Boring cycle (spindle stop, rapid out)Canned CycleG86 X_ Y_ Z_ R_ F_YesBore to depth, spindle stops, rapid retract. Will leave a drag mark.[Fanuc, Haas, Mazak only]
G87Back boring cycleCanned CycleG87 X_ Y_ Z_ R_ Q_ F_YesOriented spindle stop, rapid to bottom, shift, spindle on, bore upward.[Fanuc, Haas only]
G90Absolute positioning modePositioningG90YesAll coordinates relative to work origin. Most programs use G90.
G91Incremental positioning modePositioningG91YesAll coordinates relative to current position. Common with G28: G91 G28 Z0.
G92Work coordinate offset / Threading (Lathe)Work OffsetG92 X_ Y_ Z_ (mill offset) or G92 X_ Z_ F_ (lathe thread)NoMill: 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]
G93Inverse time feed modeFeedG93YesF value = 1/time in minutes to complete move. Used in 5-axis and rotary machining.
G94Feed per minute modeFeedG94YesF = inches/min (G20) or mm/min (G21). Default for milling.
G95Feed per revolution modeFeedG95YesF = inches/rev or mm/rev. Default for lathe turning. Also used for mill tapping.
G96Constant surface speed (Lathe)LatheG96 S_ (SFM or m/min)YesSpindle adjusts RPM as diameter changes to maintain constant SFM. Always set G50 S_ first for max RPM clamp.[Fanuc, Haas, Mazak only]
G97Constant RPM mode (Lathe)LatheG97 S_ (RPM)YesFixed spindle speed. Use for drilling, threading, grooving on lathe. Also cancels G96.[Fanuc, Haas, Mazak only]
G98Return to initial Z levelCanned CycleG98YesAfter canned cycle, retract to initial Z (where cycle was called). Use when clearing clamps/fixtures.[Fanuc, Haas, Mazak only]
G99Return to R planeCanned CycleG99YesAfter 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.

Frequently Asked Questions

What is G-code?

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.

What does G28 do?

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.

What is the difference between G90 and G91?

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.

Related Tools