G-Code Vs M-Code in CNC
In CNC programming, G-code Vs M-code serve distinct but complementary roles. While G-codes (Geometric codes) control the movement and positioning of the machine tool (e.g., linear cuts, arcs, and drilling cycles), M-codes (Miscellaneous codes) manage auxiliary machine functions (e.g., spindle control, coolant, and tool changes).
CNC Machining Center Standard G-Code Reference Chart |
||||
1. Unit & Coordinate Setup |
||||
G-Code |
Function |
Example |
Machine Type |
Notes |
| G20 | Inch Units | G20 | Universal | Common in US/EU machines |
| G21 | Metric Units | G21 | Universal | Global standard |
| G90 | Absolute Positioning | G90 | Universal | Default programming mode |
| G91 | Incremental Positioning | G91 | Universal | Relative movements |
| G54-G59 | Work Coordinate Systems | G54 | Universal | Extendable (G54.1 P1-P48) |
2. Motion Control |
||||
| G00 | Rapid Positioning | G00 X100 Y50 | Universal | Non-cutting move |
| G01 | Linear Interpolation | G01 X50 F200 | Universal | Requires feedrate (F) |
| G02 | CW Circular Interpolation | G02 X30 Y30 I5 J0 | Universal | IJK=center relative coords |
| G03 | CCW Circular Interpolation | G03 X30 Y30 R5 | Universal | R=radius value |
| G17 | XY Plane Selection | G17 | Universal | Default plane |
| G18 | XZ Plane Selection | G18 | Mill-Turn | Turning operations |
| G19 | YZ Plane Selection | G19 | 5-Axis | Side milling |
3. Tool Compensation |
||||
| G40 | Cancel Cutter Comp | G40 | Universal | Mandatory at program end |
| G41 | Cutter Comp Left | G41 D01 | Universal | D=offset number |
| G42 | Cutter Comp Right | G42 D02 | Universal | Must initiate first |
| G43 | Tool Length Comp (+) | G43 H01 Z50 | Universal | H=length offset number |
| G44 | Tool Length Comp (-) | G44 H02 | Universal | Rarely used |
| G49 | Cancel Length Comp | G49 | Universal | Safety command |
4. Canned Cycles |
||||
| G73 | High-Speed Peck Drilling | G73 X50 Y30 Z-20 Q3 R2 F100 | Universal | Q=peck depth |
| G74 | LH Tapping Cycle | G74 X30 Y20 Z-15 R3 F1.0 | Universal | F=pitch×RPM |
| G76 | Fine Boring Cycle | G76 X40 Y25 Z-18 Q0.1 R2 F50 | Universal | Q=retract value |
| G80 | Cancel Cycle | G80 | Universal | Must be explicit |
| G81 | Simple Drilling | G81 X30 Y40 Z-10 R2 F80 | Universal | Through holes |
| G82 | Spot Drilling | G82 X30 Y40 Z-5 P500 R2 F60 | Universal | P=dwell (ms) |
| G83 | Deep Hole Peck Drilling | G83 X50 Y30 Z-25 Q5 R2 F70 | Universal | Q=peck increment |
| G84 | RH Tapping Cycle | G84 X40 Y20 Z-12 R3 F1.25 | Universal | Needs spindle encoder |
| G85 | Boring Cycle | G85 X35 Y45 Z-18 R2 F40 | Universal | No spindle stop |
| G86 | Bore & Stop Cycle | G86 X35 Y45 Z-15 R2 F50 | Universal | Spindle stops |
5. Advanced Functions |
||||
| G28 | Return to Reference | G28 Z0 | Universal | Moves via intermediate point |
| G29 | Return from Reference | G29 X50 Y30 | Universal | Requires prior G28 |
| G52 | Local Coordinate System | G52 X10 Y5 | Universal | Temporary offset |
| G68 | Coordinate Rotation | G68 X0 Y0 R45 | Universal | R=rotation angle |
| G69 | Cancel Rotation | G69 | Universal | Must be explicit |
6. High-Speed Machining |
||||
| G05.1 | High-Speed Mode | G05.1 Q1 | Advanced CNC | Controller-specific |
| G08 | Look-Ahead | G08 P1 | 5-Axis | Smooth corners |
| G61 | Exact Stop | G61 | Universal | Decelerates at corners |
| G64 | Continuous Mode | G64 | Universal | Default cutting mode |
7. 5-Axis Functions |
||||
| G43.4 | Tool Center Point Control | G43.4 H01 | 5-Axis | Tool tip following |
| G54.4 | Extended Work Offsets | G54.4 P1 | 5-Axis | Additional coordinate systems |
| G68.2 | Dynamic Work Plane | G68.2 X0 Y0 Z0 I1 J0 K0 | 5-Axis | Defines tilted plane |
Critical Notes
-
Modal Codes: G90/G91 etc. remain active until changed
-
Safety Cancellation: Always cancel compensation (G40), cycles (G80), and rotation (G69)
-
5-Axis Programming: G43.4/G68.2 require post-processor support
-
Brand Variations: Some codes (e.g., G05.1) may differ between controllers
This table covers 95%+ of standard G-codes for 3-axis/5-axis machining centers, compatible with Fanuc, Siemens, Mitsubishi controls. Always consult machine manuals for brand-specific implementations.
CNC Machining Center Standard M-Code Reference Chart |
|||
1. Program Control |
|||
M-Code |
Function |
Example |
Notes |
| M00 | Program Stop (Manual Resume) | M00 (Inspection) | Requires “Cycle Start” to continue |
| M01 | Optional Stop (Panel Confirm) | M01 (Batch Sampling) | Needs “Optional Stop” enabled |
| M02 | Program End (No Reset) | M02 (Legacy Program End) | Use M30 instead in modern CNCs |
| M30 | Program End & Reset | M30 (Standard Program End) | Returns to program start |
| M98 | Subprogram Call | M98 P1001 (Calls O1001) | Subprogram number after P |
| M99 | Subprogram End/Return | M99 (End of Subprogram) | Can force jump (e.g., M99 P200) |
2. Spindle Control |
|||
| M03 | Spindle CW (Forward) | S2000 M03 (2000 RPM CW) | Always specify speed (S) |
| M04 | Spindle CCW (Reverse) | S1500 M04 (1500 RPM CCW) | Used for tapping/left-hand threads |
| M05 | Spindle Stop | M05 (Before Tool Change) | Mandatory safety command |
| M19 | Spindle Orientation | M19 (Tool Change Alignment) | Aligns spindle keyway |
| M29 | Rigid Tapping Mode | M29 S500 (Rigid Tap at 500 RPM) | Requires spindle encoder |
3. Coolant Control |
|||
| M07 | Mist Coolant (MQL) | M07 (Minimum Quantity Lubrication) | For finishing |
| M08 | Flood Coolant | M08 (Standard Cutting) | Most common coolant command |
| M09 | Coolant Off | M09 (Before Program End) | Prevents leakage |
4. Automatic Tool Change (ATC) |
|||
| M06 | Tool Change | T02 M06 (Changes to Tool 2) | Requires M05 first |
| M60 | Pallet Change (APC) | M60 (For Horizontal Mills) | Machine-specific |
5. Special Functions |
|||
| M21-M28 | Mirror Imaging (X/Y/Z) | M21 (X-Axis Mirror) | For symmetrical parts |
| M48/M49 | Feed Override Cancel/Enable | M49 (Locks 100% Feedrate) | Ensures consistent cuts |
| M52 | Tailstock Advance (Mill-Turn) | M52 (Lathe Mode) | For mill-turn machines |
| M53 | Tailstock Retract (Mill-Turn) | M53 (Milling Mode) | For mill-turn machines |
6. Machine Status Control |
|||
| M07 | Mist Coolant (MQL) | M07 (Fine Finishing) | Low-quantity lubrication |
| M08 | Flood Coolant | M08 (General Machining) | Default coolant mode |
| M09 | Coolant Off | M09 (Program End) | Mandatory before shutdown |
Critical Notes
-
Tool Change Safety: Always stop spindle (M05) and coolant (M09) before M06.
-
Program Termination: Prefer M30 (auto-reset) over legacy M02.
-
Brand Variations: Some codes differ (e.g., Haas uses M16 for tool change).
-
Coolant Management: Turn off coolant during long pauses to protect pumps.
This table covers 90%+ of standard M-codes for 3-axis/5-axis CNC mills, vertical/horizontal machining centers. For machine-specific codes, always consult
Get In Touch
Our senior sales and technical engineers will answer you questions fast and efficient.