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:
M3— spindle on, clockwise, at the modalSspeedM4— spindle on, counter-clockwiseM5— spindle stopM19— oriented stop (lock at a known angle — tool changers, back-boring)M7— mist coolant onM8— flood coolant onM9— all coolant off
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.
| Operation | LinuxCNC | GRBL | Centroid | FANUC | Mach3 | Mach4 | Notes |
|---|---|---|---|---|---|---|---|
| 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
- M3 with no S word anywhere. Depending on the control: alarm, zero
RPM, or a stale speed from the last job. State
Sin every program. - Wrong direction for the tool. A right-hand end mill under M4 rubs instead of cutting and work-hardens the material before it breaks. If chips aren't forming, direction is the 10-second check.
- Plunging while the spindle is stopped. Programs edited by hand sometimes lose the M3 line. A simulator that flags feed moves with the spindle off catches it before the machine does — this viewer's spindle telemetry shows exactly that state.
- Assuming coolant lines exist. M7 on a machine with no mist system is silently ignored (fine) or alarms (annoying), depending on setup. Posts have flags for which coolant outputs the machine actually has.
- Forgetting M9 before program end. Harmless to the part, hard on the shop floor — the pump runs until someone notices. M30 resets coolant on many controls, but not all; explicit M9 is good manners.