Quick reference guide for common G-codes (preparatory functions) and M-codes (miscellaneous functions) used in CNC programming. Use the search and filters to find specific codes.

G-Codes (Preparatory Functions)

G-codes prepare the machine for specific operations - motion, cycles, modes, and compensation.

Canned Cycle

G73 High-Speed Peck Drilling Cycle
Usage: G73 Z__ R__ Q__ F__
Example: G73 Z-2.0 R0.1 Q0.2 F6.0
Notes: Q is peck increment. Tool does not fully retract between pecks.
Used on: Mill
G74 Left-Hand Tapping Cycle
Usage: G74 Z__ R__ F__
Notes: For left-hand threads. Spindle reverses direction.
Used on: Mill
G76 Threading Cycle (Lathe)
Usage: G76 P__ Q__ R__ / G76 X__ Z__ P__ Q__ F__
Example: G76 P010060 Q0100 R0.02
Notes: Complex code with multiple parameters. Varies by control.
Used on: Lathe
G80 Cancel Canned Cycle
Usage: G80
Notes: Cancels all active canned cycles (G73-G89).
Used on: Both
G81 Drill Cycle
Usage: G81 X__ Y__ Z__ R__ F__
Example: G81 Z-0.75 R0.1 F6.0
Notes: Z is hole depth, R is retract plane/clearance height.
Used on: Mill
G82 Spot/Counterbore Cycle
Usage: G82 X__ Y__ Z__ R__ P__ F__
Example: G82 Z-0.2 R0.1 P0.5 F4.0
Notes: P is dwell time at bottom in seconds.
Used on: Mill
G83 Peck Drilling Cycle
Usage: G83 X__ Y__ Z__ R__ Q__ F__
Example: G83 Z-2.0 R0.1 Q0.25 F6.0
Notes: Q is peck depth. Tool fully retracts to R plane between pecks.
Used on: Mill
G84 Tapping Cycle
Usage: G84 X__ Y__ Z__ R__ F__
Example: G84 Z-0.75 R0.1 F25.0
Notes: F = RPM / TPI. Spindle must be in RPM mode (G97).
Used on: Mill
G85 Boring Cycle
Usage: G85 X__ Y__ Z__ R__ F__
Notes: Feeds in and out. No dwell.
Used on: Mill
G86 Boring Cycle (Spindle Stop)
Usage: G86 X__ Y__ Z__ R__ F__
Notes: Spindle stops at bottom, rapids out. Avoids tool marks.
Used on: Mill
G89 Boring Cycle (Dwell)
Usage: G89 X__ Y__ Z__ R__ P__ F__
Notes: Dwells at bottom, feeds out. Best finish.
Used on: Mill
G98 Return to Initial Point (R)
Usage: G98
Notes: In canned cycles, returns to R clearance plane between holes.
Used on: Mill
G99 Return to R Point
Usage: G99
Notes: In canned cycles, returns only to R plane (faster when R is close to part).
Used on: Mill

Compensation

G40 Cancel Cutter Compensation
Usage: G40
Notes: Cancels G41/G42. Tool follows programmed path exactly.
Used on: Mill
G41 Cutter Compensation Left
Usage: G41 D__
Example: G41 D01
Notes: Tool offsets to the left of the programmed path by diameter offset amount.
Used on: Mill
G42 Cutter Compensation Right
Usage: G42 D__
Example: G42 D01
Notes: Tool offsets to the right of the programmed path by diameter offset amount.
Used on: Mill
G43 Tool Length Compensation +
Usage: G43 H__
Example: G43 H01 Z1.0
Notes: Adds tool length offset to Z position. H is offset register number.
Used on: Mill
G44 Tool Length Compensation -
Usage: G44 H__
Notes: Subtracts tool length offset. Rarely used.
Used on: Mill
G49 Cancel Tool Length Compensation
Usage: G49
Notes: Cancels G43/G44.
Used on: Mill

Coordinate

G50 Coordinate System Setting / Max Spindle Speed
Usage: G50 S__ (lathe) or G50 X__ Y__ Z__ (mill)
Example: G50 S3000 (limit spindle to 3000 RPM)
Notes: Usage varies by machine type and control.
Used on: Lathe
G52 Local Coordinate System
Usage: G52 X__ Y__ Z__
Notes: Temporary shift of work coordinate system.
Used on: Both
G53 Machine Coordinate System
Usage: G53 G00 X__ Y__ Z__
Example: G53 G00 Z0 (rapid Z to machine home)
Notes: Single-block command. Moves in machine coordinates.
Used on: Both
G54 Work Offset 1
Usage: G54
Notes: Most commonly used work offset.
Used on: Both
G55 Work Offset 2
Usage: G55
Used on: Both
G56 Work Offset 3
Usage: G56
Used on: Both
G57 Work Offset 4
Usage: G57
Used on: Both
G58 Work Offset 5
Usage: G58
Used on: Both
G59 Work Offset 6
Usage: G59
Used on: Both
G92 Set Work Coordinate / Threading (Lathe)
Usage: G92 X__ Y__ Z__ (mill) or G92 threading code (lathe)
Notes: Usage varies widely. On mills, shifts work coordinate. On lathes, used for threading.
Used on: Both

Feed

G94 Feed Per Minute Mode
Usage: G94
Notes: Feed rate in inches/mm per minute (IPM/mm/min). Default for mills.
Used on: Both
G95 Feed Per Revolution Mode
Usage: G95
Notes: Feed rate in inches/mm per spindle revolution. Common for lathes.
Used on: Lathe

Mode

G90 Absolute Positioning Mode
Usage: G90
Notes: All coordinates measured from work zero. Most common mode.
Used on: Both
G91 Incremental Positioning Mode
Usage: G91
Notes: Coordinates measured from current position. Use with care.
Used on: Both

Motion

G00 Rapid Positioning
Usage: G00 X__ Y__ Z__
Example: G00 X2.0 Y3.0 Z1.0
Notes: Moves at maximum feed rate. Do not use for cutting.
Used on: Both
G01 Linear Interpolation (Feed Move)
Usage: G01 X__ Y__ Z__ F__
Example: G01 X2.0 Y3.0 F10.0
Notes: Moves at specified feed rate. Used for cutting.
Used on: Both
G02 Circular Interpolation Clockwise
Usage: G02 X__ Y__ I__ J__ F__ or G02 X__ Y__ R__ F__
Example: G02 X2.0 Y2.0 I1.0 J0 F8.0
Notes: I, J, K are arc center offsets from start point. R is arc radius.
Used on: Both
G03 Circular Interpolation Counter-Clockwise
Usage: G03 X__ Y__ I__ J__ F__ or G03 X__ Y__ R__ F__
Example: G03 X0 Y0 I-1.0 J0 F8.0
Notes: Same as G02 but in opposite direction.
Used on: Both
G04 Dwell (Pause)
Usage: G04 P__ or G04 X__
Example: G04 P2.0 (pause 2 seconds)
Notes: P is in seconds, X may be in seconds or milliseconds depending on control.
Used on: Both
G28 Return to Home Position
Usage: G28 X__ Y__ Z__
Example: G28 G91 Z0 (return Z to home)
Notes: Machine returns to machine home through specified intermediate point.
Used on: Both

Plane

G17 XY Plane Selection
Usage: G17
Notes: Default for milling. Arcs in XY plane, Z is perpendicular.
Used on: Mill
G18 XZ Plane Selection
Usage: G18
Notes: Common for lathes. Arcs in XZ plane, Y is perpendicular.
Used on: Lathe
G19 YZ Plane Selection
Usage: G19
Notes: Arcs in YZ plane, X is perpendicular.
Used on: Mill

Spindle

G96 Constant Surface Speed (CSS)
Usage: G96 S__
Example: G96 S500 (500 SFM)
Notes: RPM varies to maintain constant surface speed. Lathe turning.
Used on: Lathe
G97 Constant RPM Mode
Usage: G97 S__
Example: G97 S1200
Notes: Spindle runs at fixed RPM. Default mode.
Used on: Both

Units

G20 Inch Programming
Usage: G20
Notes: All coordinates interpreted as inches.
Used on: Both
G21 Metric Programming (mm)
Usage: G21
Notes: All coordinates interpreted as millimeters.
Used on: Both

M-Codes (Miscellaneous Functions)

M-codes control machine functions like spindle, coolant, tool changes, and program flow.

Coolant

M08 Coolant On (Flood)
Usage: M08
Notes: Turns on flood coolant or default coolant mode.
Used on: Both
M09 Coolant Off
Usage: M09
Notes: Turns off all coolant.
Used on: Both

Program Control

M00 Program Stop
Usage: M00
Notes: Machine stops. Must press cycle start to continue.
Used on: Both
M01 Optional Stop
Usage: M01
Notes: Stops only if optional stop switch is ON. Used for inspections.
Used on: Both
M02 Program End
Usage: M02
Notes: Ends program. Does not reset to start.
Used on: Both
M30 Program End and Reset
Usage: M30
Notes: Ends program and resets to beginning. Most commonly used ending.
Used on: Both

Spindle

M03 Spindle On Clockwise
Usage: M03 or S____ M03
Example: S2000 M03
Notes: Most common direction for milling.
Used on: Both
M04 Spindle On Counter-Clockwise
Usage: M04 or S____ M04
Notes: Used for tapping, left-hand tools, or thread milling.
Used on: Both
M05 Spindle Stop
Usage: M05
Notes: Stops spindle rotation.
Used on: Both
M19 Spindle Orientation
Usage: M19
Notes: Rotates spindle to fixed angular position. Used for tool changes or probing.
Used on: Both

Subprogram

M98 Call Subprogram
Usage: M98 P____ or M98 P____ L____
Example: M98 P1000 L3 (call O1000 three times)
Notes: P is subprogram number, L is number of loops.
Used on: Both
M99 Return from Subprogram
Usage: M99
Notes: Returns to main program from subprogram.
Used on: Both

Tool

M06 Tool Change
Usage: T__ M06
Example: T2 M06 (change to tool 2)
Notes: Executes automatic tool change.
Used on: Mill