CNC G-codes and M-codes are the fundamental commands that control machine movement, spindle operation, tool changes, and machining cycles. Every CNC programmer, machinist, and operator relies on these commands to control machining processes.
This cheat sheet provides a practical quick-reference guide covering the most commonly used G-codes and M-codes along with real CNC program examples used in milling and machining centers.
This page is designed to function as a bookmarkable reference for CNC operators and programmers.
══════════════════════════════════════════════════════════════════════════════
SECTION 1 — RAPID POSITIONING (G00)
G00 is used for rapid positioning moves where the tool travels at maximum machine speed.
Example
G00 X0 Y0
The machine moves rapidly to the specified coordinates.
Typical use cases:
- Moving between machining positions
- Moving above the workpiece
- Positioning before cutting begins
Safety note:
Always retract to safe Z height before rapid XY moves.
Example safe move
G00 Z100
G00 X50 Y50
══════════════════════════════════════════════════════════════════════════════
SECTION 2 — LINEAR CUTTING MOVE (G01)
G01 performs linear interpolation at a programmed feedrate.
Example
G01 X50 Y25 F200
This command moves the tool in a straight line while cutting.
Common use cases:
- Slot milling
- Contour cutting
- Pocket machining
Feedrate must always be defined when using G01.
Example
G01 Z-5 F150
══════════════════════════════════════════════════════════════════════════════
SECTION 3 — CIRCULAR INTERPOLATION (G02 / G03)
Circular interpolation is used for arcs and circular movements.
G02 = clockwise arc
G03 = counterclockwise arc
Example
G02 X50 Y50 I10 J0
This command creates a clockwise arc ending at X50 Y50 with arc center offset defined by I and J values.
Common machining operations:
- circular pockets
- radius corners
- bore finishing
══════════════════════════════════════════════════════════════════════════════
SECTION 4 — ABSOLUTE VS INCREMENTAL POSITIONING (G90 / G91)
G90 activates absolute positioning.
Example
G90
G01 X100 Y50
The machine moves to exact coordinates from program zero.
G91 activates incremental positioning.
Example
G91
G01 X10 Y10
The machine moves relative to its current position.
Incremental positioning is often used in repetitive patterns.
══════════════════════════════════════════════════════════════════════════════
SECTION 5 — WORK COORDINATE SYSTEMS (G54 – G59)
Work coordinate systems define the location of the part on the machine table.
Example
G54
This activates the first work coordinate offset.
Additional offsets include:
G55
G56
G57
G58
G59
These allow multiple setups within the same machine program.
Example
G54 (part 1)
G55 (part 2)
══════════════════════════════════════════════════════════════════════════════
SECTION 6 — DRILLING CYCLES (G81 / G83)
Drilling cycles automate repetitive drilling operations.
Example simple drilling cycle
G81 X20 Y20 Z-15 R2 F120
This performs:
- rapid move to X20 Y20
- drill to Z-15
- retract to R2 plane
Peck drilling example
G83 X30 Y30 Z-25 R2 Q5 F120
This breaks chips during deep drilling by retracting periodically.
══════════════════════════════════════════════════════════════════════════════
SECTION 7 — SPINDLE CONTROL (M03 / M04 / M05)
Spindle commands control tool rotation.
M03 — spindle clockwise
M04 — spindle counterclockwise
M05 — spindle stop
Example
S3000 M03
The spindle rotates clockwise at 3000 RPM.
══════════════════════════════════════════════════════════════════════════════
SECTION 8 — TOOL CHANGE (M06)
M06 performs automatic tool change.
Example
T2 M06
The machine loads tool number 2 from the tool magazine.
Tool changes should always occur at a safe retract height.
Example
G00 Z100
T2 M06
══════════════════════════════════════════════════════════════════════════════
SECTION 9 — COOLANT CONTROL (M08 / M09)
Coolant commands manage cutting fluid flow.
M08 — coolant on
M09 — coolant off
Example
M08
Coolant begins flowing before cutting operation.
Coolant improves tool life and removes heat during machining.
══════════════════════════════════════════════════════════════════════════════
SECTION 10 — PROGRAM END (M30)
M30 marks the end of the CNC program.
Example
M30
This command:
- stops the program
- rewinds to the beginning
- prepares the machine for the next cycle
Programs typically end with:
M05
M09
G00 Z100
M30
══════════════════════════════════════════════════════════════════════════════
FINAL PRINCIPLE
G-codes and M-codes form the foundation of CNC programming. Understanding how each command affects machine behavior allows machinists to create safe, efficient, and reliable machining programs.
A well-structured CNC program combines motion commands, spindle control, coordinate systems, and machining cycles into a predictable and repeatable manufacturing process.
Leave a comment