In CNC machining, G-codes and M-codes are two fundamental programming commands used to control the movement and functionality of machine tools.
G-code, also known as “geometric code” or “preparatory code,” is primarily used to define the motion and positioning of the cutting tool. These codes instruct the machine on how to move, such as rapid motion (G00), linear interpolation (G01), and circular interpolation (G02 and G03), among others.
On the other hand, M-code, also known as “miscellaneous code,” controls various functions of the machine tool, such as spindle rotation, coolant flow adjustment, and tool change. Each G and M code is usually followed by a number representing a specific function or command.
The existence of G-codes and M-codes enables CNC machine tools to perform complex machining tasks. By precise programming instructions, they control the actions of the machine tool, resulting in high precision and high-quality machining effects.
Different combinations of G and M codes can complete various machining operations, including but not limited to drilling, milling, and turning. However, it’s important to note that different manufacturers’ CNC systems may have variations in the specific meanings and applications of these codes. Therefore, reference to the specific machine tool’s operating manual or consultation with the manufacturer is necessary to ensure correct application.
In summary, G-codes and M-codes are indispensable parts of CNC machining. Together, they form the programming language of CNC machine tools, making the mechanical machining process more flexible and efficient. Mastery of these codes’ meanings and applications is crucial for CNC programmers.
What is G-code?
G-code (also known as RS-274) is the most widely used NC programming language.
It has many versions and is mainly used to control automatic machine tools in computer-aided manufacturing.
G code is sometimes called G programming language.
G code is the instruction in the numerical control program. Commonly referred to as the G instruction.
G code can be used to realize rapid positioning, inverse circle interpolation, along circle interpolation, middle point arc interpolation, radius programming and jump processing.
What is M-code?
M code is defined as auxiliary function code in FANUC program.
M code plays an auxiliary control role for the machine tool and is used for non axis movement command.
The program is suspended. Press the ‘cycle start’ program to continue
M30
The program ends and returns to the beginning
19. GSK928 TC / TE G code
G-code
Function
G00
Positioning (fast moving)
*G01
Linear interpolation (cutting feed)
G02
Arc interpolation CW (clockwise)
G03
Circular interpolation CCW (counterclockwise)
G32
Tapping circulation
G33
Thread cutting
G71
Outer circle rough turning cycle
G72
End rough turning cycle
G74
End face deep hole machining cycle
G75
Outer circle, inner circle, grooving cycle
G90
Outer circle, inner circle, turning cycle
G92
Thread cutting cycle
G94
Outer circle inner conical surface circulation
G22
Local cycle start
G80
End of local cycle
*G98
Feed per minute
G99
Feed per revolution
G50
Set workpiece absolute coordinate system
G26
10. Z-axis back reference
G27
X-axis back to reference point
G29
Z axis back to reference point
20. GSK928 TC / TEM code
M-code
Instruction
M03
Spindle forward rotation
M04
Spindle reversal
M05
Spindle stop
M08
Coolant on
M09
Coolant off (no output signal)
M32
Lubrication on
M33
Lubrication off (no output signal)
M10
Spare
M11
Spare tip (no signal output)
MOO
Program pause, press’ cycle start ‘program to continue
M30
The program ends and returns to the beginning
21. GSK990M G Code
G-code
Group
Explain
G00
1
Positioning (fast moving)
G01
Linear cutting
G02
Clockwise circular arc
G03
Counterclockwise tangent arc
G04
0
suspend
G17
2
XY face assignment
G18
XZ face assignment
G19
YZ face assignment
G28
0
Machine return to origin
G29
Return from reference point
*G40
7
Cancel tool diameter offset
G41
Tool diameter left offset
G42
Tool diameter right offset
*G43
8
Tool length + direction offset
*G44
Tool length minus direction offset
G49
Cancel tool length offset
*G53
14
machine tool coordinate system selection
G54
workpiece coordinate system 1 Selection
G55
workpiece coordinate system 2 selection
G56
workpiece coordinate system 3 selection
G57
workpiece coordinate system 4 selection
G58
workpiece coordinate system 5 Selection
G59
workpiece coordinate system 6 selection
G73
9
high speed deep hole drilling cycle
G74
left spiral cutting cycle
G76
fine boring cycle
*G80
cancel fixed cycle
G81
drilling cycle (spot drilling)
G82
drilling cycle (boring stepped holes)
G83
deep hole drilling cycle
G84
tapping cycle
G85
boring cycle
G86
borehole circulation
G87
reverse boring cycle
G88
boring cycle
G89
boring cycle
*G90
3
use absolute value command
G91
use incremental value command
G92
0
set workpiece coordinate system
*G98
10
fixed cycle return to starting point
*G99
return to fixed cycle r point
22. GSK990M M code
M-code
Instruction
M00
Program stop
M01
Select Stop
M02
Program end (reset)
M03
Spindle forward rotation (CW)
M04
Spindle reversal (CCW)
M05
Spindle stop
M06
Change knife
M08
Cutting fluid on
M09
Cutting fluid off
M10
Clamping
M11
Release
M32
Lubrication on
M33
Lubrication off
M98
Subroutine call
M99
End of subroutine
23. GSK928MA G-code
G-code
Explain
G00
Positioning (fast moving)
G1
Linear cutting
G02
Clockwise circular arc
G03
Counterclockwise tangent arc
G04
Delay waiting
G17
XY face assignment
G18
XZ face assignment
G19
YZ face assignment
G28
Machine return to origin
G29
Return from reference point
*G40
Cancel tool diameter offset
G41
Tool diameter left offset
G42
Tool diameter right offset
*G43
Tool length + direction offset
*G44
Tool length offset in one direction
G49
Cancel tool length offset
*G53
Machine coordinate system selection
G54
Workpiece coordinate system 1 Selection
G55
Workpiece coordinate system 2 selection
G56
Workpiece coordinate system 3 selection
G57
Workpiece coordinate system 4 selection
G58
Workpiece coordinate system 5 Selection
G59
Workpiece coordinate system 6 selection
G73
High speed deep hole drilling cycle
G74
Left spiral cutting cycle
G80
Cancel fixed cycle
G81
Drilling cycle (spot drilling)
G82
Drilling cycle (boring stepped holes)
G83
Deep hole drilling cycle
G84
Right tapping circulation
G85
Boring cycle
G86
Drilling cycle
G89
Boring cycle
*G90
Use absolute value command
G91
Use incremental value command
G92
Set floating coordinate system
*G98
Fixed cycle return to starting point
*G99
Return to fixed cycle r point
G10 G11
Rough milling in circular groove
G12 G13
Full circle internal finish milling
G14 G15
Cylindrical finish milling
G22
System parameter operation (mode)
G23
Parameter value jump
G27
Mechanical zero point detection
G28
Quickly locate the program through the middle point
G31
Quick return to R datum
G34 G35
Finish milling in rectangular groove
G38 G39
Rectangular external finish milling
24. GSK928MAMcode
M2
The program ends and stops. Stop the spindle, turn off the coolant, eliminate the G93 coordinate offset and tool offset, and return to the starting program section (not running). After executing M2, the system will switch to the reference workpiece coordinate system.
M3
Spindle forward rotation
M4
Spindle reversal
M5
Stop spindle
M8
Turn on the cooling pump
M9
Turn off the cooling pump
M12
Pause: wait for the “run” key to continue running (press the emergency stop key to stop)
M30
At the end of the program, eliminate the tool offset and return to the starting program segment (not running). After executing M30, the system will switch to the reference workpiece coordinate system.
M32
Lubrication on;
M33
Lubrication off;
M98
Call subroutine
M99
Subroutine end return
25. Mitsubishi E60 milling machine G code
G-code
Group
Explain
※G00
1
Position positioning (rapid feed)
*G01
Straight line repair
G02
Clockwise arc cutting (CW)
G03
Counterclockwise arc cutting (CCW)
G04
0
suspend
G05
High speed machining mode
G09
Stop the check correctly
G10
Program parameter input / correction input
G11
Program parameter input cancel
G12
Circular cutting CW
G13
Circular cutting CCW
*G17
2
Plane selection X-Y
※G18
Plane selection z-x
G19
Plane selection Y-Z
※G20
6
Imperial directive
G21
Metric instruction
G27
0
Reference origin check
G28
Reference origin reset
G29
Start point reset
G30
The 2nd ~ 4th reference origin reset
G31
Jumping function
G33
1
Thread cutting
G37
0
Automatic tool length measurement
G38
Tool diameter correction vector assignment
G39
Angle arc correction tool
*G40
7
Tool diameter correction cancellation
G41
Tool diameter correction left
G42
Tool diameter correction right
G43
8
Tool length correction (+)
G44
Tool length correction (I)
*G49
Tool length correction quantity cancellation
G52
0
Local coordinate system setting
G53
Selection of mechanical coordinate system
*G54
12
Workpiece coordinate system 1 Selection
G55
12
Workpiece coordinate system 2 selection
G56
Workpiece coordinate system 3 selection
G57
Workpiece coordinate system 4 selection
G58
Workpiece coordinate system 5 Selection
G59
Workpiece coordinate system 6 selection
G60
0
Unidirectional position positioning
G61
13
Make sure to stop the inspection mode
G62
Automatic angle feed rate adjustment
G63
Tapping mode
*G64
Cutting mode
G73
9
Fixed cycle (step cycle)
G74
Fixed circulation (reverse tapping)
G76
Fixed cycle (fine boring)
*G80
Fixed cycle cancellation
G81
Fixed circulation (drilling / lead hole)
G82
Fixed cycle (drilling / counter boring)
G83
Fixed circulation (deep drilling)
G84
Fixed circulation (tapping)
G85
Fixed cycle (boring)
G86
Fixed cycle (boring)
G87
Fixed cycle (reverse boring)
G88
Fixed cycle (boring)
G89
Fixed cycle (boring)
*G90
3
Absolute value instruction
*G91
Incremental value instruction
G92
0
Mechanical coordinate system setting
G93
5
Counterclockwise feed
*G94
Asynchronous cutting (feed per minute)
*G95
Simultaneous cutting (feed for each drilling)
*G96
17
The cycle speed must be controlled effectively
*G97
The cycle speed control must be invalid
*G98
10
Fixed cycle starting point reset
G99
Fixed cycle r-point reset
26. DASEN 3I milling machine G code
G-code
Group
Explain
※G00
1
Position positioning (rapid feed)
*G01
Straight line repair
G02
Clockwise arc cutting (CW)
G03
Counterclockwise arc cutting (CCW)
G04
0
suspend
G05
High speed machining mode
G09
Stop the check correctly
G10
Program parameter input / correction input
G11
Program parameter input cancel
G12
Circular cutting CW
G13
Circular cutting CCW
*G17
2
Plane selection X-Y
※G18
Plane selection z-x
G19
Plane selection Y-Z
※G20
6
Imperial directive
G21
Metric instruction
G27
0
Reference origin check
G28
Reference origin reset
G29
Start point reset
G30
The 2nd ~ 4th reference origin reset
G31
Jumping function
G33
1
Thread cutting
G37
0
Automatic tool length measurement
G38
Tool diameter correction vector assignment
G39
Angle arc correction tool
*G40
7
Tool diameter correction cancellation
G41
Tool diameter correction left
G42
Tool diameter correction right
G43
8
Tool length correction (+)
G44
Tool length correction (I)
*G49
Tool length correction quantity cancellation
G52
0
Local coordinate system setting
G53
Selection of mechanical coordinate system
*G54
12
Workpiece coordinate system 1 Selection
G55
12
Workpiece coordinate system 2 selection
G56
Workpiece coordinate system 3 selection
G57
Workpiece coordinate system 4 selection
G58
Workpiece coordinate system 5 Selection
G59
Workpiece coordinate system 6 selection
G60
0
Unidirectional position positioning
G61
13
Make sure to stop the inspection mode
G62
Automatic angle feed rate adjustment
G63
Tapping mode
*G64
Cutting mode
G73
9
Fixed cycle (step cycle)
G74
Fixed circulation (reverse tapping)
G76
Fixed cycle (fine boring)
*G80
Fixed cycle cancellation
G81
Fixed circulation (drilling / lead hole)
G82
Fixed cycle (drilling / counter boring)
G83
Fixed circulation (deep drilling)
G84
Fixed circulation (tapping)
G85
Fixed cycle (boring)
G86
Fixed cycle (boring)
G87
Fixed cycle (reverse boring)
G88
Fixed cycle (boring)
G89
Fixed cycle (boring)
*G90
3
Absolute value instruction
*G91
Incremental value instruction
G92
0
Mechanical coordinate system setting
G93
5
Counterclockwise feed
*G94
Asynchronous cutting (feed per minute)
*G95
Simultaneous cutting (feed for each drilling)
*G96
17
The cycle speed must be controlled effectively
*G97
The cycle speed control must be invalid
*G98
10
Fixed cycle starting point reset
G99
Fixed cycle r-point reset
27. DASEN 3I lathe G code
G-code
Group
Explain
※G00
1
Fast mobile positioning
※G01
Straight line repair
G02
Arc gap (CW, Clockwise Clock)
G03
Arc gap repair (CCW, counter clock)
G04
0
suspend
G09
Correct stop
G10
Program parameters / correction input
G11
Program parameter / correction input mode cancelled
※G17
2
X-Y plane selection
※G18
Z-x plane selection
※G19
Y-Z plane selection
※G20
6
Imperial input
※G21
Metric input
G27
0
Reference point reset check
G28
Automatic reference point reset
G29
Reset from reference point
G30
Reset of reference points 2, 3 and 4
G31
Jumping function
G33
1
Thread cutting
G34
Variable thread cutting
G37
0
Automatic tool correction
*G40
7
Tool diameter correction cancellation
G41
Tool diameter correction (left side)
G42
Tool diameter correction (right side)
G46
Tool diameter correction (automatic direction selection)
G52
0
Local coordinate system setting
G53
Selection of mechanical coordinate system
※G54
12
Workpiece coordinate system selection 1
G55
Workpiece coordinate system selection 2
G56
Workpiece coordinate system selection 3
G57
Workpiece coordinate system selection 4
G58
Workpiece coordinate system selection 5
G59
Workpiece coordinate system selection 6
G61
13
Correct stop check mode
G62
Automatic angle speed control
G63
Tapping mode
*G64
Cutting mode
G70
9
Finish cutting cycle
G71
Straight turning rough cutting cycle
G72
End face rough cutting cycle
G73
Spindle table movement in rough machining cycle
G74
End cutting cycle
G75
Straight turning cycle
G76
Thread cutting cycle
G77
From cutting cycle
G78
Tooth fixation cycle
G79
End cutting fixed cycle
G80
Machining hole cycle command cancel
G83
Deep drilling cycle (Z-axis)
G84
Tapping cycle (Z axis)
G85
Boring cycle (Z axis)
G87
Deep hole drilling cycle (x-axis)
G88
Tapping cycle (x-axis)
G89
Boring cycle (x-axis)
※G90
3
Absolute value command
※G91
Incremental value command
G92
0
Coordinate system setting / spindle speed setting
※G94
5
Asynchronous feed (feed per minute)
※G95
Synchronous feed (feed per revolution)
※G96
17
Cycle speed control on
※G97
Cycle speed must be controlled off
*G98
10
Fixed cycle
Initial value reversion
G99
Fixed cycle
R-point reset
28. Huaxing lathe G code
G-code
Explain
G00
Fast positioning
G01
Linear interpolation
G02
Clockwise circular interpolation
G03
Counterclockwise circular interpolation
G04
delayed
G09
Feed quasi stop
G20
Independent subroutine call
G22
Independent subroutine definition
G24
When the independent subroutine definition is finished, return to the calling program
G25
Jump processing
G26
Block call subroutine call in machining program
G27
Infinite loop
G30
Magnification cancellation
G31
Magnification definition
G47
Short linear speed automatic transition
G48
cancel
G54~G59
Workpiece coordinate system selection
G71
Internal and external circular cutting
G72
Face cutting compound cycle
G73
Closed contour compound cycle
G74
Return to machine reference point (mechanical origin)
G75
Return to tool setting point
G76
Return to machining start point
G77
Restore the current coordinate system
G81
Cylindrical machining cycle
G82
End face machining cycle
G85
Inch rigid tapping cycle
G86
Metric thread machining cycle
G87
Inch thread machining cycle
G90
Absolute value mode programming
G91
Incremental value programming
G92
Set program zero
G96
Constant linear speed cutting is effective
G97
Cancel constant linear speed cutting
G98
Cancel feed per revolution
G99
Set feed per revolution
P = parameter assignment
29. Huaxing lathe M code
M instruction
Explain
M01
Conditional stop
M02
Program end and shutdown
M03
Spindle forward rotation
M04
Spindle reversal
M05
Spindle stop
M06
Cooling on
M07
Cooling off
M08
Workpiece clamping
M09
Workpiece loosening
M10
Turn on the specified relay
M11
Turn off the specified relay
M20
Set tool complement number
M21
The program ends and returns to the beginning of the program
M71~M85
Relay pulse output
30. Huaxing milling machine G code
G-code
Explain
G01
linear interpolation
G02
Clockwise arc interpolation or spiral interpolation
G03
Counterclockwise arc interpolation or spiral interpolation
G04
delayed
G09
Servo quasi stop in place
G11
The block is mirrored along the Y axis
G12
The block is mirrored along the X axis
G13
The program block is processed by mirror image at the origin
G17
Select the xoy plane
G18
Select the x0z plane
G19
Select the y0z plane
G20
Subroutine call
G22
subprogram declaration
G24
The subroutine definition ends and returns to the calling program
G25
Jump processing
G26
Transfer processing
G27
Infinite loop
G30
Zoom in / out magnification cancel
G31
Definition of magnification / reduction ratio
G40
Cancel tool radius compensation
G41
Left tool radius compensation
G42
Right tool radius compensation
G43
Establish tool length compensation
G44
Undo tool length compensation
G47
Short linear speed automatic transition
G48
Cancel the automatic transition of short linear speed
G54~G59
Workpiece coordinate system selection
G73
High speed deep hole machining cycle
G74
Return to machine reference point (mechanical origin)
G75
Return to tool setting point
G76
Return to program zero from current position
G78
Fine boring cycle
G81
Central hole drilling cycle
G82
Central drilling cycle with pause
G83
Deep hole machining cycle
G84
Metric rigid tapping cycle
G85
Inch rigid tapping cycle
G86
Boring cycle (automatic return)
G87
Reverse boring cycle
G88
Boring cycle (manual return)
G89
Boring cycle with pause
G90
Absolute value mode programming
G91
Incremental value programming
G92
Set workpiece coordinate system
P = parameter assignment
31. Huaxing milling machine M code
G-code
Explain
M00
Program pause
M01
L ×× (K ××)
M02
Program end and shutdown
M03
Spindle forward rotation
M04
Spindle reversal
M05
Spindle stop
M08
Cooling on
M09
Cooling off
M10
Workpiece clamping
M11
Workpiece loosening
M20
K ×× Relay No
M21
K ×× shut ×× Relay No
M30
The program ends and returns to the beginning of the program
How do you select the appropriate G-codes and M-codes for programming based on different CNC systems?
To select the appropriate G and M codes for programming based on different CNC systems, you first need to understand the basic functions and uses of G and M codes. G codes primarily control machine tool movements, such as linear motion and circular interpolation, while M codes execute auxiliary operations of the machine tool, like spindle rotation and coolant switch.
Understand the characteristics of different CNC systems: Different CNC systems (like Fanuc, Siemens) may support G and M codes differently. Therefore, you must familiarize yourself with the specific functions and limitations of the CNC system you are using.
Refer to relevant materials: You can obtain the specific meanings and uses of G and M codes by referring to relevant CNC programming guides or code encyclopedias. For instance, you can refer to materials such as “Fanuc, Siemens Common CNC System Code Encyclopedia (G, M codes), Command Explanation”.
Understand the functions of G and M codes: G codes mainly involve motion control of the machine tool. For example, G00 denotes rapid positioning, G01 indicates linear interpolation feed, G02 and G03 represent clockwise and counter-clockwise circular interpolation respectively. M codes include auxiliary operations like M01 for optional stop, M02 for program end (reset), M03 for spindle forward rotation, and so on.
Choose the appropriate code according to processing needs: Once the functions of G and M codes are clear, you can select the appropriate code based on specific processing needs. For example, if rapid positioning is required, use G00; if spindle rotation control is needed, use M03 or M04.
Pay attention to the selection of coordinate systems and planes: During programming, you should also be mindful of the selection of coordinate systems and planes, like G17, G18, and G19, which are used to select the XY plane, ZX plane, and YZ plane, respectively.
Practice and test: Lastly, validate the correctness and applicability of the selected G and M codes through actual programming and testing. In practice, you may encounter some special scenarios or requirements, where you might need to adjust or choose other codes to meet specific needs.
In practical CNC machining, how can G-codes and M-codes be effectively combined to enhance machining efficiency and precision?
In real-world CNC machining, to effectively combine G-codes and M-codes to boost machining efficiency and precision, it’s crucial to first understand the basic functions and roles of G-codes and M-codes.
G-codes primarily control the movement of the machine tool, such as rapid positioning (G00), linear interpolation (G01), and circular interpolation (G02 and G03). Meanwhile, M-codes are used to execute auxiliary functions of the machine tool, like coolant switch and tool change commands.
To enhance machining efficiency and precision, the following strategies can be adopted:
Optimize G-code programs: Depending on the characteristics of the CNC system and the actual performance of the machine tool, select suitable G-code instructions to ensure the optimization of the machining path. For instance, by reducing idle travel distance and using more efficient interpolation methods, production efficiency can be significantly improved.
Rational application of M-codes: During programming, M-codes should be arranged logically according to machining needs, such as activating the coolant when high-precision machining is required, or changing the tool after certain specific machining steps are complete. This can not only improve the quality of machining but also avoid unnecessary downtime.
Macro programming: By utilizing the macro programming function of the CNC machining center, the corresponding combination of G-codes and M-codes can be automatically generated based on specific machining requirements. This method can ensure machining precision while further enhancing programming efficiency and machining efficiency.
Pay attention to programming details: When writing programs, it’s important to analyze the part diagram to determine the precision and technical requirements of CNC machining, as well as the characteristics of the machine tool control system. This allows for the creation of a combination of G-codes and M-codes that not only meets machining requirements but also fully utilizes the performance of the machine tool.
How useful was this post?
Click on a star to rate it!
Average rating 4 / 5. Vote count: 1
No votes so far! Be the first to rate this post.
As you found this post useful...
Follow us on social media!
We are sorry that this post was not useful for you!
As the founder of MachineMFG, I have dedicated over a decade of my career to the metalworking industry. My extensive experience has allowed me to become an expert in the fields of sheet metal fabrication, machining, mechanical engineering, and machine tools for metals. I am constantly thinking, reading, and writing about these subjects, constantly striving to stay at the forefront of my field. Let my knowledge and expertise be an asset to your business.