M6 executes a tool change; the T word says which tool. Together
they're the boundary line every multi-tool program is organized around:
; ---- Tool 2: 6mm end mill ----
M5 ; spindle off
G53 G0 Z0 ; retract to machine top
T2 M6 ; the change itself
G43 H2 ; new tool's length offset — NEVER skip
S9500 M3
G0 X0 Y0 Z5 ; back to work
What M6 physically does is machine-specific — carousel swap, umbrella
dance, drawbar release and a beep asking a human to do it — but the
program-side contract is the same everywhere: after M6, tool n is in
the spindle and no length offset is active until you apply one.
#T is a selection, M6 is the act
On magazine machines the two are deliberately separate. T pre-stages:
the carousel rotates the named pocket into position while cutting
continues. M6 then swaps in seconds. Posts exploit it like this:
T3 M6 ; change to tool 3
T4 ; stage tool 4 NOW — magazine turns during the next op
... ; tool 3 cuts
M6 ; instant change to the already-staged tool 4
On hobby machines the distinction collapses — T2 M6 is simply "swap to
tool 2", and on stock GRBL it means "pause so the human can."
| Operation | LinuxCNC | GRBL | Centroid | FANUC | Mach3 | Mach4 | Notes |
|---|---|---|---|---|---|---|---|
| Tool change | M6 |
— | M6 |
M6 |
M6 |
M6 |
Pairs with a prior Tn. GRBL pauses and prompts. |
| Set current tool number (no change) | M61 |
— | — | — | — | — | Declares the loaded tool without a swap. |
— means the control has no equivalent code. Full cross-control tables: the complete G-code & M-code reference.
#The lines around the change
A tool change is a cluster, not a line, and the cluster has an order:
- Before: coolant off (
M9), spindle stop (M5), retract to a safe machine position (G53 G0 Z0orG91 G28 Z0 G90). - The change:
Tn M6. - After: length offset (
G43 Hn), speed and direction (S… M3), coolant back on, rapid to the next feature at safe height first.
Almost every tool-change crash is a missing item 3: the G43 forgotten
(tool runs a full length low — see the tool length page) or the first
rapid going to X/Y and Z in one move with a longer tool than before.
#Common mistakes
- No G43 after the change. The single most expensive omission in G-code. New tool, no length comp, first Z move too low.
- H number from the old tool.
T4 M6 G43 H3applies tool 3's length to tool 4. Posts get this right; hand edits are where it breaks. - Changing tools below safe height. M6 at Z-5 in a pocket asks the change macro to move through the part. Retract explicitly first.
- Assuming the changer knows the tool. After a manual swap or restart,
the control's idea of the loaded tool can be stale — that's what
LinuxCNC's
M61 Qn(and equivalent screens elsewhere) exist to fix.