Provide efficient production and faster design to delivery.


Produce precision parts that exceed industry standards.


Create and test products quickly to bring them to market.

Consumer Products

Bring new, affordable products to market faster.


Empower to innovate faster, maximizing performance.


Innovation in enclosures for low-volume production.

Industrial Equipment

Deliver machinery that beats the competition.

New Energy

Speed up innovation and development.

Medical Devices

Build prototypes and products that adhere to medical safety.


Improve efficiency with precise, fast, and constant part quality.


Drive time-to-market through on-demand production.

CNC Machining for Aerospace

The extremely high level of precision needed within the aerospace industry makes CNC machining a suitable manufacturing process for the sector.


This article provides you with a complete guide to aerospace machining and its importance.



Gain valuable insights into manufacturing processes.


Choose from 50+ metals and plastics for your project.

Case Studies

Learn successful stories to inspire your project.

Knowledge Base

Whitepaper, design guide, materials, and finishing.

Surface Finishes

Different finishing options enhance part appearance and functionality.


Discover our library of educational videos.

CNC Machining eBook

If you want to produce high-quality machined parts with a sleek appearance, it’s essential to consider some critical factors related to CNC machining. 


Here, we’ve gathered some basic information and important considerations to help you achieve the desired results.

About RapidDirect

Our vision, mission, development history, and dedicated team.


Real feedback on experiences and opinions of our services.


Company news, platform updates, holiday announcement.

Our Platform

Get instant quotes with our smart online platform.

Our Capabilities

Rapid prototyping, and on-demand production.

Quality Assurance

Deliver quality parts that meet requirements and exceed expectations.

Contact Us

Online Quotation Platform v3.0

Attention! We have exciting news to share with you. We have just launched the latest online platform, version 3.0! 



The updated platform boasts a fresh and intuitive design, along with enhanced functionality that streamlines and accelerates the quoting process, like a new manufacturing process, streamlined quoting summary page, and improved checkout page. 

G and M Codes: Understanding the CNC Programming Languages

Table of Contents

Subscribe for expert design and manufacturing tips delivered to your inbox.

    CNC machining is one of the core processes in manufacturing that produce intricate and sophisticated products which have applications in various industries. However, these processes would be difficult to execute without the machines that drive them. Without the G and M codes, these machines can’t function.

    While you would find CNC codes being used together in most machine shops, they are quite different from each other. What are the differences? How do these codes control the functions of CNC machines? To find out the answers to these questions and more, read this article to the end.

    What is G Code and M Code?

    As mentioned earlier, G and M codes are required for CNC machining. However, what is the exact function of the two CNC letters program? How do they control CNC machines? This section will answer these questions and also highlight the differences between both codes.

    What is G Code?

    G code (also RS-274D) is the most popular CNC programming language. Most G code commands are in alphanumeric format and start with G which stands for geometry. G-code is responsible for the movements of CNC machines, telling the machine where to start, how to move, and when to stop when fabricating a part.

    However, G code programming can be quite complicated for machinists because different machines read G codes in different formats. Most machines’ difference is in the presence or absence of spaces between commands and in the number of zeros between the letter and number in the commands. For example, a machine might use G3 while another uses G03. Machinists must always be conversant with the type of machine they’re using. Otherwise, errors in the command can lead to serious problems in parts production.

    While G is the most common letter in G codes CNC programming, it is not the only letter used. Other letters also tend to represent different commands. Examples of some letters in the G code include:

    A: It directs the tool around the x-axis.

    R: It gives the radius of the arcs the machine makes.

    X, Y, Z: These three values indicate the tools’ position in three dimensions – X and Y represent the horizontal and vertical dimensions, respectively, while Z represents the depth.

    I and J: Both values designate the incremental center of any arc the machine makes.

    N: N gives the line number.

    The code also uses other letters which depend on the machine’s capabilities.


    What is M Code?

    Like the G code, the M code also begins with the letter ‘M.’ The M code is a set of auxiliary commands that control all the machine’s non-geometric actions. Machinists refer to the code as miscellaneous codes as it controls non-cutting actions such as stopping programs, flooding the machine with coolants, and shutting it off after the temperature drops.

    When setting up the CNC letters program using G and M codes, the M code should only have one command per block of information. This is because they mainly turn the machine on and off. Therefore, using them multiple times in one block could cause program problems.

    Just like G codes, M codes also vary between different machines. Some machines allow the omission of the zero between the letter and number, while some do not.


    Although machinists use G and M codes concurrently in any CNC machining process, they differ. Here are some examples of how both CNC codes differ:

    1. G code commands tend to differ in most CNC machines, while M codes are similar in most CNC machines.
    2. G codes direct the machine’s motion and function, while M codes direct the operations outside movements.
    3. The G code activates the CNC machine while the M code activates the machine’s programmable logic controller.

    How does CNC Programming Control CNC Machines?

    Before the advent of computers, machinists used cards or tapes to control machine movements. They punched holes on these cards in a specific order to create the codes. While this was also effective at the time, it was quite tedious. Also, these cards were prone to damage or getting lost in the machine shops. This led to several problems in production at the time.

    When machinists started using computers for numerically controlled machines, they still came across a few problems. This was because they had to input the codes manually. This would, of course, be very tedious when they were making quite sophisticated parts that required a lot of instructions.

    However, with much more advanced computers and software, machinists can simply instruct the software on what to do. The software will then generate the G codes and M codes that the machine understands. With CAD and CAM software, code generation for machine functions has become very easy.


    To start the process, the programmer needs high-level computer-aided software. The programmer then imports the machine model and the machining fixture into the software. He/She also selects the tools and the tooling paths of the spindle. The software then generates the G and M codes that the machine needs to function.


    This is the summary of the process through which CNC programming controls the function of CNC machines. Although the process above seems simplified, it could take weeks to generate the codes for a sophisticated part.

    Try RapidDirect Now!
    All information and uploads are secure and confidential.

    G Code and M Code Commands List

    This section will illustrate different examples of basic G and M codes and what they mean. Part of these codes means the same thing in G and M codes, although other units may vary. Examples of these codes include:

    G Code List – G Codes for CNC Lathe

    G00: Rapid Position Motion

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

    G02: CW Circulation Interpolation Motion – Modal

    G03: CCW Circular Interpolation Motion – Modal

    G04: Dwell (P) P=Seconds. Milliseconds

    G05: Fine Spindle Control Motion (Live Tooling) – Optional

    G09: Exact Stop

    G10: Programmable Offset Setting

    M Codes for CNC Lathes

    M00: Program Stop – Modal

    M01: Optional Program Stop – Modal

    M02: Program End – Modal

    M03: Spindle on Forward (S) – Modal

    M04: Spindle on Reverse (S) – Modal

    M05: Spindle Stop – Modal

    M08: Coolant On – Modal

    M09: Coolant Off – Modal

    M10: Chuck Clamp – Modal

    G Code List for CNC Milling

    G00: Rapid Motion

    G01: Linear Interpolation Motion

    G02: CW Interpolation Motion

    G03: CCW Interpolation Motion

    G04: Dwell

    G09: Exact Stop

    G10: Programmable Offset Setting

    G12: CW Circular Pock Milling (Yasnac)

    G13: CCW Circular Pock Milling (Yasnac)

    G17: XY Plane Selection

    M Codes for CNC Milling

    M00: Program Stop

    M01: Optional Program Stop

    M02: Program End (Setting 39)

    M03: Spindle On, Clockwise (S) (Setting 144)

    M04: Spindle On, Counterclockwise (S) (Setting 144)

    M05: Spindle Stop

    M06: Tool Change (T) (Setting 42, 87, 155)

    M08: Coolant On (Setting 32)

    M09: Coolant Off

    M10: 4th Axis Brake On


    Using CNC machines is one of the most important processes in CNC machining. However, these machines cannot function without G and M codes which instruct them on what to do. Understanding how to generate these codes is vital to the CNC machining process and successful parts production. Mastery of these codes gives you a head start in your CNC programming career.

    RapidDirect CNC Machining Services

    Need a company to handle your CNC machining project? Look no further because RapidDirect has all the technical expertise you’ll ever need. With over two decades of manufacturing experience, we have experienced staff in all areas of the manufacturing process.

    Try RapidDirect Now!
    All information and uploads are secure and confidential.

    RapidDirect understands that you want excellent CNC machining service and you don’t want to spend much to get it; therefore, we offer precisely that. With us, you will get the exceptional service you crave at a highly competitive price. Our service is affordable, and we don’t compromise quality at any stage.

    Once you assign your project to us, you do not have to worry about the coding or any CNC machining needs. We take full responsibility for the project and keep our communication lines open at all times. We also give experienced recommendations that can make the project a success.


    Do all CNC machines use G code commands?

    Yes! All CNC machines utilize G code CNC programming. This instructs the machine on when, where, and how to move.

    How many G codes are there?

    There are about a hundred G codes, Turning and milling machines each have separate codes, although both machines share some of these codes.


    Let's Start A New Project Today

    Latest Blog Posts

    Check out the latest industry trends and take inspiration from our updated blogs, giving you a fresh insight to help boost your business.

    cnc machining tolerances

    Everything You Need to Know About CNC Machining Tolerances

    CNC machines can achieve very high levels of accuracy. Some machines can achieve accuracies as high as +/-0.0025mm. However, running …

    rapid tooling vs conventional tooling

    Rapid Tooling Vs Conventional Tooling: The Key Differences

    Tooling is a vital step in the manufacturing process, involving the creation of tools necessary for product creation. This includes …

    medical 3d printing

    Medical 3D Printing and its Impact on the Healthcare Sector

    3D printing has taken over the healthcare sector like a storm in the past few years, from surgery, pharmacology, dentistry, or …