M-codeSpindle ControlMill · Lathe · 3D printer
M03, M04 & M05: Starting and Stopping the Spindle
M03 starts the spindle clockwise, M04 starts it anticlockwise and M05 stops it. Clockwise is the view from above on a vertical mill and from the tailstock on a lathe, which is the way right-hand tooling has to turn to cut. Speed comes from the S word, and S is modal, so it holds from an earlier block and the direction word is what actually starts the motor. Where a builder has fitted them, M13 and M14 roll the spindle and the coolant into one block, and those two belong to whoever built the machine, not to the control.
Syntax
S__ M03 Spindle clockwise at the programmed speed
S__ M04 Spindle anticlockwise
M05 Spindle stop
S__ M13 Spindle clockwise and coolant on, where the builder has fitted it
S__ M14 Spindle anticlockwise and coolant onParameters
| Address | Meaning | Notes |
|---|---|---|
S | Spindle speed | Modal, and read as rev/min under G97 or as surface metres per minute under G96 on a lathe. Written on the direction block or on any block before it |
| none | M05 carries no address | M03 and M04 carry none either once an S is already live, which is why a rewind to the middle of a program can start the spindle at last year's speed |
A commanded spindle is not a turning spindle. The direction word goes out to the drive and the control reads the next block, so unless the spindle speed arrival signal is being checked, the cut starts while the motor is still accelerating. That is a machine setting, not something the program controls, and it is the single thing worth knowing about these three codes.
Example
O0030 (COVER PLATE, 120 X 60 X 35 IN 6082)
G21 G17 G40 G49 G80 G90 (safe start block)
T04 M06 (63mm face mill, five inserts)
G54 (part zero at the top left corner)
S1200 M03 (237m/min in aluminium, clockwise)
G04 P2000 (two seconds of ramp before the first cut)
G00 X-45. Y-30. (clear of the left edge, on the centreline)
G43 H04 Z50. M08 (tool 4 length, flood on)
G01 Z-1. F500 (1mm skim off the top face)
X165. F1800 (one pass over the full 60mm width)
G00 Z50. M09 (clear of the job, coolant off)
M05 (spindle stopped before the carousel moves)
G49 (drop the face mill's length)
G91 G28 Z0. (Z to machine home, X and Y stay put)
G90 T07 M06 (12mm three flute carbide end mill)
S4800 M03 (181m/min, clockwise again)
G00 X-10. Y-30. (off the end of the plate)
G43 H07 Z50. M08 (tool 7 length, flood on)
G01 Z-8. F400 (down to depth in fresh air)
X130. F900 (slot straight through the 120mm length)
G00 Z50. M09
M05 (stop the spindle before the program ends)
G49
G91 G28 Z0.
M30Controller differences
| Control | Behaviour |
|---|---|
| Fanuc | The three codes are auxiliary functions. The control strobes the M code to the builder's PMC ladder, which drives the serial spindle forward and reverse signals and sends the completion signal back, so how fast the drive ramps and how hard it brakes is drive parameters and ladder rather than anything in the program. Whether the control waits for the spindle to reach speed before a cutting feed is bit 0 (SAR) of parameter 3708, and parameter 3740 sets how long it waits after the speed command before it starts looking at the signal. |
| Haas | M06 already stops the spindle and switches coolant off, through-spindle included, before the changer moves, so an M05 ahead of a tool change is belt and braces rather than a requirement. The mill list does carry an M13: it is Release 5th Axis Brake, with M12 engaging the brake, and there is no M14, so an M13 posted from another builder's machine releases the brake rather than starting the spindle and the coolant. On the lathe M13 is air jet off and M14 main spindle clamp. |
| Siemens 840D | M3, M4 and M5 are predefined by the NCK, which is the opposite of the coolant codes, so they mean the same thing on every 840D. On a machine with more than one spindle the number goes into the address: M2=3 starts spindle 2 clockwise and S2=1000 sets its speed, while SETMS hands master-spindle status to a given spindle so that a bare M3 and S reach it. SPOS positions the spindle rather than M19. |
| Mazak | In a Mazatrol conversational program speed and direction are fields in each unit, and the control changes them at the unit boundary. On a machining centre EIA/ISO programs use M03, M04 and M05 as on Fanuc. On an INTEGREX e-series those three drive the milling spindle, and turning spindle 1 takes M203 to M205. |
| Grbl | M4 is not reverse on a laser build. With $32=1, laser mode, M4 is dynamic power, where the output is scaled by the current feed rate so that corners and ramps do not overburn, and M3 is constant power. S is scaled between $31 and $30 onto the PWM output, and an S0 under M3 leaves the output off with the spindle state still reported as on. |
| Marlin | M3, M4 and M5 exist only with SPINDLE_FEATURE or LASER_FEATURE in Configuration_adv.h, and M4 needs SPINDLE_CHANGE_DIR on top of that. SPINDLE_CHANGE_DIR_STOP stops the spindle before it reverses and SPINDLE_LASER_POWERUP_DELAY holds the program off while the drive ramps, which is the arrival check done with a timer. CUTTER_POWER_UNIT decides whether S is read as PWM255, PERCENT or RPM, so the same S1200 is full output on one build and a twentieth of it on another. |
What goes wrong
A drill snaps on the first hole because the block under M03 ran while the spindle was still winding up. The control issues the direction word and carries on unless it has been told to wait, and on a Fanuc that wait is the spindle speed arrival check in parameter 3708, which plenty of builders leave switched off. A 50 taper reaching 6000 rev/min takes several seconds. Switch the check on, or put a G04 P2000 under the start block and let the clock do it.
Second is direction on a turning centre. A rear turret holds the insert upside down and cuts under M03, while the same insert in a front turret or on a gang plate wants M04. Get it the wrong way round and the clearance face rubs until the tip breaks off.
Third is coasting. M05 commands a stop, it does not wait for one, so an M00 written underneath it for a manual tool change hands the operator a cutter that is still turning. A Haas stops the spindle inside M06 for you. A machine with a manual change does not.
Fourth, M13 and M14 are the builder's, not the control's. A post that writes S1200 M13 because the last shop's mill had it releases the fifth axis brake on a Haas mill and switches intermittent coolant on at a Doosan HP5100, and on neither machine does the spindle start.
Last, Grbl reads M4 as dynamic laser power rather than reverse once $32=1 is set, so a router program posted with M4 runs the spindle forward with the output chasing the feed rate.
Updated 11 Oct 2026