G-code is the universal programming language used to control CNC machine movement, cutting operations, and machine behavior. Most modern CNC controllers such as Fanuc, Haas, Siemens, Mitsubishi and other industrial systems rely on the same fundamental programming structure based on ISO CNC standards.
While some machine-specific variations exist, the majority of motion, tool, drilling, and offset commands remain consistent across modern CNC machining centers and turning machines.
This reference page documents the most widely used modern CNC G-codes and M-codes along with real programming examples used in milling and turning operations.
══════════════════════════════════════════════
SECTION 1 — BASIC CNC PROGRAM STRUCTURE
══════════════════════════════════════════════
Typical CNC program format
%
O1001
G90 G17 G40 G49 G80
G54
T1 M06
S3000 M03
G00 G43 Z100 H01
This block initializes machine safety states and prepares the spindle and tool.
══════════════════════════════════════════════
SECTION 2 — MOTION CONTROL G-CODES
══════════════════════════════════════════════
G00 Rapid Positioning
Moves the tool rapidly without cutting.
Example
G00 X0 Y0 Z100
G01 Linear Interpolation
Controlled cutting movement at feedrate.
Example
G01 X50 Y20 F200
G02 Circular Interpolation CW
Example
G02 X60 Y40 I20 J0 F150
G03 Circular Interpolation CCW
Example
G03 X20 Y20 I-10 J0 F150
══════════════════════════════════════════════
SECTION 3 — PLANE SELECTION
══════════════════════════════════════════════
G17 XY Plane
Standard milling plane.
G18 ZX Plane
Used in turning or special toolpaths.
G19 YZ Plane
Example
G17
══════════════════════════════════════════════
SECTION 4 — COORDINATE SYSTEMS
══════════════════════════════════════════════
Work coordinate systems define part zero.
G54
G55
G56
G57
G58
G59
Example
G54
G00 X0 Y0
══════════════════════════════════════════════
SECTION 5 — TOOL COMPENSATION
══════════════════════════════════════════════
G40 Cancel Cutter Compensation
G41 Cutter Compensation Left
G42 Cutter Compensation Right
Example
G41 D01
══════════════════════════════════════════════
SECTION 6 — DRILLING CYCLES
══════════════════════════════════════════════
Modern CNC machines use canned cycles for automated drilling operations.
G81 Standard Drilling
Example
G81 X20 Y20 Z-15 R2 F150
G83 Peck Drilling
Example
G83 X30 Y30 Z-25 R2 Q5 F120
G84 Tapping Cycle
Example
G84 X10 Y10 Z-12 R2 F1.5
G80 Cancel Drilling Cycle
══════════════════════════════════════════════
SECTION 7 — MACHINE CONTROL M-CODES
══════════════════════════════════════════════
M-codes control machine functions such as spindle, coolant and tool changes.
M00 Program Stop
M01 Optional Stop
M02 Program End
M03 Spindle Clockwise
M04 Spindle Counter-Clockwise
M05 Spindle Stop
M06 Tool Change
M08 Coolant ON
M09 Coolant OFF
M30 Program End and Reset
Example
S2500 M03
M08
══════════════════════════════════════════════
SECTION 8 — ADVANCED CNC COMMANDS
══════════════════════════════════════════════
G28 Machine Home Return
Example
G28 Z0
G10 Programmable Offset Setting
Example
G10 L2 P1 X0 Y0 Z0
G04 Dwell Command
Example
G04 P2
══════════════════════════════════════════════
SECTION 9 — REAL MILLING PROGRAM EXAMPLE
══════════════════════════════════════════════
%
O2001
G90 G17 G40 G49 G80
G54
T1 M06
S3000 M03
G00 G43 Z100 H01
G00 X0 Y0
G01 Z-5 F200
G01 X50
G01 Y50
G01 X0
G01 Y0
G00 Z100
M30
══════════════════════════════════════════════
SECTION 10 — CNC PROGRAMMING BEST PRACTICES
══════════════════════════════════════════════
Professional CNC programmers follow several safety rules.
Always use safe start blocks.
Verify work offsets before cutting.
Perform dry run simulation before machining.
Use single-block testing for new programs.
These practices reduce the risk of crashes and ensure reliable machining operations.
══════════════════════════════════════════════
FINAL PRINCIPLE
Modern CNC programming relies on standardized G-codes for motion control and M-codes for machine functions. By mastering the most common commands and understanding their practical applications, programmers and machine operators can develop safe, efficient, and reliable machining programs for a wide range of CNC machines.
Leave a comment