Glossary · CNC and machine tools
M-code
Also known as: Miscellaneous function, M word
German: M-Code
In CNC programming, an M-code is a miscellaneous function, written with the address letter M and a number, that switches machine functions such as spindle start and stop, coolant, tool change or program end.
- CNC
- Standards
In one sentence
An M-code is a miscellaneous function in a CNC program that switches machine functions such as spindle, coolant, tool change or program end.
Example
M03 S2000 starts the spindle clockwise at 2,000 rpm, M08 switches on the coolant and M30 ends the program.
How it applies
- Engineering: Some M-codes are common across controls (M03, M05, M30), but many are assigned by the machine builder and executed by the PLC part of the CNC, for example to clamp a pallet or open a door. Their meaning is machine-specific.
- Commissioning: Machine-specific M-codes must be tested together with the interlocks they depend on, such as door or clamping state, before the machine is released.
- Documentation: Every machine-specific M-code belongs in the machine's programming or Operating manual with its function, preconditions and effects. Keep this list under change control: when the PLC program changes an M-code, the document must change in the same release.
M-code vs. G-code
G-codes define how the tool moves; M-codes switch machine functions. A single Program block (NC) can contain both, and the control defines the order in which they take effect within the block.