Ultimate CNC G-Code & M-Code Dictionary (2025 Edition)
This reference is designed as a long-life “evergreen” CNC code dictionary: a single page you can bookmark, share, and come back to every time you see an unfamiliar line in a program. It focuses on the most widely used Fanuc/Haas-style G-codes and M-codes, with clean explanations and real production examples.
Note: Exact behavior can vary by control and machine builder, but the logic and usage patterns here match what most modern FANUC, Haas, Mitsubishi and compatible controls expect.
1. How to Use This CNC Code Dictionary
- Use Ctrl+F / search in page: type
G71orM30to jump straight to that code. - Each code includes:
- Plain English meaning
- Typical usage
- A realistic example line
- Codes are grouped by function, not just numerical order, so you can understand the logic of a program, not just memorize numbers.
2. Core Motion & Interpolation G-Codes
G00 – Rapid Positioning
- Fast, non-cutting moves between positions.
- Use for safe clearance moves, tool changes, and positioning above the part.
- Example:
G00 X0. Y0. Z100.
G01 – Linear Interpolation (Feed Move)
- Straight line cutting at programmed feedrate.
- Used for almost all profile milling/turning.
- Example:
G01 X50. Y20. Z-5. F800
G02 / G03 – Circular Interpolation
- G02 = clockwise arc, G03 = counterclockwise arc (as seen from +Z).
- Requires end point and either radius R or I/J center offsets.
- Example (arc with radius):
G03 X40. Y60. R10. F600
G04 – Dwell
- Pause motion for a specified time (P in ms or X in seconds, control-dependent).
- Use for letting spindle stabilize, coolant build up, or tapping dwell.
- Example:
G04 P500 (0.5 second dwell)
3. Units, Coordinate System & Feed Modes
G20 / G21 – Inch / Metric
- G20 = inches, G21 = millimeters.
- Set once near top of program; don’t mix.
- Example:
G21 (All dimensions in mm)
G90 / G91 – Absolute / Incremental Positioning
- G90: Positions given from work zero (G54, etc.).
- G91: Positions given as increments from current point.
- Example safe retract:
G91 G28 Z0.
G90
G93 / G94 / G95 – Feed Modes
- G94 = feed per minute (standard for milling).
- G95 = feed per revolution (standard for turning).
- G93 = inverse time (common in 5-axis).
- Example (milling default):
G94 F1200
G17 / G18 / G19 – Plane Selection
- G17 = XY plane (milling default).
- G18 = ZX plane (turning, front face).
- G19 = YZ plane.
- Example (milling setup line):
G17 G90 G40 G80
4. Work Offsets & Coordinate Presets
G54–G59 – Standard Work Offsets
- Each defines a different work coordinate system.
- Common pattern: G54 = first vise, G55 = second vise, etc.
- Example:
G54
G00 X0. Y0.
G54.1 P1–P48 – Extended Work Offsets
- Additional offsets for pallet systems, fixture plates, multi-part setups.
- Example:
G54.1 P5 (Use extended offset #5)
G92 – Coordinate Preset (NOT threading)
- Temporarily redefines the current position as specific coordinates.
- Used less often today; replaced by work offsets and G10.
- Example:
G92 X0. Y0. Z0.
G10 – Programmable Offset Setting
- Write values directly into G54/G55/etc. from a program.
- Used with probing/macros for full automation.
- Example:
G10 L2 P1 X125.40 Y60.20 Z-12.30 (Set G54)
5. Tool Length, Radii & Compensation
G43 – Tool Length Compensation (Positive)
- Applies tool length stored in H register.
- Almost every mill program uses it.
- Example:
T12 M06
G43 H12 Z100.
G43.4 – TCP / Tool Center Point Control (5-Axis)
- Maintains tool tip position as rotary axes move in 5-axis machining.
- Essential for accurate 5-axis work.
- Example:
G43.4 H8
G01 X120. Y40. Z-15. A30. C110. F2000
G41 / G42 – Cutter Radius Compensation
- G41 = tool left of path, G42 = tool right of path (relative to motion).
- Allows you to program nominal geometry and adjust size at the machine.
- Example:
G41 D12 X30. Y10. F800
G40 – Cancel Cutter Compensation
- Always cancel before leaving a profile or retracting.
- Example:
G40 X0. Y0.
6. Drilling, Tapping & Boring Cycles (Milling)
G80 – Cancel Canned Cycle
- Always end G81–G89 cycles with G80.
G81 – Simple Drilling Cycle
- Rapid to R plane, drill to Z, retract to R.
- Example:
G81 X25. Y30. Z-18. R2. F250
G83 – Deep Hole Peck Drilling
- Full retract peck drilling, ideal for deep holes and tough materials.
- Example:
G83 X40. Y22. Z-60. R2. Q5. F160
G73 – High-Speed Peck Drilling
- Shallow retract, very fast; best for shallow to medium holes.
- Example:
G73 X30. Y20. Z-12. R2. Q2. F250
G84 – Tapping Cycle (Rigid Tapping)
- Synchronizes feed to spindle for tapping. F = pitch, not mm/min.
- Example (M8 × 1.25):
S1200 M03
G84 X50. Y40. Z-12. R2. F1.25
G85–G89 – Boring & Dwell Cycles
- G85: boring, no dwell, no rapid out.
- G86: boring, spindle stop, rapid out.
- G88 / G89: boring with dwell and/or manual operator interaction (on some controls).
7. Roughing & Finishing Cycles (Turning)
G71 – Rough Turning Cycle (OD/ID)
- Automatic multi-pass roughing based on a defined profile.
- Example:
G71 U2.0 R0.5
G71 P100 Q200 U0.3 W0.1 F0.25
G72 – Facing Cycle
- Roughing from outer edge toward center face.
- Example:
G72 W1.5 R0.5
G72 P300 Q400 U0.3 W0.1 F0.28
G70 – Finishing Cycle
- Finishes the profile previously roughed by G71/G72.
- Example:
G70 P100 Q200
G76 – Multi-Pass Threading Cycle
- High-level automatic threading with depth control and pull-out.
G74 / G75 – Peck & Groove Cycles
- G74: peck drilling/turning in Z.
- G75: groove pecking in X.
8. High-Speed, Smoothing & Accuracy Codes
G05.1 – AI Contour Control (HPCC)
- High-speed contouring with look-ahead and smoothing.
- Use for 3D surfacing and molds.
- Example:
G05.1 Q1
G08 – High-Speed Smoothing Mode
- Blends small segments for smoother motion.
- G08 P1 / P2 levels vary by machine.
G187 (Haas) – Motion Tolerance Control
- P1/P2/P3 and E-value tune speed vs precision balance.
9. Rotation, Tilted Planes & 5-Axis
G68 – 2D Coordinate Rotation
- Rotates XY workplane; great for angled pockets and patterns.
- Example:
G68 X0 Y0 R30.
G69 (cancel)
G68.2 – Tilted Working Plane (5-Axis)
- Defines a 3D tilted plane using rotations about X/Y/Z.
G54.4 / DWO / TCP
- Dynamic work offset; adjusts for rotary motion.
10. Essential M-Codes (Spindle, Coolant, Program Flow)
Spindle Control
- M03 – Spindle on clockwise
- M04 – Spindle on counterclockwise
- M05 – Spindle stop
- Example:
S12000 M03
Coolant Control
- M08 – Coolant on
- M09 – Coolant off
- Some machines: M88/M89 for through-spindle coolant.
Tool Change & Program Flow
- M06 – Tool change
- M00 – Program stop (optional manual action)
- M01 – Optional stop (only stops if OPT STOP active)
- M30 – Program end and rewind
- M99 – Return from subprogram / loop
Subprogram & Remote Calls
- M98 – Call internal subprogram (O####)
- M198 – Call program from external device (e.g. USB)
Machine & Miscellaneous
- M17 – 4th/5th axis brake on (machine-dependent)
- M19 – Spindle orient
- M130 (Haas) – Media display (show PDF/image/video on control)
11. Realistic Milling Program Skeleton (Fanuc/Haas Style)
This template shows how many of these codes combine in a real file:
O1000 (3-AXIS MILLING EXAMPLE)
G21 G17 G90 G40 G49 G80
G54
T12 M06
S12000 M03
G00 X0. Y0. Z100.
M08
G00 X25. Y35.
G43 H12 Z10.
G01 Z-4. F600
G01 X80. Y35. F1200
G03 X90. Y45. R10.
G01 Y80.
G00 Z50.
M09
G91 G28 Z0.
G90
M30
This demonstrates:
- Safe start line
- Work offset G54
- Tool change / spindle / coolant
- Rapid & feed moves
- Arc + linear cutting
- Safe retract and program end
12. Realistic Turning Program Skeleton
O2000 (TURNING EXAMPLE)
G21
G50 S2500
G96 S220 M03
G00 X80. Z5.
T0101
G71 U2.0 R0.5
G71 P100 Q200 U0.3 W0.15 F0.25
N100 G00 X60. Z2.
N110 G01 Z-40.
N120 G01 X30.
N200
G70 P100 Q200
G00 X200. Z200.
M05
M30
Shows:
- Constant surface speed (G96)
- Roughing (G71) and finishing (G70)
- Tool call with geometry/wear (T0101)
- Safe retract and end
13. Debugging Unknown G/M Codes in Any Program
When you find a code you don’t recognize:
- Identify context
- Is it near drilling? motion? tool change?
- Look at values on the line
- G08 with P or Q → smoothing
- G10 with L2/L20 → offsets
- M130 with a filename → media display
- Check if it is modal (stays active) or one-shot.
- Look for cancel code (G69 for G68, G80 for drilling, G40 for comp, etc.).
- Test on air (above the part) with Z raised and feed override low.
14. Why This Page Should Live as a Permanent Reference
- It covers core G- and M-codes used daily worldwide.
- It is arranged by function, not just numeric order.
- It includes real, production-style examples, not just theory.
- It is future-proof: the fundamentals of G-code change very slowly.
- It’s perfect as:
- A shared team reference
- A new-hire training page
- A bookmarked “CNC dictionary” for every programmer and operator.
If you keep this dictionary updated with machine-specific notes (Haas, Fanuc, Siemens differences), it will become one of the most visited and shared resources in your entire CNC ecosystem.
Leave a comment