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 cnc routers, router lifts and router 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.
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.
List of M Code Commands
M codes in CNC are almost the same for turning and milling. M codes are usually used for turning ON/OFF various processes. The following are the M codes.
M00 – Program stop
M01 – Optional stop
M02 – Program end
M03 – Spindle start
M04 – Spindle start (anti-clockwise)
M05 – Spindle stop
M06 – Tool change
M07 – Coolant ON (Within the spindle)
M08 – Coolant ON
M09 – Coolant OFF
M30 – End program
M98 – Call subroutine
M99 – End subroutine
Commonly Used M Code Commands
The M in M-code signifies that there will be a miscellaneous command after it. M03, for example, activates the cnc spindle and is usually followed by a S code that sets the rate. Following are some of the M-code commands:
- For stopping the program: M00
- For the end of program: M02
- For spindle start–forward, of clockwise rotation M03
- For reversing spindle or starting, counterclockwise rotation: M04
- For spindle stop: M05
- 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.
List of G Code Commands
The following are some of the commonly used G codes and their description in CNC milling.

G00 – Rapid positioning
G01 – Linear travel/interpolation
G02 – Circular travel/interpolation (clockwise)
G03 – Circular interpolation (Anti-clockwise)
G04 – Dwell
G10 – Programmable data input
G17 – XY plane selection
G18 – ZX plane selection
G19 – YZ plane selection
G20 – Programming in inch units
G21 – Programming in metric units
G27 – Reference point return check
G28 – Automatic return to point of reference
G29 – Automatic return from the point of reference
G30 – Return to 2nd, 3rd, or 4th point of reference
G40 – Cutter diameter compensation cancel
G41 – Cutter diameter compensation left
G42 – Cutter diameter compensation right
G43 – Tool length compensation in positive (+) sign
G44 – Tool length compensation in a negative (-) sign
G45 – Tool offset increase
G46 – Tool offset decrease
G49 – Tool length offset cancel
G53 – Machine coordinate system
G54-59 – Work coordinate system
G80 – Canned cycle cancel
G81 – Drilling cycle canned
G82 – Counter boring or countersinking cycle canned
G83 – Peck drilling cycle (canned)
G84 – Tapping cycle (canned)
G85 – Reaming cycle (canned)
G86 – Boring cycle (canned)
G90 – Absolute positioning
G91 – Incremental positioning
G92 – Zero preset
G94 – Feed rate in mm/min
G95 – Feed rate in mm/rev
G96 – Constant surface speed control
G97 – Constant surface speed control cancel
Commonly Used G Code Commands
Here are common individual codes, when combined with other codes are responsible for the function of the machines.
- For Rapid positioning: G00
- For linear interpolation: G01
- For circular/helical Interpolation: G02
- For programming in inches: G20
- 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:
- For directing the tool on x-axis: A
- For giving radius of arcs: B
- For the three-dimensional movement: X, Y, Z
- 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.
Conclusion
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!