Numerical control technology is the core of numerical control machine. The control program contribute much for Numerical control technology. G code and M code are the main components of the control program. In this article, we will help you get a comprehensive understanding of G & M codes in the CNC machining process.

What is G-code?

G code is one of the most commonly used programming languages in CNC machine tools, which can control the movement of the tool and the machining path. G code is often used to control simple lines, arcs, etc.

What is M-code?

M code is a programming language used in CNC machine to control the auxiliary functions of the machine tool, such as tool change, lubricating oil pump switch, etc. M codes are often used to control actions such as stopping, starting, and repeating.

The combination of M code and G code can create complex parts by CNC machining. When writing M code, it is necessary to note that different brands and models of CNC machines may have different code specifications and compatibility issues.

Definition of the letters In CNC programming

  • O: Program number
  • N: program sequence number
  • G: Preparatory function
  • X/Y/Z: Dimension characters, axis movement command
  • A/B/C/U/V/W: Additional axis movement command
  • R: Radius of arc
  • I/J/K: Center coordinates of arc (vector)
  • F: Feed rate
  • S: Spindle speed
  • T: setting tool number
  • M: control function on/off
  • H/D: setting tool offset number
  • P/X: setting dwell time
  • P: setting subprogram number (e.g., subprogram call: M98 P1000)
  • L: Loop, setting subprogram or fixed loop repetition count (e.g., M98 P1000 L2, omitting L represents L1)
  • P/W/R/Q: parameters used for fixed cycles (e.g., threading G98/(G99) G84 X_ Y_ R_ Z_ P_ F_)”

How does G-codes work?

Rapid Positioning

Format: G00 X(U)Z(W)

  • The instruction makes the tool move quickly to the specified position, The workpiece shall not be processed during movement.
  • when one axis completes the programming value, it stops, while the other axes continue to move.
  • G00 can be written as G0.

Example: G00 X75 Z200 G01 U-25 W-100:  First, along with X and Z axis move simultaneously at a rapid speed to point A by 25 units, then along Z continues to move rapidly to point B by 75 units.

Linear Interpolation

Format: G01 X(U)_Z(W)F(mm/min)

  • This command moves the tool to the specified position in a linear interpolation manner. The feed speed is controled with F command. All coordinates can be run in tandem.
  • G01 can also be written as G1.

Example: G01 X40 Z20 F150: Two-axis simultaneous movement from point A to point B.

Arc Interpolation mia

Format: G02 X(u)_Z(w)I_K_F

  • When X and Z are at G90, the end coordinate of the arc is the absolute coordinate value compare to the programming zero. At G91, the end of the arc is the increment relative to the beginning of the arc. I and K are the incremental coordinates of the center of the arc compare to the starting point.
  • When the G02 instruction is programmed, it can be directly programmed through the quadrant circle, the whole circle, etc.
  • G02 can also be written as G2.

Example: G02 X60 Z50 I40 K0 F120: Programming a quadrant arc with specified parameters.


Format: G04_F_ or G04_K_

During machining, motion is paused, and after the specified time, machining continues. The pause time is specified by the data following F. The unit is in seconds, ranging from 0.01 seconds to 300 seconds.

Intermediate Point Arc Interpolation

Format: G05 X(u) Z(w) IX IZ F

X and Z are the endpoint coordinates, while IX and IZ are the coordinates of the intermediate point. Similar to G02/G03 with additional parameters.

Example: G05 X60 Z50 IX50 IZ60 F120


Format: G08

These commands occupy a line by themselves in the program. When the program reaches this section, the feed rate will increase by 10%. To increase it by 20%, you would need to write two separate lines.

Radius Programming

Format: G22

When placed on a line by itself in the program, the system will operate in radius mode, and the values following in the program will also be interpreted as radius values.

Diameter Dimension Programming

Format: G23

When placed on a line by itself in the program, the system will operate in diameter mode, and the values following in the program will also be interpreted as diameter values.

Jump Machining

Format: G25 LXXX

When the program reaches this segment, it transfers to the specified program segment (XXX represents the program segment number).

Loop Machining

Format: G26 LXXX QXX

When the program reaches this segment, it starts the program segment specified by LXXX as a loop, and the number of repetitions is determined by the value following QXX.

G Code Commands List

G Code command could be used in both CNC milling and CNC lathe machines to control the movements of CNC milling tools and CNC lathe cutting tools

Tool Movements

  • G00 Rapid linear movement
  • G01 Linear feed movement
  • G02 Clockwise arc
  • G03 Counterclockwise arc
  • G05 Arc
  • G06 Arc, tangent
  • G07 Linear, parallel axis
  • G10 Rapid polar coordinate linear movement
  • G11 Polar coordinate linear feed
  • G12 Clockwise polar coordinate arc
  • G13 Counterclockwise polar coordinate arc
  • G15 Polar coordinate arc
  • G16 Polar coordinate arc, tangent transition

Defining Machining Planes

  • G17 Spindle Z-plane XY
  • G18 Spindle Y-plane ZX
  • G19 Spindle X-plane YZ


  • G24 Chamfer of length R, chamfer length R
  • G25 Radius R rounding, radius R
  • G26 Tangent approach to contour with radius R
  • G27 Tangent exit contour, radius R

Defining Workpiece for Graphic Display 

  • G30 Workpiece definition: minimum point
  • G31 Workpiece definition: maximum point

Tool Radius Compensation

  • G40 Tool center path, no tool radius compensation
  • G41 Left radius compensation path
  • G42 Right radius compensation path
  • G43 Radius compensation: expanding path
  • G44 Radius compensation: retracting path

Coordinate Transformation

  • G28 Mirroring
  • G53 Origin shift using the origin table
  • G54 Origin shift
  • G55 Origin plane
  • G73 Rotation
  • G72 Scaling factor
  • G80 Machining plane
  • G247 Origin setting

Dimension Units

  • G70 Dimension units in inches (program starting point)
  • G71 Dimension units in millimeters (program starting point)


  • G90 Absolute dimensions
  • G91 Incremental dimensions

Tool Definition

G99 Tool definition, tool number T, length L, and radius R

Other G Codes

  • G04 Dwell time
  • G37 Contour
  • G38 Stop program execution
  • G36 Spindle orientation
  • G39 Program call
  • G55 Origin plane
  • G62 Tolerance
  • G79 Repeat call
  • G29 Load current position (e.g., polar coordinates with the center as the origin)
  • G51 Tool change preparation (with a central tool magazine)
  • G98 Set mark

M Code Commands List 

  • M00: Program execution pause/spindle stop/coolant stop
  • M01: Optional program stop
  • M02: Program stop/spindle stop/coolant stop/as required
  • M03: Spindle clockwise rotation
  • M04: Spindle counterclockwise rotation
  • M05: Spindle stop
  • M06: Tool change/program stop (depends on machine parameters)/spindle stop
  • M08: Coolant on
  • M09: Coolant off
  • M13: Spindle clockwise rotation/coolant on
  • M14: Spindle counterclockwise rotation/coolant on
  • M30: Same as M02
  • M89: Auxiliary function or repeat call available
  • M99: Program segment repeat call
  • M91: Positioning program segment, coordinates relative to the machine tool origin
  • M92: Positioning program segment, coordinates defined relative to the machine tool manufacturer
  • M94: Reduce rotation axis display to within 360°
  • M97: Processing small contour steps
  • M98: Complete processing of an open contour
  • M109: Constant contour processing speed at tool edge (increase and decrease feed rate)
  • M110: Constant contour processing speed at tool edge (only decrease feed rate)
  • M111: Reset M109/M110
  • M116: Rotary axis feed rate (mm/min)
  • M117: Reset M116
  • M118: Manual wheel overlay positioning during program execution
  • M120: Pre-calculate radius compensation contour (pre-read)
  • M126: Rotary axis short-path motion
  • M127: Reset M126
  • M128: Maintain the tooltip position when positioning with a tilted axis (TCPM)
  • M129: Reset M128
  • M130: In the positioning program segment: points are relative to the untilted coordinate system
  • M140: Retract from the contour along the tool axis direction
  • M141: Cancel probe monitoring function
  • M143: Delete basic rotation
  • M148: Automatically retract tool from contour at NC stop
  • M149: Reset M148


G and M codes, as well as a transformation of traditional machining methods, require a strong ability to apply program instructions and rich practical skills. At KUSLA, we have the necessary equipments, materials, and know-how of G&M codes to help you get high-quality machined parts.

Maybe you also like:

Understanding Engineering Drawings

Mechanical design is a rigorous and highly practical profession. As engineering language in the field of engineering design, engineering drawings need to meet the essential requirements of clear and complete expression. At the same time, the readers of the drawings are also required to fully comprehend and understand them. So, how can we achieve clear reading of engineering drawings?
Read More Understanding Engineering Drawings

Similar Posts