Introduction

You might feel that understanding G-codes and M-codes is a tough task. That’s not true, though. When you have a keen interest in CNC machining or are up for working in a CNC machine shop, gaining a better knowledge of both codes will help you perform your duties.

To help, we have compiled the complete guide to understand both G codes and M codes here. This blog post will cover:

  • G and M-codes
  • History of CNC programming
  • The role of machine programming in CNC machining
  • G and M-code command list

… and more. Let’s crack the G&M codes first.

G-code and M code, CNC Programming

What are G and M Codes?

You can’t CNC machine the parts until you are well-versed in the correct way to use the CNC machines. Then, how can one be adept at using CNC machines?

You can master handling the CNC machines by learning the CNC machine programming language and getting the know-how to CNC machining codes – G-Code and M-Code, for instance. Without better knowledge of these CNC machined codes, you can’t succeed in making the CNC parts. Now, Let’s have a quick look and understand these two types of codes.

G-Code

G-Code is the most common programming language. A G-Code in CNC Programming works like a controller and dictator.  It controls the machine’s movement and dictates how and where it should move to formulate the end CNC machined product.

M-Code

M-Code is used for specific applications. An M-Code CNC Programming controls different machine functions, including starting and stopping specific actions or programs.

G-Code and M-Code work together to fabricate CNC machined parts and components. Hence, they are essential in the manufacturing and industrial sectors.

History of CNC Programming

In the late 1950s, the MIT Servomechanisms Laboratory, the first implementation of numerical control programming, was developed. Since then, multiple commercial and non-commercial organizations have developed numerical control programming implementations. G-code was mainly used in these implementations.

Later on, in 1960, the Electronic Industry Alliance of numerical control programming language was standardized in the United States. A final revision was then approved in February 1980. One standardized version of G-Code is known as BCL (Binary Cutter Language). This language was developed to control CNC machines in straight lines and arcs.

Many tool builders attempted to deal with the compatibility issues by standardizing the machine tool controllers during the 1970s and 1990s. In 2010, controller differences and incompatibilities were no more than troublesome. Because machining operations were then being developed with CAD/CAM applications.

According to Wikipedia, “G-Code started as a language that lacked loops, conditional operators, and programmer-declared variables that could not encode logic.” However, now G-Code includes macro language capabilities that are somewhat closer to high-level programming languages.

The Role of Machine Programming in CNC Machining

The letter “C” in the CNC programming refers to the “Computer” that operates the system of the programming machine. The computers only understand the specific languages to accomplish the different tasks.

The same goes for CNC Programming! The machinists may input the programs manually or with the CAD software. No matter what method the machinist employs, the code needs to be PERFECT.

Before computer-based machine programming, maintaining the correct programs for multiple machining was difficult due to the paper format of the NC Programming.

How Does CNC Programming Control CNC Machines?

Before we know how CNC programming controls CNC machines, let’s go into the flashback and learn how CNC machines would operate before the arrival of computers.

In the days before computers, machinists controlled CNC machines with cards and tapes. For creating codes, they would punch the cards in different orders. This was an effective method, BUT it was a tiresome task. Moreover, these cards would get damaged, and they might get lost. As A Result, the production procedure had to face multiple problems.

Thanks to the advent of computers, most production issues came to an end. Still, all was not rainbows and sunshine…They had to input all the codes manually. This was again an annoying job to do. And, when it came to manufacturing more sophisticated parts, they had to follow more instructions. Hence, manual coding would become more of a labor.

Sooner, when the more advanced computers became the norm, the machinists would simply instruct the software. Then, this advanced software would generate the G codes and M codes that the machines understand. Computer-Aided Design (CAD) and Computer-Aided Manufacturing (CAM) software have made code generation much easier!

Understanding G and M Codes in More Detail

What is G Code? 

G code is also known as RS-274D. According to Wikipedia, G-code is the most widely used computer numerical control (CNC) programming language. The language is used to control many computer tools and has different dialects. G-code is written in a logical language.

The letter “G” in the G-code stands for “Geometry.” While instructing a CNC machine, the letter “G” followed by a particular number makes a command to change the geometry of the part that’s being machined.

Some Important G Codes

Below are some of the G-codes and what they mean.

  • G00 – Rapid movement (for a specific coordinate position)
  • G01 – Linear feed move
  • G02 – Clockwise feed move
  • G03 – Anticlockwise feed move

A geometric location follows all these G-codes. Geometry consists of coordinates along axes, i.e. an “X” and “Y” on a plane.

Functions of G Codes

G-codes often start with the letter “G,” but that’s not the only number used in G-code programming. Following is the list of some more letters that are used in G-coding.

  • A:  To direct the tool around the x-axis
  • R: To give the radius of the arcs
  • X, Y, and Z: To indicate the tool’s positions in three dimensions – X represents the horizontal dimensions, Y represents the vertical dimension, and Z represents the depth of the tool.
  • I and J: To designate the incremental center of any arc the machine makes.
  • N: To give the line number
  • F: To indicate how quickly the machine feeds the piece.
  • S: To tell the machine how quickly to move the spindle.
  • T: To tell the machine which tools to use.
  • R: To give the radius of arcs (made by the machine)
  • A: To direct the tool around the axis
  • B: To show the rotational value around the x-axis
  • C: An auxiliary axis rotates around the Z-axis from the C value.
  • D: To show how much the system offsets the tool diameter.
  • L: To give the system a value to indicate repeating operations and to tell how many times they need to loop
  • P: To jump in time or a delayed time (with the P command)

G-code also may use some other letters, but it depends on the capabilities of the CNC machine. G-code can repeat an action until it’s stopped.

G-codes are single-letter commands that tell the machines what to do. They can also command the machine to move and tell it to do other things like turning the spindle on. These codes make the CNC machines programmable. Which in return gives the CNC machines the flexibility to formulate different parts.

Mostly the G-code commands are in alphanumeric format. Different machines, however, read the G-codes in different formats. This different ability of the machines to read the G-codes depends on:

  • The presence or absence of the spaces
  • The number of zeros between a letter and a command

Hence, the machinist should also be familiar with what type of machine they are using. Otherwise, errors in the commands can lead to different complications.

How to Read the G Codes?

Reading the G-codes isn’t hard. The steps are below.

  • Step 1: Break down the lengthy and complicated contents into the Cartesians coordinates and markers.
  • Step 2: Try looking for the codes you are the most familiar with. You may remind yourself of the codes (you’ve forgotten) with the keys. Because each string of numbers has an order, the G-codes follow a careful structure to carry out the functions properly.

What is M-Code?

M-code is the machine control language that controls the overall program of the programming machine. It directs the machine’s functions.

The letter “M” in the M-codes is referred to as “Miscellaneous.” However, some refer to it as “Machine code” because these codes control the particular operations of the equipment—M-codes direct non-cutting operations of the machine. Without M-codes, you can only instruct the machine to perform the G-codes’ three main movements.

For other operations, such as stopping a program, changing tools, and flooding the system with coolant, the machinists must have the right knowledge to execute M-codes.

Functions of M Codes

M-code controls all the non-geometrical machine functions or, simply put, miscellaneous machine functions. For instance, spindle rotation starts and stops, pallet changes, coolant on and off!

There are two separate actions for M-codes. The machine might need to flood the system with coolants and shut it off after the temperature drops. Like the G-codes, the dialects used for M-codes also depend on the machine. For example, some machines require a zero between the letter and numerals, while others might not need a zero.

Some Important M-Codes                              

Here again, the machinist will have to know some important M codes. Like G-codes, M-codes also contain “M” followed by the number. Below are some of the M-codes with the function they perform. Again, some machines would include a zero between the first letters of the M-code.

  • M00 – Stop (Whatever function the program is performing)
  • M01 – Rotate Spindle (Clockwise)
  • M08 – Flood Coolant On
  • M09 – Flood Coolant Off

M-codes are more specific for different machines than the G-codes and are highly customizable. Moreover, M-codes may also vary with different machines. For example, some machines might support the inclusion of zero between the letter and numbers.

Remember! While setting up G and M codes on the CNC programming machine, the machinist must use the M-code with one command (per block of information). M-codes might turn the machine on and off. Therefore, using M-codes more than once can cause program troubles.

How to Read the M-Codes?

M-codes are not used alone. Instead, they are used with other codes to activate the machine’s ideal settings. Because of their combination with other categories of codes, M-codes appear to be complex.

However, just like the G-codes, they too are set in a specific order that keeps the machining processes running smoothly.

G-Code and M-Code Command Lists

This section will learn different G and M-codes and know what they mean. As mentioned earlier, the G and M-codes are composed of letters followed by a number and some additional units. Therefore, part of these codes might mean the same, but some units might have different meanings.

There are almost a hundred G-codes. Turning and Milling machines have different codes, but they also share some codes in common. Look at some of the G and M codes and understand their functions.

G-Code List for CNC Lathe

G-CodeFunction
G00Rapid Position Motion
G01Linear Interpolation Motion or Linear Motion,
Chamfer and Corner Rounding – Modal
G02CW Circulation Interpolation Motion – Modal
G03CCW Circular Interpolation Motion – Modal
G04Dwell (P) P=Seconds. Milliseconds
G05Fine Spindle Control Motion (Live Tooling) – Optional
G09Exact Stop
G10Programmable Offset Setting

M-Code List for CNC Lathe

M CodeFunction
M00Program Stop – Modal
M01Optional Program Stop – Modal
M02Program End – Modal
M03Spindle on Forward (S) – Modal
M04Spindle on Reverse (S) – Modal
M05Spindle Stop – Modal
M08Coolant On – Modal
M09Coolant Off – Modal
M10Chuck Clamp – Modal

G-Codes for CNC Milling

G-CodeFunction
G00Rapid Motion
G01Linear Interpolation Motion
G02CW Interpolation Motion
G03CCW Interpolation Motion
G04Dwell
G09Exact Stop
G10Programmable Offset Setting
G12CW Circular Pock Milling
G13CCW Circular Pock Milling
G17XY Plane Selection

M-Codes for CNC Milling

M-CodeFunction
M00Program Stop
M01Optional Program Stop
M02Program End
M03Spindle on Clockwise (S)
M04Spindle on Counterclockwise (S)
M05Spindle Stop
M06Tool Change (T)
M08Coolant On
M09Coolant Off
M104th Axis Brake On

What are the Differences Between G and M-Codes?

Although both codes – G and M – go hand in hand while performing CNC programming, they still differ. Below are some of the main differences of G and M codes. They would help you to understand better of G&M codes In CNC manufacturing.

  • G-codes are about Geometry, while M-codes are about miscellaneous machine functions.
  • G-codes differ in different CNC machines, while M-codes are the same in most CNC machines.
  • G-codes command the machine’s motion and function for the product’s design, while M-codes are used to conduct the non-movement operations of the programming.
  • G-code initiates the CNC machine while the M-code initiates the machine’s programmable language controller (PLC).

Who Needs to Learn G-Codes and M-codes?

So, by far, you have gathered enough information about both magical codes to give a basic understanding. But, the real question is, “Who” needs to learn the G and M-codes. Right?

Here is your answer. EVERYONE who works in a machine shop or has the intention to pursue CNC machine programming in the future must get the know-how to use both codes. Because understanding the G and M codes for every worker in the machine shop is mandatory regardless of their position in the machine shop.

It depends on your job responsibilities and how deeper you need to know about these codes. Maybe perusing through a piece of basic information about G and M-codes is sufficient. Or maybe, you need to master both programming codes to accomplish your duties in the workplace. For example, knowing a little bit about the CNC machining codes is good for almost every position in the CNC machine shop. Some machine shops also offer training to make their employees well-versed in CNC programming languages.

CNC machining center and program repeatedly run and without interaction, but that majorly depends on the part (being manufactured) and the manufacturing process. Once the CNC programming is complete, you might not need further edits. But in case, if the manufactured products lack the desired precision, they can be edited to make slight adjustments. However, the editing work is reserved for skilled people only. Like, experienced engineers, setup pros, and supervisors only! 

Need to learn more about G-code and M-code programming? This video source from TITANS will explain the manual programming on a CNC machine. Hope it helps!

Conclusion

G codes and M codes are different. As G-code is about Geometry while M-code is about Machine functions. G Codes are used to make CNC Machines programmable and give CNC machines the flexible to make almost any part. CNC machines use G and M codes for CNC programming.  These codes tell the machines what EXACTLY they should do, including:

  • When to move 
  • Where to move 
  • How to move

In a word, without understanding the G and M-codes, one cannot kick start their career in the CNC machine shop.

Thanks for reading this blog post on G and M-codes, we hope it helped you better understand them. G and M-codes are magical. By the way, what interesting aspects of G and M-codes did you learn today? Leave a comment below.

Thanks for reading. Top Level Intl. is an experienced CNC machining shop in China. We supply custom CNC Machined Parts and Progressive Cavity Pump Spare Parts. So we created this blog and shared some guides and acknowledge involved in. Hope it’s helpful to you. For any questions, feel free to contact us!

Top Level Intl.

We've supplied machined parts to TOP 3 companies for 10+ years. And now we are ready to support you too!
Top Level

Subscriber

No spam! Notifications only about new products and updates.

Leave a Comment