Last Updated on May 16, 2022 | Andrew Jason

Have you ever wondered how CNC machines work? CNC machining is among the most important industrial processes. Its machining methods create complex and sophisticated machines such as routers, lifts and tables that are used in a wide range of industries. These procedures, on the other hand, would’ve been hard to carry out without the equipment that powers these. Hence, it’s called the art of CNC programming. These CNC machines work due to CNC programming that has g-code and m-code for different purposes. While all these CNC codes are commonly used together within machine tools, these are very distinct from one another. 

G and M Codes

What are the distinctions? What functions do these codes govern on CNC machines? What is CNC programming, exactly? Read this article until the conclusion to find out the answers to these and other questions. What functions do these codes govern on CNC machines and their differences?

What is CNC programming?

The art of programming CNC machines is called CNC programming. It’s also known as Computer numerical control programming. The codes, G code and M code are contained in a file. Each code is there to serve its own purpose. G codes control the mobility and functioning inside the machine, whereas M codes control the actions outside of the machine. The CNC machine is activated by the G code, whereas the programmable logic controller is activated by the M code.

What is G and M code?

The entire CNC machining is dependent on these two codes. G and M codes. This section will provide answers to these queries as well as a comparison of the two codes.

M Code 

M-code is the CNC machine control language. It’s used in collaboration with G-code to turn on and off certain machine functionalities. There is some feature similarity across many CNC controller platforms, like G-code, but the actual specifications for any M-code operation is laid out by the control maker.


The M in M-code signifies that there will be a miscellaneous command after it. M03, for example, activates the spindle and is usually followed by a S code that sets the rate. Following are some of the M-code commands: 

  1. For stopping the program: M00
  2. For the end of program: M02
  3. For spindle start–forward, of clockwise rotation M03
  4. For reversing spindle or starting, counterclockwise rotation: M04
  5. For spindle stop: M05
  6. For changing tool: M06

G code 

The official name of G-code is RS-274D. Majority of the instructions in this code begin with the letter G. It represents Geometry. The G code, which is given in an alphanumeric manner, is fundamental for the machine’s motions. When creating a unit, it directs the machinery where and how to start, its movement, and when to stop. Despite its apparent simplicity, G code programming can be difficult for CNC programmers. This is because different machines read G codes in various formats.


Here are common individual codes, when combined with other codes are responsible for the function of the machines. 

  1. For Rapid positioning: G00
  2. For linear interpolation: G01
  3. For circular/helical Interpolation: G02
  4.  For programming in inches: G20
  5. For programming in mm: G21

While the letter G is the most used in G code CNC programming, it is not the only one. Several other letters in the code have functions as well. such as: 

  1. For directing the tool on x-axis: A
  2. For giving radius of arcs: B
  3. For the three-dimensional movement: X, Y, Z
  4. For the incremental center of any arc: I and J

The G code uses other letters as well but that entirely depends on the capabilities of the machine.

Difference in CNC codes in Machines

The G codes are instructions for motion or location relative to the work, which are commonly employed in CNC turning for generating cylinder surfaces or CNC milling for fabricating rectangular plate profiles. While on the other hand, M codes control machine functions such as pace, cooling, and so on. G-code is used to design CNC parts or products, while M-code is used to turn the machine on and off. The numerically controlled machine is activated by G-code, whereas the machine’s PLC is activated by M-code.

Is CNC programming hard?

Well, basic CNC programming is simple to learn if you have a basic understanding of mathematics and how milling works. This is normally learned in a matter of days. Aa moderate level, CNC programming abilities can be gained in under a year, while expert level in CNC programming skills can take years to master. There are a lot of CNC Software available in the market to create CNC design.


G and M codes have a great importance in the CNC machine industry because they instruct the machines to perform functions. Understanding how to produce these codes is critical for successful CNC machining and part manufacturing. Mastering these codes will give you a leg up on the competition when it comes to CNC programming. For people who enjoy creating and have a keen eye for detail, a career as a CNC programmer is interesting and fulfilling. This is a rapidly expanding profession with plenty of prospects for those who have been trained to operate complex CNC equipment. Hence, if your interested in this field than you should probably go for it or if you’re reading this article, we hope it proved to be informative for you. 

Happy Reading!