CNC stands for computer numerical control, a modern tool that is misrepresented in the manufacturing world. Sometimes, you might think of it as a traditional tool, but it advances beyond that, popularly referred to as CNC machining. CNC machining is regarded as one of the significant manufacturing processes that help to create complex geometrically shaped products across industries that need its application for final production.

The G and M codes are the best guide to accomplishing excellent precision and efficiency in CNC machining. These codes are significant programming languages used to guide CNC tools/machines.

These codes offer distinct features to CNC operation, and in this article, you will learn what an M code is, how it is meant to function, and commonly used M-codes and their purpose. You will also learn the M-code types and the differences between Manual machining vs. M-codes.

Basics of M-Codes

M-code constitutes an integral component of the programming language employed by AutoCAD and CAM (computer-aided manufacturing) to provide directives to CNC machines. In collaboration with G-codes, M-codes facilitate the precise positioning of a workpiece and orchestrate the machine’s actions. M-codes control equipment operations as miscellaneous or machine codes, dictating when to initiate or cease specific actions. Unlike G-codes, which primarily govern linear or arcuate machine movements, M-codes are essential for instructing the machine to halt, change tools, introduce coolant, or execute other designated actions once the tool is appropriately positioned. Activating or deactivating a tool is a specific aspect addressed within the M-code language.

The utilization of M-codes varies according to the specific CNC machine in use. During the programming phase, each code block necessitates one M-code to convey instructions related to tool activation, deactivation, and other operations. Including multiple M-codes in a single code block may lead to operational issues. The machine’s manufacturer stipulates the delineation of M-code functions and their intended purposes.

Operators rely on M-codes to command machines to undergo tool changes, initiate spindle rotation, introduce coolant, or manipulate doors. Familiarity with various M-codes is imperative for optimal machine performance. Furthermore, each machine employs a distinct protocol for inputting M-codes, with variations such as the inclusion or omission of a zero between the M and the numerical code. The specific method applicable to a particular machine is explicitly outlined in the manufacturer’s instructions.

How Do M-codes differ from G-codes?

Close up of a machinist inputting M code sequences into a computer
Close up of a machinist inputting M code sequences into a computer

G codes specifically pertain to the complex geometric aspects of processing a part, detailing how the tool moves relative to the workpiece. On the other hand, M codes focus on individual functions performed by the machine, delineating what the machine executes in the machining process.

G-codes Control the CNC machine’s movement and operation. Meanwhile, M-codes control non-moving processes, including pausing programs, switching out tools, turning on or off the spindle, and turning on coolant systems.

In essence, while G codes govern the movement of the tool concerning the workpiece, M codes govern the machine’s specific actions throughout the machining process. Additionally, the RS-274 programming language incorporates a comprehensive set of auxiliary functions to refine further and control various parameters in the machining operation.

Detailed Function of M-codes

M-codes have several functions/purposes, as they have played a significant role in building up the operational ability and control of CNC machine tools. Here are the primary purposes of M-codes in CNC machining:

Machine Control

M-codes are used as commands to regulate several surfaces of the CNC machine tool. These surfaces include speed adjustment, spindle activation, and the management of the cooling system.

Tool Changes

M-codes help to initiate tool changes, which will prompt the CNC machine to pause for a while so that the operator can replace the cutting tool manually or automatically.

Program Flow Control

M-codes are important because codes such as M00 and M01 help contribute to program flow control by introducing stops. This allows the operator to disrupt the CNC machining process so that you can inspect and carry out other necessary actions.

Coolant Control

M-codes are utilized to control the coolant system. M08 activates the coolant to lubricate and cool the cutting tool, while M09 deactivates it.

Spindle Control

M-codes govern the spindle’s rotation. M03 initiates clockwise rotation, M04 initiates counter-clockwise rotation, and M05 halts the spindle.

Subprogram and Subroutine Calls

M-codes facilitate the incorporation of subprograms or subroutines within the primary CNC program. This modular approach enhances organization and programming efficiency.

Program End and Rewind

M-codes like M30 signify the conclusion of the CNC program, and they may include commands to rewind the program or return the machine to a specific position.

Gear Range Selection

M-codes may be employed in machines with multiple speed options to select different gear ranges, adjusting the machine’s speed capabilities.

Optional Stops

M-codes, exemplified by M01, provide optional stops within the program. This feature empowers the operator to decide whether to halt the program at a specific point for inspection or other considerations.

Error Handling

M-codes serve as a mechanism for implementing error-handling routines or actions triggered by specific conditions, thereby enhancing the resilience of CNC programs.

Frequently Used M Codes

While CNC machines commonly utilize M-codes alongside G-codes, the absence of universal standardization across models necessitates caution among CNC programmers regarding machine-specific codes. Nevertheless, certain M-codes maintain consistent meanings across diverse machines.

M00 – Program Stop

Purpose: Temporarily halts the CNC program, requiring operator intervention to resume.

Usage: Often employed for situations demanding a temporary pause in the program.

M02 – Program End

Purpose: Marks the end of the CNC program, prompting the control to stop. Operator intervention may be necessary to reset or restart the machine.

Usage: Executed to conclude the CNC program after all necessary operations.

M03 – Spindle On, Clockwise

Purpose: Initiates spindle rotation in the clockwise direction. They are typically accompanied by a speed command (S) to set the spindle speed.

Usage: Commonly used when the machining process requires the spindle to rotate clockwise.

M04 – Spindle On, Counterclockwise

Purpose: Similar to M03, M04 activates the spindle but induces rotation in the counterclockwise direction.

Usage: Applied when specific machining operations demand counterclockwise spindle rotation.

M05 – Spindle Stop

Purpose: Ceases spindle rotation. They are often utilized during tool changes or operations requiring the spindle to remain stationary.

Usage: Implemented to bring the spindle to a stop when its rotation is no longer required.

Types of M-codes and Universal M-codes Applicable Across Platforms

M-Codes for Controlling Programs

M00 – Termination of Program:

  • Function: Allows operator interaction by momentarily stopping the CNC program.
  • Application: Helpful for planned pauses, such as changing out manual tools or adding new features in the middle of a task.

M01 – Selective Pause:

  • Function: Adds an optional pause that lets the user halt the program at specified intervals.
  • Application: Usually utilized for preliminary measurements, inspections, and tool checks.

Spindle Control M-Codes

M03 – Spindle On, Clockwise:

  • Function: Initiates spindle rotation in the clockwise direction, often followed by a speed command (S) to set spindle speed.
  • Application: Commonly used when a clockwise rotation is required for the cutting tool.

M04 – Spindle On, Counterclockwise:

  • Function: Activates the spindle in the counterclockwise direction.
  • Application: Applied in machining operations that specifically demand counterclockwise spindle rotation.

M05 – Spindle Stop:

  • Function: Halts the spindle rotation.
  • Application: Used during tool changes or when a stationary spindle is necessary for certain operations.

M-Codes for Tool Change

M06 – Tool Change:

  • Function: Triggers a tool change, allowing the operator to replace the cutting tool manually or automatically.
  • Application: Essential for processes involving different tools for various machining operations.

M-Codes for Coolant Control

M08 – Coolant On:

  • Function: Activates the coolant system, ensuring lubrication and cooling of the cutting tool.
  • Application: Employed to enhance tool life and improve machining performance.

M09 – Coolant Off:

  • Function: Deactivates the coolant system.
  • Application: Used when coolant is unnecessary or to avoid coolant splashing during specific machining phases.

M-Codes for Feed Rate and Speed Control:

M50 – Feedrate Override On:

  • Function: Enables feed rate override, allowing real-time adjustment of cutting speed.
  • Application: Useful for fine-tuning cutting parameters during machining.

M51 – Feedrate Override Off:

  • Function: Disables feed rate override.
  • Application: Restores default feed rate settings.

M52 – Spindle Speed Override On:

  • Function: Enables spindle speed override.
  • Application: Allows adjustments to spindle speed during operation.

M53 – Spindle Speed Override Off:

  • Function: Disables spindle speed override.
  • Application: Restores default spindle speed settings.

M-Codes for Program End and Rewind

M30 – Program End:

  • Function: Marks the end of the CNC program and may include commands to rewind the program or return the machine to a specific position.
  • Application: Essential for concluding the machining process and preparing for the next cycle.

M-Codes for Axis and Work Offset

M54 to M59 – Select Work Coordinate System:

  • Function: Specifies different work coordinate systems for machining operations.
  • Application: Enables the machine to reference specific points for precise machining.

M65 through M98: Personalized User Features

  • Function: Intended for unique, user-defined functions that encourage structured, modular programming.
  • Application: Promotes the utilization of reusable code parts by improving program flexibility and structure.

M-Codes for Selecting Gear Range

M61 to M68 – Selecting the Gear Range:

  • Function: Selecting different gear ranges allows the machine to have multiple speed options to change its speed capabilities.
  • Application: This makes adjusting to different material properties and machining requirements possible.

A List of M-Codes

M08CoolantCoolant flood or on
M42Auxiliary FunctionsHigh Gear Select
M19Spindle ControlChange spindle orientations
M00Program ControlProgram Stop
M02Program ControlProgram End
M03Spindle ControlSpindle On, Clockwise
M04Spindle ControlSpindle On, Counterclockwise
M05Spindle ControlSpindle Stop

Advanced Application of M-codes


M-codes are essential for guiding CNC machines through complex machining jobs in the fast-paced aerospace field. These codes direct the precise fabrication of structural and difficult sections and other aircraft components. Consider them the conductors coordinating spindle adjustments, coolant activations, and tool changes. The dependability of M-codes largely shapes the aerospace industry’s high-tolerance components.


M-codes are essential to the core of the car manufacturing process since they guarantee accuracy and productivity. Imagine them as the maestros in charge of CNC machines, coordinating everything from tool changes to transformations. Incorporating M-codes improves automation and ensures reliable and accurate manufacturing of essential automobile components, from transmission to engine parts.


M-Codes are the CNC machining equivalent of the architects of the defense industry, directing the production of durable parts for use in military applications. They operate machines through complex procedures such as drilling, turning, and milling to produce durable and precise parts. M-code use becomes essential to ensure the consistency and dependability needed for military-grade components.


When creating complex circuitry and components, M-codes become invaluable resources. Imagine CNC machines controlled by M-Codes that painstakingly mill, drill, and route printed circuit boards (PCBs) and electronic components. Technology and electronic device improvements are accelerated by manufacturers’ ability to create intricate, tiny electronic components with precise tolerances because of the flexibility provided by M-Codes.


Entering the field of medicine, M-Codes take on the role of precision architects, directing CNC machines in manufacturing vital parts for medical apparatus. M-codes coordinate the production of prosthetics, implants, and other medical devices within this domain. Their contribution goes beyond simple supervision; they guarantee the production of specialized, high-precision medical parts that satisfy the demanding requirements of the medical sector.


M-codes control CNC machines that produce parts essential to producing and distributing electricity. Imagine M-Codes as the producers and directors behind the scenes that make it possible to precisely build generator parts, turbine parts, and other essential components required for dependable and efficient energy generation. M-Codes’ adaptability makes machine various materials necessary for energy-related applications possible.

M-Codes vs. Manual Machining

Manual machining is centered around craftsmanship and skill. Expert machinists use their knowledge to construct precise components using instruments like drills and lathes. Experience takes the lead in this practical art form.

  • Time-Intensive: Precision machining requires meticulous dancing rather than a sprint. Every movement-a cut, turn, or drill-requires conscious thought and precision. It is an accurate but labor-intensive operation, with the machinist’s physical capabilities setting the speed.
  • Artisanal Touch: Manual machining has a distinct quality that is difficult to duplicate. Machinists are proud of their work and give each piece a unique touch. Experience is the critical component that makes desired results a reality, not simply a bonus.
  • Limited Precision: Manual machining precision is an art form in and of itself. While expert machinists strive for flawlessness, human limitations can cause minute differences in tolerances and measurements. It’s a task that infuses a little artistry.
Diverse examples of M code applications showcasing its versatility in controlling various functions
Diverse examples of M code applications showcasing its versatility in controlling various functions


  • Automation and Precision: Welcome to the M-Code era, when automation and precision come together. M-codes enable CNC machines to perform jobs with astonishing accuracy, making them precision artists. In industries where strict tolerances are unavoidable, this changes everything.
  • Speed and Efficiency: M-Code-driven CNC machines operate at a higher speed than the methodical pace of hand milling. They function at faster speeds, emphasizing efficiency. Because of the automation component, production is faster and more dynamic by reducing cycle times.
  • M-codes introduce a new dimension of uniformity and reproducibility to the manufacturing industry. A program is a recipe that can be accurately repeated for large-scale production once it is set. When industries need similar components, this consistency turns into a powerhouse.
  • Handling Complexity: M-Codes let complexity in. M-Codes enable CNC machines to handle complex geometries and designs easily. It’s a dance of technology that increases the potential for producing sophisticated and sophisticated parts.
  • Programming Ability Needed: M-Code magic isn’t created by accident. It calls for knowledge of programming. Experts must master writing accurate CNC programs, maximizing M-Codes’ potential, and converting them from lines of code into manufacturing wonders.


CNC machines are essential in CNC machining, but the real magic happens in the instructions these machines receive, known as M-codes. These codes become the machines’ guides, effectively controlling their every action. Not only is it vital to understand how to create and apply these codes, but it is also the foundation of the CNC machining process and is essential to the effective manufacturing of parts.

Learning these codes gives anyone starting in CNC programming a significant boost above simply gaining a new ability. It’s the kick-start you need to unlock the full potential of CNC machines and carve out a successful career in CNC programming. Visit Zintilon to discover the world of CNC machining solutions. We pride ourselves on combining precision and understanding in our approach. Our system’s foundational elements of efficiency and accessibility ensure a flawless experience customized to you.


  1. What is M-Code?

A set of instructions used in CNC (Computer Numerical Control) machining is called M-code or machine code. It is essential for managing a CNC machine’s auxiliary operations, including spindle speed adjustments, coolant activation, and tool changes.

  1. How Do M-Codes Affect CNC Machining?

M-codes serve as command instructions that direct the CNC machine to carry out particular tasks. They contribute to the overall automation and accuracy of the machining process by managing auxiliary operations.

  1. What Is the Total Number of M-Code Types?

M-codes are divided into categories, each representing a certain action or function. M00 (Program Stop), M03 (Spindle On, Clockwise), M08 (Coolant On), and M30 (Program End) are examples of common types.

  1. What Are the Various M-Code Types, and How Are They Used?

M-codes come in different varieties, each with a distinct function. As an illustration, M02 and M30 denote the conclusion of a program, M03 and M04 regulate spindle rotation, while M08 and M09 oversee coolant operations. It is necessary to comprehend these kinds to program CNC machines precisely.

Read More

Share Posts
Subscribe To Newsletter

    All uploads are secure and confidential

    Let's Start a New Project Today