G54.APP

G-code deep dive

M3, M4, M5 Spindle & M7, M8, M9 Coolant Codes

M3M4M5M19M7M8M9S

Spindle and coolant are the workhorse M-codes — identical across every control in the table, which makes them the most portable lines in a program:

T1 M6
S12000 M3        ; speed first, then direction — spindle spins up
M8               ; flood on
G0 X0 Y0 Z5
...              ; cutting
M9               ; coolant off
M5               ; spindle stop

S sets speed but starts nothing; M3/M4 start rotation but carry no speed of their own. The pair on one line (S12000 M3) is idiomatic. A new S while running changes speed on the fly — canned tapping cycles rely on the control managing exactly that.

Timing: does the machine wait?

Most controls hold the program until the spindle reports at-speed before the next motion (or the post inserts a G4 dwell to the same effect). Hobby controls often don't — GRBL fires the PWM and moves on immediately, which is why GRBL posts add a dwell after M3. A tool entering material at 10% speed sounds exactly as bad as it is; if your first cuts chatter for half a second, check the post's spin-up handling.

OperationLinuxCNCGRBLCentroidFANUCMach3Mach4Notes
Spindle on, clockwise M3 M3 M3 M3 M3 M3 S word sets speed.
Spindle on, counter-clockwise M4 M4 M4 M4 M4 M4 GRBL laser mode: dynamic power.
Spindle stop M5 M5 M5 M5 M5 M5
Spindle orient (oriented stop) M19 M19 M19 M19 Centroid: needs a custom M19 macro. Mach3: depends on builder VBScript. Mach3: builder-dependent
Mist coolant on M7 M7 M7 M7 M7 M7
Flood coolant on M8 M8 M8 M8 M8 M8
All coolant off M9 M9 M9 M9 M9 M9

— means the control has no equivalent code. Full cross-control tables: the complete G-code & M-code reference.

Common mistakes

Frequently asked questions

What is the difference between M3 and M4?

Rotation direction. M3 spins clockwise (viewed from above the tool, the normal direction for right-hand cutters), M4 counter-clockwise. Milling runs M3 almost exclusively; M4 appears for left-hand tools, some tapping retracts, and reversed lathe work.

Does M3 start the spindle at full speed?

M3 starts rotation at the speed set by the S word — which is modal, so it can come earlier in the program. S1200 M3 is the usual pairing. An M3 with no S ever set means zero or an alarm depending on the control: always set S first.

What is the difference between M7 and M8?

M7 is mist coolant (air/oil aerosol), M8 is flood coolant (pumped liquid). They map to two different outputs on the machine; hobby machines often wire only one. M9 turns both off.

Why is M4 special on GRBL?

In GRBL's laser mode, M4 enables dynamic power: laser output scales with actual motion speed so acceleration ramps don't burn darker. On the same board driving a spindle, M4 is just reverse — the overload of meaning is a GRBL quirk worth knowing when reading laser G-code.

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