M-Code Commands: Meanings, Commands and Simulators
Contact Companies
Please fill out the following form to submit a Request for Quote to any of the following companies listed on
Get Your Company Listed on this Power Page
Introduction
This Article takes an In-depth look at the M-Code Plain Text Language
You will learn more about topics such as:
The types of commands programmed into a CNC machine
Fanuc M-Code List (Lathe)
Fanuc M-Code List (Mill)
What is CNC Machining?
The CNC Machining Process
Computer numerical control (CNC) is a fundamental part of modern manufacturing. The majority of machines operate using instructions and guidelines that have been downloaded using a CNC program controller. For a machine to interpret the commands from CNC, the commands have to be entered using G and M codes. CNC operators are required to know the appropriate codes and instructions as well as how to use them. Both types of coding are necessary for the system of a CNC device to perform correctly.
M-code is a part of the language that AutoCAD and CAM, computer aided manufacturing, use to input instructions into CNC machines. G-codes and M-codes work in unison for positioning a workpiece and guiding the machine‘s actions. M-codes, miscellaneous or machine codes, control the operations of the equipment telling it when to operate or cease operation. While the G-code can direct a machine to move in a line or arc, once the tool is positioned, it won‘t know to stop, change tools, add coolant, or complete any other actions, which are provided by M-codes. Instructions for a tool to turn on or off is part of the M-code language.
The use of M-codes varies depending on the machine. During programming, one M-code is required per code block giving the commands for a tool to turn on or off and activate other operations. Having more than one M-code in a code block can cause problems. The definition of M-code functions and their uses is spelled out by the machine‘s manufacturer.
Operators use M-codes to tell a machine to change tools, turn on the spindle, load coolant, or open and close a door. There are several M-codes that operators need to know for a machine to perform properly. Also, each machine has a different method for downloading the M-codes. One controller may require a zero between the M and the number while others don‘t need the zero. The particular method for a machine is clearly laid out in the instructions from the manufacturer.
Leading Manufacturers and Suppliers
The types of commands programmed into a CNC machine
M-codes are an important component of the operation of a CNC machine. While G-codes describe the positioning for an operation, M-codes provide data for a machine‘s actions. For the proper functioning of a CNC machine, G and M codes have to be entered. They work in tandem and together to instruct, guide, and program the responses of a CNC device. As with any computer, CNC machines have a controller for data input. Though most computer languages are built on C or C++, there are variations for each type of controller.
Fanuc manufactures robotic controllers that use M-codes for commands for CNC machines. Their controllers use the M zero number form of M-codes. Below are several of the Fanuc controller M-codes.
M00 Program stop
M01 Optional program stop
M02 End of program
M03 Spindle start forward CW
M04 Spindle start backward CCW
M05 Spindle stop
M08 Coolant on
M09 Coolant off
M29 Rigid tap mode
M99 End of program
M commands are part of an information group that determines how and when a machine should start or stop an action. Beginning with M00 they continue in an arithmetic progression to M99, which ends the program. How an M-code is used differs between vendors and producers. In many cases, not every M-code is programmed into the machine. Knowing the codes and how they make the machine function is critical. In some cases, when a code is not used or programmed, the definition of the code is left to the discretion of the user.
Examples of the programmable codes for a lathe and milling operation are listed below. Table 1 has codes for a lathe while table 2 has the M-codes for a milling operation. Both tables are examples of M-codes for Fanuc controllers.
Fanuc M-Code List (Lathe)
M code
Description
M00
Program stop
M01
Optional program stop
M02
End of program
M03
Spindle start forward CW
M04
Spindle start reverse CCW
M05
Spindle stop
M08
Coolant on
M09
Coolant off
M29
Rigid tap mode
M30
End of program reset
M40
Spindle gear at middle
M41
Low Gear Select
M42
High Gear Select
M68
Hydraulic chuck close
M69
Hydraulic chuck open
M78
Tailstock advancing
M79
Tailstock reversing
M94
Mirrorimage cancel
M95
Mirrorimage of X axis
M98
Subprogram call
M99
End of subprogram
Fanuc M-Code List (Mill)
M code
Description
M00
Program stop
M01
Optional program stop
M02
End of program
M03
Spindle start forward CW
M04
Spindle start reverse CCW
M05
Spindle stop
M06
Tool change
M07
Coolant ON � Mist coolant/Coolant thru spindle
M08
Coolant ON � Flood coolant
M09
Coolant OFF
M19
Spindle orientation
M28
Return to origin
M29
Rigid tap
M30
End of program (Reset)
M41
Low gear select
M42
High gear select
M94
Cancel mirrorimage
M95
Mirrorimage of X axis
M96
Mirrorimage of Y axis
M98
Subprogram call
M99
End of subprogram
There may be some confusion regarding the codes for CNC machines since some operators refer to all codes as being G-codes even though they input both G and M codes. To avoid misinformation and misunderstandings, it is important to know that every code block has to have one M-code to begin and end a function. The G-code tells the machine where and when to do a job. M-codes stop an operation, end a programmed task, or begin a movement after the tool has been positioned.
Most parts and products produced by CNC machines are programmed using CAD or CAM software that give directions for CNC machines using alphanumeric programming. Even though engineers are fluent in those two forms of software, it is still important for them to have an understanding of how G and M codes direct a CNC machine.
Leading Manufacturers and Suppliers
What is CNC Machining?
CNC machining is a sophisticated electromechanical process that precisely controls machinery along three to five axes, methodically cutting away surplus material to fabricate intricate parts and components. Initial designs for CNC machining are created using CAD software, which is subsequently translated into specialized CNC codes to direct the tools within the CNC machine.
This technology ensures top-notch finishes on turned pieces through a broad spectrum of applications, catering to both vertical and horizontal machining requirements.
The capabilities of CNC machines allow for the seamless and efficient production of components in a single operation. These machines are versatile, performing numerous applications such as bushings, collars, fasteners, fittings, inserts, machined components, washers, pins, nuts, spacers, spindles, standoffs, drive shafts, and splined shafts, among many others.
What are the Top M-Code Simulators?
M-code simulators are essential software tools designed to emulate and analyze the behavior of M-codes—machine instructions integral to CNC (Computer Numerical Control) systems. These advanced CNC simulation programs play a critical role in manufacturing by verifying, optimizing, and troubleshooting CNC machine tool programs before they are run on actual equipment. By providing a virtual environment for M-code program testing, these simulators help manufacturers prevent costly machining errors, minimize downtime, and streamline the CNC programming process. A range of leading software providers offer specialized M-code simulators tailored to specific industries, such as aerospace, automotive, and precision manufacturing. Below, discover a comprehensive review of the best M-code simulation software on the market and the innovative companies behind them.
Predator Virtual CNC by Predator Software
Predator Virtual CNC stands out as an extensive CNC machine simulation software with robust M-code simulation and G-code simulation capabilities. The platform delivers a highly realistic 3D simulation environment, enabling users to preview, validate, and optimize CNC programs—including complex toolpaths and subprograms—prior to running them on physical CNC machines. Its simulation features help identify programming errors, tool collisions, and machining inefficiencies, which is invaluable for CNC programmers, manufacturing engineers, and machinists seeking high accuracy and process reliability.
Founded in 1994, Predator Software is an established leader in manufacturing software solutions, specializing in CNC programming, shop floor automation, digital twin technology, machine monitoring, and integration for Industry 4.0 environments. With its broad support for various CNC machine models and controllers, Predator Virtual CNC supports the digital transformation initiatives of modern manufacturing facilities.
Vericut by CGTech
Vericut by CGTech is one of the most prominent M-code simulators, known for its advanced CNC program verification, optimization, and virtual machining capabilities. Vericut provides comprehensive simulation of the entire machining process, including tool movement, material removal visualization, and detection of programming errors, collisions, over-travel, and inefficiencies within the code. The software supports both G-code and M-code simulation for multi-axis and multi-channel CNC machines, making it a top choice for complex part manufacturing and high-precision industries.
CGTech, founded in 1988, is an international leader in CNC simulation, NC program verification, and numerical control optimization. Serving industries such as aerospace, automotive, medical device manufacturing, and energy, CGTech’s Vericut improves overall CNC machine safety, productivity, and efficiency by delivering highly accurate simulation results and CNC code validation.
Cimco DNC-Max by CIMCO A/S
Cimco DNC-Max is a comprehensive software suite offering best-in-class DNC (Direct Numerical Control) and M-code simulation features. In addition to facilitating reliable CNC program transfer, it provides advanced simulation capabilities to validate both G-code and M-code, helping users identify issues such as program logic errors, syntax mistakes, and machine compatibility concerns. By automating CNC file transmission and program simulation, Cimco DNC-Max minimizes setup time, supports data-driven manufacturing, and enhances shop floor connectivity for manufacturers of all sizes.
CIMCO A/S, established in 1991, is a trusted developer of DNC software, CNC communication solutions, machine data collection, and production analytics tools. Its solutions are widely adopted for smooth and reliable CNC machine integration in smart manufacturing and Industry 4.0 applications.
Mastercam Simulator by CNC Software, Inc.
Mastercam is a widely recognized CAD/CAM software for sophisticated CNC programming, featuring a powerful integrated M-code and toolpath simulation environment. The Mastercam Simulator empowers users to visualize, back-plot, and analyze CNC programs with support for complex multi-axis toolpaths and post-processing validation. By simulating and optimizing programs before they reach the machine, Mastercam enhances machining accuracy, tool life, and production workflow efficiency.
Developed by CNC Software, Inc. (established in 1983), Mastercam is one of the most frequently used CAM software solutions in the world. The simulator improves user confidence by preventing errors and reducing time spent on machine setup and troubleshooting. Mastercam’s active user community and extensive post-processor library further enhance its position as a go-to platform for advanced CNC programming and M-code simulation.
Fusion 360 by Autodesk
Fusion 360, from Autodesk, is an all-in-one product development platform that fuses advanced 3D CAD, CAM, and CAE into a unified, cloud-based environment. Its robust CNC simulation tools include interactive M-code and G-code verification, toolpath optimization, and machine tool collision detection. With real-time visualization of machining operations, Fusion 360 supports CNC programmers and manufacturers by identifying errors, ensuring code compatibility, and enabling process optimization for a wide range of machine types and controllers.
Autodesk, established in 1982, is renowned for its innovative software solutions spanning multiple design and engineering sectors. Fusion 360 is highly regarded for its user-friendly interface, cloud collaboration features, and integrated simulation workflows, making it ideal for prototyping, small-batch manufacturing, and educational purposes.
Choosing the right M-code simulator depends on your manufacturing needs, CNC machine types, industry requirements, and budget. Modern M-code simulators not only boost productivity and machining accuracy but also address evolving challenges like digital twin integration, NC code optimization, and compliance with digital manufacturing standards. Top-rated simulation software such as Predator Virtual CNC, Vericut, Cimco DNC-Max, Mastercam Simulator, and Fusion 360 empower users to achieve reliable, cost-effective CNC program verification and seamless shop floor implementation.
For manufacturing professionals seeking to streamline the CNC programming process, reduce scrap, and improve time to market, investing in advanced M-code simulation technology is essential. When researching and selecting an M-code simulator, consider critical features such as compatibility with your CNC controller, user interface, support for complex machining operations, and the ability to simulate real-world scenarios with high accuracy. Requesting software demos, reading customer reviews, and consulting with experts can help your team select the best M-code simulator for your production needs.
What is the CNC machining process?
CNC, or Computer Numerical Control, machining is a systematic process aimed at efficiently producing parts. This technique involves computer-controlled machines that execute tasks based on pre-programmed instructions, starting from a 2D or 3D design rendered on a computer.
After the design file is input and coded, the CNC machine carries out each operation in line with the specified design parameters.
The CNC Machining Process
The key distinction between CNC machining and other manufacturing methods is that CNC machining is a subtractive process. It involves removing layers of material to achieve the desired shape, as opposed to additive or formative manufacturing techniques.
Computer Programming
The success of CNC manufacturing largely depends on the initial programming. The software must be precisely coded with accurate instructions, ensuring the machine operates within its specified limitations. The effectiveness of CNC processes is directly influenced by the quality of the instructions provided. Careful attention is given during the programming phase to minimize errors and prevent production delays.
Computer Aided Design (CAD) and Computer Aided Manufacturing (CAM)
CAD-CAM refers to the software used for both designing and machining parts with CNC machines. CAD (Computer-Aided Design) software is utilized to create, draw, and model parts using geometric shapes and constructs. CAM (Computer-Aided Manufacturing) software then converts the CAD data into machine language, known as G-Code.
Before converting the CAD model into machine instructions, CAM software determines the toolpaths required to remove excess material from the workpiece. Together, CAD and CAM provide the CNC machine with precise instructions needed for accurate and efficient cutting operations.
CNC Machine Setup
Before uploading the CAD-CAM program to the CNC machine, it is essential to prepare the correct cutting tools. One approach involves manually selecting tools from a tool cart and installing them into the machine.
Alternatively, an Automatic Tool Changer (ATC) can streamline this process. The ATC system holds tools on a rotating drum or chain and automatically swaps them out as needed. This method is designed to enhance efficiency and minimize downtime.
Another crucial setup step is defining the gage point, which determines the distance from the tool tip to a reference point. Proper calibration of this measurement ensures that the tool cuts at the desired depth. Additionally, testing the coolant or lubricant system is vital. Coolant can be applied via air, mist, flood, or high-pressure methods. Accurate pressure settings are necessary to prevent tool damage and protect the machine.
Common setup mistakes include neglecting to check the coolant quality, which may result in unpleasant odors, inadequate levels, low concentration, or insufficient filtration.
Work Holding
Work holding devices are used to secure, support, and position the workpiece during machining operations. Also known as CNC fixtures, these tools ensure precision, consistency, and smooth operation by stabilizing the workpiece. Unlike jigs, which guide tools, work holding devices primarily focus on securing and supporting the workpiece itself.
Similar to CNC tools, work holding fixtures come in various types, each suited for specific operations such as turning, milling, drilling, boring, and grinding.
Loading the G-Codes
G-codes are widely recognized as the standard language for CNC machining. While there are universal G-codes applicable to all CNC machines, manufacturers often customize these codes to fit their specific equipment. Each G-code corresponds to a particular movement or function of the cutting tools in a CNC machine.
G-codes can be generated by various software programs from a CAD design, but they can also be manually written or created through conversational programming, which does not rely on CAD designs. These codes can be transferred to a CNC machine via a USB drive, directly from a CAM computer, or programmed directly into the machine itself.
Program Proofing
Program proofing is the last step before executing the actual cuts. It aims to verify the accuracy of the program and ensure the CNC machine setup is correct, preventing potential issues with the G-code.
This step is crucial for detecting any errors in the G-code. Proofing can be done by running the machine through the cutting process without engaging the workpiece, known as "cutting air," which, while effective, is time-consuming and occupies the machine. Alternatively, a G-code simulator can be used, providing a virtual simulation of the CNC process to identify any problems.
Machining the Part
Once all preparations are finalized, the next step is to insert the workpiece and begin the cutting process. The initial workpiece should be closely monitored as it undergoes machining. This prototype serves as a benchmark for all subsequent parts and will provide valuable insights into the effectiveness of the programming and setup.
Execution
After completing the setup and testing phases, the CNC machine is ready for production. CNC machining enables manufacturers to produce parts quickly, efficiently, and safely, with each part being an exact replica of the original design.
Fanuc G-Codes and their description for a Mill and Lathe
The importance of subprograms and macros in CNC programming
Related Posts
5 Axis CNC Machining
The normal functioning of CNC machines is done along the three Z, X, and Y axes. The five axes machines have two more axes accessible, which are namely A and B. The addition of the two extra axes makes it easy to cut complex and intricate parts...
CNC Machining
CNC machining is an electromechanical process that manipulates tools around three to five axes, with high precision and accuracy, cutting away excess material to produce parts and components. The initial designs to be machined by CNC machining are created in CAD...
CNC Milling
The CNC process was developed in the 1950‘s and took a leap forward in the 1980‘s with the addition of computerization. Unlike other production processes, CNC begins with a rendering by a computer, which creates a two or three dimensional representation of the part to be produced...
G-Code
G-code is the name of a plain text language that is used to guide and direct CNC machines. For most modern CNC machines, it isn‘t necessary to know the meaning of G-codes since CAD and CAM software is translated into G or M codes to instruct a CNC machine on how to complete a process...
Types of Machining
Machining is a manufacturing process used to produce products, parts, and designs by removing layers from a workpiece. There are several types of machining that include the use of a power driven set of machining tools to chip, cut, and grind to alter a workpiece to meet specific requirements...
What is CNC?
The CNC process, computer numerical control, is a method of manufacturing where programmed software directs the operation of factory tools and machinery. It is designed to manage a wide range of complex machines from grinders and lathes to mills and routers...
Contract Manufacturing
Contract manufacturing is a business model in which a company hires a contract manufacturer to produce its products or components of its products. It is a strategic action widely adopted by companies to save extensive resources and...