M06 is the core tool change command that exists in CNC programming. It is used to allow the automatic tool changer, also known as ATC, to perform tool change. When the program executes the M06 command, the machine tool will pause the current processing, return the current tool on the spindle to the tool magazine, and take out the specified tool from the tool magazine and install it on the spindle. This article is based on the ISO 6983 standard and the general specifications of mainstream CNC systems. It provides a complete operating guide for the M06 code, as well as common error analysis and safety practices to ensure that programmers and operators can use this instruction accurately and safely.
01Standard format and execution logic of M06 code
The M06 command is used in conjunction with the T code (tool selection command), and its standard format is:
T__ M06
or
M06 T__
In the actual system, both sequences can be executed. However, it is recommended to perform the T operation first and then the M06 operation to ensure that the tool magazine is positioned at the target tool position in advance, thereby reducing the time required for tool change. Its execution logic is divided into four stages: first, the spindle realizes directional stop and is positioned at the tool change point; second, the spindle releases the tool, and the manipulator or tool magazine removes the current tool; third, the tool magazine rotates to the target tool position, and the manipulator grabs the new tool and installs it on the spindle; fourth, the spindle clamps the tool and restores the processing state. The entire process is generally completed within 2 to 8 seconds (depending on the machine model).
Core notes :
M06 cannot be used alone, it must be used with a valid T code (T1 to T999, which is determined based on the tool magazine capacity).
Before changing the tool, be sure to ensure that the Z-axis returns to the tool change reference point (usually referred to as G28 Z0 or G91 G28 Z0), otherwise, a collision is very likely to occur.
Some systems stipulate that before changing tools, M05, which means the spindle stops, and M09, which means the coolant is turned off, must be executed first. However, modern CNC M06 has integrated these safety logics.
02Typical application scenarios and programming examples
Scenario 1: Tool change in vertical machining center (most common situation)
When processing a certain part, it is necessary to use a Φ10 end mill, also known as T1, and a Φ6 drill bit, also known as T2. The correct programming section is as follows:

N10 T01 ;预选T1刀具,刀库转到一号刀位等待
N20 M06 ;执行换刀,T1装入主轴
N30 S3000 M03 ;主轴正转3000rpm
N40 G54 G90 X0 Y0
N50 G43 H01 Z100. ;刀具长度补偿
...加工T1程序...
N100 M05 ;主轴停止
N110 T02 ;预选T2
N120 M06 ;换为T2
N130 S5000 M03
...继续加工...
Common error example: An operator executes M06 without returning to the tool change point, causing the tool to collide with the object and damaging the spindle. Correct action: Before executing M06, be sure to use G91 G28 Z0 or G00 G53 Z0 (absolute machine coordinate zero point) to raise the Z axis to a safe position.
Scenario 2: Manual tool change without automatic tool changer
There are also some equipment used for small milling machines or turning centers that do not have automatic tool changing devices. In this case, the "06 function status of the M code is judged to be invalid, or is defined as "program pause, prompting manual tool change." For this type of machine tool, the code that needs to be called and cooperate with the operator to perform manual tool change actions should be M00 (program pause), not M06.
03Comparison and selection basis between M06 and similar instructions
| instruction | Function | Applicable scenarios | Requirements for tool magazine |
|---|---|---|---|
| M06 | Automatic tool change, direct replacement of spindle | Machining centers and CNC milling machines with ATC | must |
| T code | Only tool selection, no exchange is performed | Combined with M06 or used for tool magazine preselection | must |
| M06 and T sequence | First T, then M06: Pre-position the tool magazine and then change the tool, which is highly efficient. | Most CNC systems | All required |
The key conclusion is that in mainstream systems such as FANUC, Mitsubishi, and Siemens, the T command only completes tool magazine rotation and tool selection, while M06 is the command that actually performs tool exchange. If you only write T05 without writing M06, the tool on the spindle will not change.
04Safe operating specifications and troubleshooting
More than 90% of tool changing accidents can be avoided by following the following rules:
1. Before performing a forced tool change, the position must be checked: a suitable subroutine needs to be written here. Before each tool change, such an instruction will be executed automatically, that is, G91 G28 Z0, and a tool interference check link must be added to the program, that is, a macro program is used to determine whether the current Z value is in a safe state.
2. There is such a tool life management method that uses macro variables to record the processing time of each tool. Once the processing time exceeds the preset threshold, the program will automatically call M06 to replace it with a spare tool.
3. Manual intervention is prohibited when M06 is executed. No part of the body can enter the work area when changing tools. The panel cannot be operated before the ATC action cycle is completed.
Answers to frequently asked questions in Q/A format:
Q: The spindle does not rotate when M06 is executed. Is this normal?

A: In normal condition. M06 is only responsible for tool change. If the spindle rotates, S code and M03 or M04 need to be written separately.
Q: The tool length compensation does not take effect after changing the tool. What's going on?
You have to call it again and perform this operation for G43 H__ because M06 will not inherit the original compensation value by itself.
Q: The machine tool alarms "Tool arm stuck" after M06 in the program. How to solve it?
First, make sure that the tool holder is not broken and the tool is not overweight. Then, manually reset the ATC and perform the "tool recovery" procedure.
Q: Can I not write M05 and M09 before M06?
For A, it is feasible. The modern CNC M06 already covers the spindle stop and cooling shutdown.
Q: Will calling M06 twice in succession for the same tool damage the tool magazine?
A. No damage will occur, but it will cause a waste of cycle time. The program should be optimized to avoid repeated replacement of tools with the same number.
05Programming optimization suggestions and action plans
To maximize processing efficiency and prevent collision accidents due to improper use of M06, in this case, it is recommended to take the following three actions:
Action 1: Make a check immediately. For the tool change sections in all existing CNC programs, make sure that every T command is followed by M06, and the Z-axis zero return operation has been performed before the tool change. Just think of this situation, such as G28 Z0. You can use text search tools to find exception codes that are "T[0-9]+" but do not contain "M06".
Action 2: Create a standard program header template in the machining center, and write the stable and safe tool change logic here continuously and firmly. Template example:
O0001
G17 G40 G49 G80 G90
T01 M06 ;首次换刀
G91 G28 Z0 ;换刀后立即回零(实际上已安全)
G90
...加工...
M05
T02 M06 ;第二次换刀
Action 3: Provide the operator with an M06 operation quick reference card. This card contains prohibitions, that is, you are not allowed to press reset when changing tools, you are not allowed to manually intervene in ATC, etc. It also includes emergency recovery procedures.
In actual production, effective tool management relies on comprehensive and complete control of M06, tool number and length compensation. It is recommended to use macro programs to automatically record the number of tool changes for each tool. When the set life is reached, such as 200 times, the program will automatically jump to the backup tool to reduce manual intervention.
06M06 variants in different CNC systems
In most systems, that is, in the case of Fanuc, Mitsubishi, Siemens 828D/840D, and Heidenhain, M06 is uniformly used to indicate tool change. However, there are a few differences, such as this.
Fanuc pointed out that M06 can be on the same line as the T code or on different lines. However, when it is on the same line, it must be written in the order "T01 M06".
Siemens supports the concise writing called "T1 M6", where M6 is equivalent to M06, and also allows the cutting edge of the new tool to be automatically carried during tool change operations, which is the D number compensation.
Huazhong CNC : fully compatible with ISO standards and consistent with FANUC usage.
For brother machines, the tool change command must be additionally appended. There must be at least one space between "M06" and "T", otherwise, an error will occur in the analysis.
Inspection method: When the new machine tool is used for the first time, write the test paragraph "T01 M06; G04 X2;" and perform dry operation. Pay attention to the movement of the tool magazine and whether the spindle grabs the tool smoothly. If an alarm occurs, check the machine tool manufacturer's "M code table" to check whether M06 is occupied or needs to be replaced with another code (for example, some old machine tools use M06 as a waiting sign for "tool change completed").
07Repeat core ideas and final conclusions
The M06 CN command, which has a unique and standard function, is used to realize automatic tool exchange. Any program that does not follow the sequence of "first return to the tool change point, then execute M06, and then call length compensation" will have the risk of machine collision. Users should directly apply the security templates, checklists and conclusions to common questions provided in this article, especially the first sentence of the Q/A section, in daily programming and operations.
The last point of the action suggestion is that before the next shift starts, select a machining center, use the standard tool change section in this article to replace the five tool change codes at the beginning of the original program, and then conduct a dry run verification. At the same time, print out the "Frequently Asked Questions" section of this article and post it next to the machine tool control panel as a reference for the operator at any time. Only by implementing every rule into executable actions can we truly prevent production shutdown accidents and equipment damage caused by incorrect use of M06.
Through systematic tool management and precise cooperation with the M06 code, tool changing time can be shortened by more than 30%, and abnormal tool loss can be reduced by 50%. It is recommended to use the "tool change counting macro" in each shift to record the number of times M06 is executed as a data basis for predictive maintenance. By following the guidelines laid out in this article, your CNC programs will have industrial-grade reliability.

