M06 is the code that changes the tool. It is short, it appears in almost every program with more than one operation, and the safe way to use it is a small routine, not a single line. Get that routine right and tool changes are uneventful.

M06 and the T word work together

Two words do the job. The T word selects the tool, and M06 changes to it. You usually see them on the same line:

T6 M06   (select tool 6, then change to it)

On most machines with an automatic tool changer, T does more than name the tool: it pre-stages it by rotating the carousel to that pocket. That lets the changer stage the next tool while the current one is still cutting, then M06 performs the swap when you reach it. The behavior is defined in the LinuxCNC M-code reference, and M06 is a classic example of an M-code being a machine action rather than a motion command, which is the heart of the G-code vs M-code distinction.

The safe tool-change routine

A bare M06 is not enough on most setups. You want the spindle stopped and the tool clear of the part before anything swaps. The standard routine looks like this:

BlockWhat it does
M05Stop the spindle
G91 G28 Z0Send Z to home, clear of the part
G90Reset to absolute
T6 M06Select and change to tool 6
G54Confirm the work offset
S2000 M03Start the new tool spinning
G43 Z25. H06Apply tool 6 length, rapid to safe Z

Stopping the spindle uses the M05 spindle stop, and clearing the tool uses a G28 return to home. Some controls automate parts of this and retract to a fixed change position on their own; others need every line. Always check your machine’s manual, because tool-change behavior varies more between controls than almost any other code, a point the Wikipedia G-code overview makes about machine-specific differences.

Why G43 always follows

The single rule beginners forget: after a change, re-apply the tool length offset. The new tool is a different length, so its Z depths are wrong until the control applies the right value. That is the job of G43 tool length offset with the matching H register, normally on the first Z move after the change. Matching the numbers (tool 6 uses H06) is the standard habit that prevents mix-ups.

Automatic vs manual tool change

What M06 actually does depends on the machine:

Machine typeWhat M06 does
Automatic tool changer (ATC)Swaps the spindle tool for the staged tool
Manual mill, no changerPauses and prompts the operator to change the tool by hand

Either way, M06 is a one-shot action: it runs once and is done, unlike the modal G-codes that stay active. It is one of the most common M-codes you will read, so it belongs on every list of the common M-codes for CNC beginners and on any good code cheat sheet.

Bottom line

M06 performs the tool change and the T word selects the tool, often written together as T6 M06. Wrap it in a safe routine: stop the spindle, send Z home, change the tool, then re-apply tool length offset with G43. The exact moves depend on the control, so confirm the tool-change behavior in your machine’s manual.

Sources

Frequently asked questions

What is M06 in CNC?

M06 is the M-code that performs a tool change. It works with the T word that selects the tool, so T6 M06 selects tool 6 and changes to it. On an automatic changer it swaps the tool; on a manual machine it prompts the operator.

What is the difference between T and M06?

T selects the tool and, on many controls, pre-stages it by rotating the carousel. M06 is the action that swaps it into the spindle. Splitting them lets the carousel stage the next tool while the current one is still cutting.

Why do you need G43 after M06?

The new tool is a different length, so the control must apply its length offset for Z depths to stay correct. G43 with the matching H register does that, usually on the first Z move after the change.

What is the best way to learn M-codes like M06?

Drill them with active recall. A free app like G-Code Sprint quizzes M06 and the rest of the everyday codes as quick timed questions and repeats whichever ones you miss.

G-Code Sprint is a study and practice tool only. Always follow your instructor, employer, machine manual, and shop safety procedures.