The Ultimate Guide to G and M Codes

Before G & M Codes came into existence, machine shops had to use a much simpler, less convenient way to automate machine movement.

A Brief History of Computer Aided Manufacturing

Much like the earliest computers were programmed by punch-cards that indicated instructions, machines, like mills and lathes, also used punch-cards or tapes to control the movement and the path of the machine.

Programming the machines with coded cards allowed manufacturers to create exact replicas of precise parts.

From Punch-Cards to Coding: The Start of G and M Codes

The punch-card system was effective, but tedious. As you may infer, paper cards were often damaged from wear and tear. Using a damaged card could result in errors and problems with the parts and machines themselves.

As computers with analog and digital coding progressed, machine functions were able to be programmed with advanced numerical control instead of cards. The most popular coding system used for numerical control was “G-Code,” and it is still used today.

Although an advancement, the first numerically controlled machines required the codes to be input into the computer manually. This could be a tedious process for operators, since the more complex the part, the more instructions were required to make it.

Today’s Software

Today, with advanced software, industrial machines have become complete CNC machines, or Computer Numerically Controlled. Computer-aided Design (CAD) software can generate exact specifications for intricate parts and Computer-Aided Manufacturing (CAM) software helps to translate these specifications into the G-Code read by the machines themselves.

CNC programming files can be saved and the code can be modified and streamlined for future upgrades. Because of this, CNC machine shops are often used to manufacture sophisticated parts for:

  • Military applications
  • The automotive industry
  • Aerospace
  • Other components produced repeatedly in large quantities

Ultimate Guide to G and M Codes

The Rise of CNC G Code

Due to the progressing complexity of both manufactured parts and the instructions required to create them, a standardized coding language became necessary to control CNC machines.

Commonly referred to as “G-Code” as a whole, this programming language actually uses both G and M codes, both appearing in an alphanumeric format, to designate the machine’s functions.

The Difference Between G Codes and M Codes

The biggest difference between G & M Codes is that the “G” stands for “geometry” and

tells the machines how to move the tool. While M Codes are often referred to as “miscellaneous” or “auxiliary” codes that tell the machine when to stop, start and perform other non-cutting functions.

To put it another way:

G Codes control: M Codes control:
Directions for active movement and cutting Non-geometric commands to stop/start, turn on/off auxiliary, make changes in tooling

Both codes control CNC machines in different ways and are used together to form complete programs. As CNC machines perform their coded functions, the code may be displayed on monitors.

CNC G-Code Functions

CNC Machining G-code often tells CNC equipment to make a rapid move in a straight line or to move in a circle at a specified speed, using letters that stand for different movements. The letters used depend on the capabilities of the machine.

While the letter “G” is used often, some others could be:

A: Directs tool around the x-axis

T: Tool Number

F: Feed Rate

R: Indicates radius of the arc to make

X, Y, Z: Instructs tool positioning in three axes or dimensions

  • X represents the horizontal axes
  • Y represents the vertical axes
  • Z represents depth

I & J: Designate the incremental center of any arc the machine makes.

N: N informs the line number positioning

Letters are often followed by numbers to indicate further specification of movement or and/or a geometric location.

CNC G Code Examples

This list of popular CNC G codes gives a good example of functions that may be performed.

G00: Rapid PositionG01: Linear Interpolation MotionG02: Circular Interpolation MotionG03: CCW Interpolation MotionG04: Dwell G09: Exact StopG10: Programmable Offset SettingG12: CW Circular Pock Milling G13: CCW Circular Pock Milling G17: XY Plane Selection

Need Help with Machining Parts?

Our team offers precision production machining for industries like Aerospace, Medical, Electronics, and more.

Learn More

CNC M Code Examples

This list of codes for CNC mills gives a good example of auxiliary functions. 

M00: Program StopM01: Optional Program StopM02: Program End (Setting 39)M03: Spindle On, Clockwise (S) (Setting 144)M04: Spindle On, Counterclockwise (S) (Setting 144) M05: Spindle StopM06: Tool Change (T) (Setting 42, 87, 155)M08: Coolant On (Setting 32)M09: Coolant OffM10: 4th Axis Brake On

Again, M codes control non-cutting actions like stopping entire programs, flooding the machine with coolants, shutting them off after the temperature drops, or changing palettes.

G and M Codes

Intricacies of G and M Codes

The examples above are just some basic commands used in G-code programming. More complex examples will string the letters and numbers together like this:

G00G59X-120.Y-3

This code can be read as:

  • G00 = positioning or rapid movement to
  • G59 = work coordinates
  • X-120 = 120mm on the X-axis
  • Y-3 = 3mm on the Y-axis

There are still a few more intricacies to know when learning CNC G and M codes.

  • Knowing your machine is key. Different machines read code in different formats. This can mean small changes like the number of zeros between numbers and letters. It can also mean that one device reads an “A” as a different function than another.
  • There are different dialects of G code.Some companies may have their own proprietary coding.
  • Not all CNC machines use G code. Other programming languages include “Mazak’s Mazatrol” or “Conversational Programming.”
  • It is best to have one M code command per block of information.
  • It can take weeks to generate codes for intricate parts. Even using sophisticated CAM software, complex, large parts that require the use of multiple tools may need extra programming time. Simple parts may only take an hour.
  • G code may use more coordinates to program up to four or five axes.
Want to Learn More About CNC Machining? Check out These Blogs:

Who Needs to Know CNC G and M Codes

Anyone working in manufacturing can benefit from having a general sense of what G & M Codes are and how they function.

Experienced machine engineers, supervisors and operators will want to know G code in a more thorough way, in order to efficiently run machines, edit programming and find solutions.

Even though software plays a big part in code generation, the codes must be perfect to prevent accidents and errors. Operators can read directions easier than they know G code, though they no longer need to be memorized.

Most machines have a programming book to help operators get to know the correct dialect and requirements. The software will only do as much as the operator or programmer tells it to, so understanding the coded instructions generated is crucial.

Talk to the G and M Code Experts

Do you have parts that need to be precision-made with CNC machining? Talk to us today and get a free quote for your project.

Search