# LinuxCNC M5

Instructions · `M5` · verification: source checked

M5 is a G-code M instruction in LinuxCNC that stops the selected spindle. An optional $ parameter selects which spindle is stopped; without it the command applies to spindle 0. M5 can be issued whether the spindle is turning or already stopped.

## Specification

| Property | Value |
|---|---|
| Language | gcode |
| Code | M5 |
| Group | Spindle Control |
| Syntax | M5 [$n] |
| Dialect | LinuxCNC |

### Parameters

| Name | Description |
|---|---|
| $n | Spindle to stop. Omit to operate on spindle 0; use $-1 to operate on all active spindles. |

## Study notes

- The optional $ parameter selects the spindle: $0, $1, $2 address individual spindles, and $-1 operates on all active spindles.
- If $ is omitted, M5 operates on spindle 0, which is the normal behaviour for a single-spindle machine.
- Example from the document: M5 $2 stops spindle 2 and leaves the other spindles rotating.
- M19 spindle orient is in the same modal group (group 7) as M3, M4 and M5, and M19 is cleared by any of M3, M4 or M5.
- Program end (M2/M30) stops the spindle as if M5 were executed, along with resetting offsets, plane, distance mode and coolant.

## Sources

1. [M-Codes](https://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m3-m4-m5) (accessed 2026-10-26)

---

Source page: https://machineschema.com/instruction/mcode-m05  
JSON: https://machineschema.com/instruction/mcode-m05.json  
License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Cite Machine Schema and the original sources.
