Unveiling the Power of G and M Codes in CNC Machines: A Comprehensive Guide


In the world of CNC (Computer Numerical Control) machining, G and M codes play a vital role. These codes are essential instructions that control the movements and operations of CNC machines. Understanding and utilizing G and M codes can greatly enhance the efficiency and precision of CNC machining processes. In this blog post, we will delve into the world of G and M codes, exploring their functionalities and providing practical examples. So, let's unlock the full potential of CNC machines with G and M codes!

What are G Codes?\

G codes in CNC machining are commands that govern specific movements and functions. These codes are universal and are recognized by most CNC machines across various industries. G codes control actions such as rapid movement, feed rates, tool changes, and more. They facilitate precise positioning and ensure that the CNC machine executes the correct actions with utmost accuracy.

Some commonly used G codes include:

G00: Rapid Movement

G01: Linear Interpolation

G02/G03: Circular Interpolation (Clockwise/Anti-clockwise)

G17/G18/G19: Plane Selection (XY, ZX, YZ)

G20/G21: Unit Conversion (Inches/Millimeters)

G28: Return to Home Position

G40/G41/G42: Cutter Compensation (Off/Left/Right)

G80: Cancel Canned Cycle

What are M Codes?\

M codes, on the other hand, are used to control auxiliary functions and actions on CNC machines. These codes govern actions such as spindle operations, coolant control, tool changes, and more. M codes are specific to the machine or manufacturer and can vary between different CNC machines.

Here are some commonly used M codes:

M03: Spindle On (Clockwise)

M04: Spindle On (Counterclockwise)

M05: Spindle Off

M06: Tool Change

M08: Coolant On

M09: Coolant Off

M30/M02: Program End/Program Stop

Practical Examples of G and M Codes:\

To better understand the applications of G and M codes, let's consider a few practical examples:

1. Contouring:\

To create a complex shape or contour on a workpiece, we can use a combination of G02/G03 (circular interpolation) and G01 (linear interpolation) codes. These codes define the movement path and speed of the cutting tool, resulting in precise contouring.

2. Drilling:\

For drilling operations, G codes come into play. G00 is used for rapid positioning to the drilling location, followed by G81 for a simple drilling cycle. The drilling cycle is executed by specifying the depth, feed rate, and retract clearance to drill the desired holes.

3. Tool Change:\

When it's necessary to change the cutting tool during the machining process, M06 code is used. This code prompts the CNC machine to stop and wait for the operator to change the tool. After the tool change, the machine resumes operation at the next tool in the sequence.

4. Spindle Control:\

M codes are employed to control the spindle rotation. For instance, M03 activates the spindle in a clockwise direction, while M04 activates it in a counterclockwise direction. M05 turns off the spindle completely.

In conclusion, G and M codes are fundamental elements in CNC machining. They enable precise control over machine movements, tool changes, spindle operations, and more. By mastering these codes, operators can optimize productivity, eliminate errors, and achieve exceptional results in CNC machining processes.

Remember, practicing with different G and M codes, as well as referring to machine-specific manuals, will enhance your abilities and familiarity with these codes. So, delve into the world of G and M codes, unlock the potential of your CNC machine, and take your machining capabilities to new heights!

g and m codes for cnc machines

On demand manufacturing online CNC Machining Services

If you need custom machined parts with complex geometries, or get end-use products in the shortest possible time, sigma technik limited is good enough to break through all of that and achieve your idea immediately.

  • One -to-one friendly service
  • Instant quota within couple of hours
  • Tolerances down to +-0.01mm
  • From one -off prototypes to full mass production
Mission And Vision


CNC Machining

Equipped with 3-4-5 axis CNC milling and CNC turning machines, which enable us to handle even more complex parts with high precision.

Rapid Injection molding

Low investment, fast lead time, perfect for your start-up business.

Sheet metal

Our talented sheet metal engineers and skilled craftsmen work together to provide high quality custom metal products.

3D Printing

We offer SLA/SLS technologies to transform your 3D files into physical parts.


Delicated Employees


Countries Served


Satisfied Customers


Projects Delivered Per Month

About Us

What can we do?

Sigma Technik Limited, as a prototype production company and rapid manufacturer focusing on rapid prototyping and low volume production of plastic and metal parts, has advanced manufacturing technology, one-stop service, diversified manufacturing methods, on-demand manufacturing services and efficient manufacturing processes, which can provide customers with high-quality, efficient and customized product manufacturing services and help customers improve product quality and market competitiveness.

CNC Machining Case Application Field

CNC machining is a versatile manufacturing technology that can be used for a wide range of applications. Common examples include components for the aerospace, automotive, medical industries and etc.

Let’s start a great partnership journey!

CNC Machining FAQs

Get the support you need on CNC machining and engineering information by reading the FAQ here.

It may be caused by unstable processing equipment or tool wear and other reasons, so it is necessary to check the equipment and tools in time and repair or replace them.

It may be due to severe wear of cutting tools or inappropriate cutting parameters, which require timely replacement or adjustment of cutting tools or adjustment of machining parameters.

It may be caused by programming errors, program transmission errors, or programming parameter settings, and it is necessary to check and modify the program in a timely manner.

It may be due to equipment imbalance or unstable cutting tools during the processing, and timely adjustment of equipment and tools is necessary.

The quality and usage method of cutting fluid can affect the surface quality of parts and tool life. It is necessary to choose a suitable cutting fluid based on the processing materials and cutting conditions, and use it according to the instructions.

It may be due to residual stress in the material and thermal deformation during processing, and it is necessary to consider the compatibility between the material and processing technology to reduce part deformation.