G54.APP

G-code deep dive

M6 Tool Change: How T Numbers and Tool Calls Work

M6TM61

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."

OperationLinuxCNCGRBLCentroidFANUCMach3Mach4Notes
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:

  1. Before: coolant off (M9), spindle stop (M5), retract to a safe machine position (G53 G0 Z0 or G91 G28 Z0 G90).
  2. The change: Tn M6.
  3. 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

Frequently asked questions

What is the difference between T1 and M6?

T1 selects (stages) tool 1; M6 executes the change. On carousel machines the split is real — T for the next tool can be given during cutting so the magazine rotates in parallel, then M6 swaps instantly. On simpler machines T and M6 on one line just means 'change to this tool now'.

What does M6 do on GRBL?

Stock GRBL has no tool changer: M6 pauses the program and waits for you to swap the tool by hand and cycle-start. Typical GRBL workflows then probe the new tool's length and apply it with G43.1 before resuming.

Does M6 include the spindle stop and Z retract?

The change macro on most machines stops the spindle and moves Z to the change position itself — but posts still emit M5 and a retract explicitly beforehand, because relying on the macro is machine-specific. Treat M6 as 'swap tools', not 'make it safe to swap tools'.

What is M61 for?

LinuxCNC's 'set current tool without changing': M61 Q3 tells the control tool 3 is already in the spindle. It's for recovery situations — resuming mid-job after a restart — not normal programs.

See it, don't guess it

Paste a program into the free G54.APP viewer and watch these codes execute — toolpaths, stock removal, and machine state, live in your browser. Nothing is uploaded.

Open the G-code viewer