20% off   your first order. Save up to $1,000/€1,000. Ends 31 Dec 2024.

IATF16949:2016

ISO13485:2016

ISO9001:2015

Call Us 24/7

+86 135 1000 5651

Send Mail Us

Language

RT MANUFACTURE RESOURCES

RT is not only a parts manufacturer, but also your knowledge partner. This page contains our various processing knowledge and industry-related news. If you want to know more, you can click on an article to see if there is what you want.

G Code and M Code In CNC Programming

Jul. 24, 2025

Introduction


If you are familiar with the CNC industry, then you should know that in modern CNC manufacturing, every perfect CNC part processing is done with the help of a code, that is, the machine code that the CNC recognition system can read - G code and M code.


This guide aims to take you through the various aspects of the role of these two machine codes in the CNC manufacturing industry. Whether you are a young newbie who has just joined the manufacturing industry with enthusiasm, a CNC operator with some mechanical experience, or a CNC programmer who wants to further your studies in the CNC manufacturing industry, understanding these basic codes and their actual component control functions will help your career.


In the previous article "What is CNC", we briefly mentioned CNC g-code and CNC m-code, the two current mainstream CNC translation and recognition languages. In this article, let's take a closer look at these two interesting machine language codes. We will take you to understand the code g in CNC and the code m in CNC from the following perspectives.


What Are M Code and G Code?


Define M and G code


M code and G code in CNC programming refer to the execution code in CNC machine tools. M code is usually used to control the auxiliary functions of machine tools, while G code is used to control the movement and processing methods of machine tools. You can understand that M code is used to control the program switch instructions of CNC machine tools, while G code is the specific processing instruction.


When Did These Two Language Codes Appear?


In the 1950s (1950s). The emergence of these two codes marks that CNC technology has entered an important development stage. Together, they form the basis of modern CNC programming, making complex parts processing and efficient production possible.


Where Is the Importance of M Code and G Code Reflected?


‌M code and G code have an extremely important position in CNC machining. To understand their importance, we must first understand their impact on the entire CNC parts machining process.


They are used to control the main motion and auxiliary functions of the machine tool respectively, which are of positive significance for ensuring the machining quality and accuracy of parts, preventing interference between machining axes or tools, and improving the safety and stable operation of CNC machine tools. Let's explain it in detail below so that everyone can intuitively feel the importance of g code and m code. ‌


‌The Importance of G code‌ ‌


G code‌'s importance is mainly reflected in that it involves almost all motion control of CNC machine tools, including linear interpolation (G01), clockwise circular motion (G02), and various complex shapes. This means that if you want to remove a fixed point from a piece of raw material, you must use G code to achieve it.


Therefore, it can be said that G code is the basis of CNC programming. When you understand it, it can help you master the basic skills of CNC machining and complete machining tasks from simple to complex.


In addition, G code is not only a programming language but also a way to intuitively reflect the working status and machining process of machine tools. As you learn and understand G code in-depth, you will find that using G code well will directly affect programming efficiency and processing accuracy.


The importance of M code


Compared with G code, the actual application scenarios of M code are more streamlined in number, such as tool change, coolant switch, spindle start and stop, etc., but it involves the operation process and processing safety of CNC machine tools. Proficiency in M code can ensure the efficient operation of CNC machine tools during processing, and it is also an important factor in ensuring the safety of operators.


G Code and M Code In CNC Programming


What Are the Types of M Codes and G Codes?


Due to the differences in each CNC machine tool, the specific instructions of M codes and G codes will be slightly different. In actual application, the specific machine tool instructions should be followed. The following are some operation instructions about g codes (preparation function codes) and ‌M codes‌ (auxiliary function codes) that we have compiled based on existing resources. For reference only:


Different types of G code instructions


In actual CNC manufacturing operation scenarios, the execution of G codes is more complicated, including but not limited to the following parts:


♦G00: Rapid positioning

♦G01: Linear interpolation

♦G02 and G03: Responsible for clockwise and counterclockwise circular interpolation respectively

♦G04: Used for pause

♦G28 and G29: Involving returning to the reference point and its opposite action

♦G90 and G91: Represent absolute value programming and incremental programming respectively


Different Types of Instructions for M codes


As an auxiliary operation for controlling CNC machine tools, the instructions of M codes are more streamlined, such as starting and stopping the spindle, turning on and off the cutting fluid, automatic tool exchange, etc. Specifically, M codes include but are not limited to:


♦M00: Program pause

♦M02: Program end

♦M03 and M04: Control the forward and reverse rotation of the spindle respectively

♦M05: Stop the spindle

♦M06: Perform automatic tool exchange


What is the main difference between M codes and G codes?


Generally speaking, the role of M codes in CNC programming is more like that of officers, generals, and leaders, who are mainly responsible for regular command movements, while G codes are the specific executors below, which you can understand as soldiers.


G obeys M's instructions and orderly develops the raw materials (you can understand it as the combat area) in an area, and the entire combat work will proceed quickly. If G does not obey M's instructions or executes instructions randomly, likely, that M's instructions are not clear enough, and the problem reflected is that there are certain problems with the program code compiled by CNC programming.


Which CNC machines are equipped with M code and G code?


In modern CNC programming, G code and M code are the most basic instructions, that is, these two codes are widely used in CNC machine tool workshops around the world, and almost all CNC control systems support these two basic instructions.


For example, in the CNC manufacturing industry, the most common CNC machine tools, including machining centers, CNC lathes, milling machines, etc. are equipped with these two language tools. You can understand that whether it is CNC milling, turning, or other types of CNC machining, M code, and G code are indispensable tools.


Conclusion


In this article, we have explained the G code and M code in CNC programming in detail, hoping to give you a certain understanding of the CNC industry.


If you are interested in CNC manufacturing, you can devote yourself to this industry, and practice G code and M code in combination with actual processing cases, which can greatly improve your learning interest and hands-on ability. By analyzing and solving problems encountered in actual CNC machining, you can not only consolidate the basic knowledge but also grow rapidly in actual operation.


With the development of technology, some advanced programming languages (such as macro programming, parameter programming, etc.) have also begun to be applied to CNC programming. These high-level languages can simplify the programming process, and improve programming efficiency and machining accuracy. If you can use high-level programming languages reasonably based on mastering G code and M code, you can better meet the needs of complex machining.


Let Us Handle Your CNC Parts Manufacturing Needs through CNC Coding


If you are looking for a professional and reliable CNC machining service provider, then you will never regret choosing us. RT is one of the earliest people engaged in CNC manufacturing. We have absolute enthusiasm and confidence in CNC manufacturing. Almost all customers who have worked with us have expressed sincere admiration for our services.


Upload your CAD file now and we will provide you with a free quotation service. Don't worry, we can't make the CNC parts effect you want. We have a first-class CNC team, from CNC programming to manufacturing, just to meet your needs.


If you want to know more CNC dynamic information, please pay attention to our website at any time. We will update various CNC processing blogs and services in real time.


What do G, M, S, and T mean in CNC?


In fact, due to the differences in CNC machine tools, the functions corresponding to each editing code will be different. In this article, I will organize the commonly used operating instructions as follows, hoping to help you.


Functions of programming letter keys:


G: Preparation function Command action mode

M: Auxiliary function Machine tool M code command

F: Feed speed command

S: Spindle function Spindle speed command

T: Tool function Tool number command

I: Coordinate word Arc center X-axis coordinate

J: Coordinate word Arc center Y-axis coordinate

K: Coordinate word Arc center Z-axis coordinate

P: Program number used for a pause or start of a function in the program

L: Number of repetitions Number of repetitions of fixed cycles and subroutines

D: Compensation number Tool radius compensation command

N: Sequence number Sequence segment sequence number

U: Coordinate word Incremental coordinate value or pause time of additional axis parallel to the X axis

V: Coordinate word Incremental coordinate value of additional axis parallel to the Y axis

W: Coordinate word Incremental coordinate value of additional axis parallel to the Z axis

R: Coordinate word Fixed distance or arc radius designation in a fixed cycle

X: Coordinate word Absolute coordinate value of X-axis or pause time

Y: Coordinate word Absolute coordinate value of Y axis

Z: Coordinate word Absolute coordinate value of Z axis

A: Coordinate word Rotation around the X-axis

B: Coordinate word Rotation around the Y-axis

C: Coordinate word Rotation around the Z-axis

E: Second feed function

H: Compensation number designation

O: Sequence number Sequence number, subroutine sequence number designation

Q: Fixed cycle end segment number or fixed distance in a fixed cycle

Recent Stories

Can a Right Angle Really Cause Million-Dollar Losses? – The Life-or-Death Choices of "Corners" in Component Manufacturing

Jul 24, 2025

Can a Right Angle Really Cause Million-Dollar Losses? – The Life-or-Death Choices of "Corners" in Component Manufacturing

That unassuming "right angle" marked on your issued drawing could secretly plant the seeds of product failure, cost explosions, or even customer claims.

How Does CNC Machining Drive Innovation in Automotive Parts Manufacturing?

Apr 20, 2025

How Does CNC Machining Drive Innovation in Automotive Parts Manufacturing?

CNC machining, with its high precision and efficiency, is reshaping the automotive parts manufacturing industry. This article will explore the applications of CNC milling and turning in the automotive sector and how they help manufacturers achieve lighter, more durable components.

How to Enhance Product Value Through Surface Treatment?

Jun 12, 2025

How to Enhance Product Value Through Surface Treatment?

Surface treatment is not just about aesthetics; it also enhances the durability and functionality of products. This article will introduce common surface treatment techniques, such as electroplating, spraying, and anodizing, and how they add value to your products.

The Future of Injection Molding

Jun 12, 2025

The Future of Injection Molding

Injection molding technology is constantly evolving, with new materials and technologies reshaping the manufacturing landscape. This article will explore the latest trends in injection molding and how they enable businesses to achieve more efficient and environmentally friendly production.

Silicone Molding: The Ideal Choice for Small-Batch Production

Jun 12, 2025

Silicone Molding: The Ideal Choice for Small-Batch Production

Silicone molding is an ideal process for small-batch production and prototyping. This article will introduce how silicone molding works, its applicable scenarios, and how it helps businesses save costs and time during product development.

The Secrets of Sheet Metal Processing

Apr 22, 2025

The Secrets of Sheet Metal Processing

Sheet metal processing is an indispensable part of manufacturing. This article will delve into the key steps of sheet metal processing, including cutting, bending, and welding, as well as how to reduce costs and improve efficiency through optimized design.

Our Other Manufacturing Solutions

CNC Machining

CNC Machining

CNC milling tolerance: ±0.02mm-±0.005mm

CNC turning tolerance as low as ±0.0003 inches (±0.010 mm)

CNC machines: 15cnc lathes + 35 (3&4&5) milling machines

Maximum part processing size:

3200mm*2300mm*1000mm

Processable materials: common metals & plastics other than metal tungsten alloys

Large-scale machining of parts in just a few days

Tolerances as low as ±0.0003 inches (±0.010 mm)

Sheet Metal Fabrication

Sheet Metal Fabrication

CNC (engraving and milling machine) working stroke:

500*600*210MM - 1500*2200*500MM

Accuracy: ±0.02 - ±0.05mm

Air compressor working stroke: 

maximum 22KW

Maximum processing aperture 32mm

Cutting stroke: 1.5KW - 6KW

Processing materials: steel plate 

materials below 6MM

Provide free assembly service

Discover and help you solve problems such as parts and accessories conflicts at the source of production.

Injection Molding

Injection Molding

Manufacturing tolerance: ±0.004 to 0.012 Inch (±0.10 -±0.30mm)

Processing materials: more than 100 kinds,

General plastics (such as PE)

Engineering plastics (such as PA)

Special plastics (such as PTFE)

Injection molding machines: 14 units

Provide general plastics (such as PE), engineering plastics (such as PA), special plastics (PTFE)

Tolerances as low as ±0.004 to 0.012 inches (±0.10-±0.30mm)

Vacuum Casting

Vacuum Casting

Production of small batches of parts

High fidelity

Low cost

Fast production

Manufacturing tolerance: ±0.10 to ±0.30mm

Used materials: Plastic-like

The tolerance range can be between ±0.10 and ±0.30 mm

ruitai05@szrtmj.com

+86 135 1000 5651

Copyright © RT MANUFACTURE. All rights reserved | Sitemap

Cookies

We use cookies to ensure that we give you the best experience on and off our website. please review our privacy policy