Send Your Inquiry Today
Sheet Metal Fabrication Factory in China Get a Quote
G and M Codes

G and M Codes

The CNC cutting tools are moved by G-codes and M-codes, which are effectively computer instructions or programming languages, to create the desired product. They might be challenging to apply. Because these programs differ from machine to machine and call for the knowledge of a trained CNC programmer.

G Code: What is it?

Geometry, or G-code, is the most widely used programming language for CNC machinery.

CNC machines require instructions on where to start, how to move, and when to finish in order to be programmed to make a part.

Most G-code commands have an alphabetical structure.

G Code What is it
M Code What Is It

M Code: What Is It?

The M code is a group of auxiliary directives that govern all non-geometric operations on the machine.

These codes, which regulate non-cutting operations, include:

  • Stopping programs
  • Adding coolant to the machine
  • Shutting it off when the temperature dips

These are referred to as irregular codes by machine operators.

G and M Codes Differences

Machining specialists use G and M, two different codes, simultaneously while employing CNC machining techniques.

  1. G code directives are usually unique on CNC machines, although M codes are usually interchangeable.
  2. M codes handle the activities that need to be done in between movements, while G codes control how the machine moves.
  3. The programmable logic controller of the machine is activated by the M code, whereas the CNC machine is activated by the G code.
G and M Codes Differences

List of Commands for M and G Code

List of Commands for M and G Code (1)
List of Commands for M and G Code (2)

This section will demonstrate several basic G and M code examples along with their definitions. The following are a few instances of code:

CNC Lathe G Codes

G00 – Motion with Quick Position

G01 – Linear Interpolation Motion, Chamfer and Corner Rounding, or Modal Linear Motion

G02 – Motion – Modal Cyclic Wave Interpolation

G03 – Calculating Modal Circular Interpolation Motion

G04 – Stay for P = Seconds (P). In milliseconds

G05 – Live Tooling and Optional Fine Spindle Control Motion

G09 – Accurate Stop

G10 – Configurable Offset Adjustment


CNC Lathes M Codes

M00 – Stop of Program

M01 – Program Stop Option

M02 – End of the Program

M03 – Push Forward with Spindle (S)

M04 – Counterclockwise Spindle (S)

M05 – Spindle Stop

M08 – The cooling system is on.

M09 – Coolant Discharged

M10 – Clamp, Chuck


CNC Milling G Code

G00 – Quick Motion

G01 – Motion of Linear Interpolation

G02 – Motion of CW Interpolation

G03 – Motion of CCW Interpolation

G04 – Reside

G09 – Precise Stop

G10 – Adjustable Offset Configuration

G12 – CW Milling of Circular Pocks

G13 – CCW Milling of Circular Pocks

G17 – Choosing an XY Plane


CNC Milling M Codes

M00 – Terminating Program

M01 – Program Stop Optional

M02 – Termination of Program (Setting 39)

M03 – Spindle On, Rotating Clockwise (S) (Setting 144)

M04 – Counterclockwise (S) Spindle On (Setting 144)

M05 – Stop of Spindles

M06 – Adjusting the Tool (T) (Position 42, 87, 155)

M08 – Coolant is on (Setting 32)

M09 – Coolant Not in Use

M10 – Applying the 4th Axis Brake

Are G-Code Commands Used by All CNC Machines?

Yes, indeed! CNC programming in G code is used by all CNC machines. This gives the machine directions on how, where, and when to move.

What is the Total Number of G Codes?

There are roughly one hundred G codes. While some of these codes are shared by both turning and milling machines, they are unique to each machine.

How Can the G Codes Be Read?

When examining a G code file, deconstruct its long, intricate contents into its markers and Cartesian coordinates. Utilize a key to help you remember any codes you may have forgotten, and try searching for the codes you are most familiar with.

Every sequence of numbers has a purpose, and the G codes adhere to a certain framework in order to perform their duties as intended.

How Can the M-Codes Be Read?

The machine’s optimal settings are commonly activated by adding codes from other categories to M codes, or miscellaneous codes. Despite being organized in a particular order to maintain process continuity, this gives lines with M codes a complex appearance.

In Summary

One essential component of CNC machining is the use of CNC machines. G and M codes, on the other hand, provide instructions to these machines and are necessary for them to operate. Productivity in CNC machining and successful part manufacture depend on knowing how to generate these codes. You can jumpstart your CNC programming career by mastering these codes.

Update cookies preferences
Scroll to Top