FANUC G-Code Reference for CNC Mills (2025)

By Nishikant Xalxo | FANUC CNC Milling Operator | Updated: January 10, 2025 | 15 min read

Having worked with FANUC 0i-MF and 30i-B controls for six years in aerospace manufacturing, I've compiled this definitive reference for programmers and operators. Unlike generic guides, this focuses on real-world applications and common pitfalls.

Essential FANUC G-Codes for Milling

G-Code Function Group Notes
G00 Rapid Positioning 01 Non-interpolated, use for positioning only
G01 Linear Interpolation 01 Requires feed rate (F)
G02/G03 Circular Interpolation 01 Clockwise/Counterclockwise
G04 Dwell 00 G04 X1.0 (dwell 1 second)
G17/G18/G19 Plane Selection 02 XY/ZX/YZ plane
G20/G21 Unit Selection 06 Inches (G20) / Metric (G21)
G28 Return to Reference 00 G28 G91 Z0 (safe Z return)
G40/G41/G42 Cutter Compensation 07 Cancel/Left/Right compensation
G43/G49 Tool Length Compensation 08 Apply/Cancel tool length
G54-G59 Work Offsets 12 Work coordinate systems

Common FANUC M-Codes

Example: Safe Tool Change Sequence
G91 G28 Z0        ; Return Z to home
M05                ; Spindle stop
M09                ; Coolant off
G00 G90 G54 X0 Y0  ; Move to safe position
M06 T02            ; Tool change to tool 2
M03 S2500          ; Spindle on clockwise at 2500 RPM
G43 H02 Z1.0       ; Apply tool length offset

Macro B Programming (FANUC 0i and 30i)

FANUC's macro B capability allows parameterized programming. Here's a real example I use for bolt hole patterns:

Macro for Bolt Hole Circle
#100 = 4          ; Number of holes
#101 = 50.0       ; Radius
#102 = 0          ; Starting angle
#103 = 90         ; Angle increment (360/#100)
#104 = 1          ; Counter

N10 WHILE [#104 LE #100] DO1
  #105 = #101 * COS[#102]
  #106 = #101 * SIN[#102]
  G81 X#105 Y#106 Z-10.0 R1.0 F15.0
  #102 = #102 + #103
  #104 = #104 + 1
END1
G80

Common Pitfalls & Solutions

1. Alarm PS0001 "Program Error": Usually caused by missing decimal points in feed rates or coordinates. Always use F100.0 not F100 when in metric mode.

2. Cutter Comp Alarms (PS0041): Ensure lead-in move is > tool radius and in correct plane (G17). Use G01 approach, never G00.

3. Tool Length Comp Cancel: Always cancel G43 before M30. Use G49 or G28 G91 Z0 to avoid crashes.

Tool Life Management (FANUC 30i-B)

FANUC 30i-B supports tool life counting via system variables:

About the Author: Nishikant Xalxo has operated FANUC CNC mills for 6+ years in aerospace manufacturing. He built SHADER7 to provide free tools for machinists worldwide. Contact: nxdecore@gmail.com

Further Reading: Check out our FANUC Macro B Programming Guide for advanced techniques.