Reference49 entries7 controllers

M-code List

This M-code list has all 49 M-codes in the G-Code Guru reference, grouped by job: program stops and ends, spindle, coolant, tool change, clamps and subprograms. G-codes command motion and modes; M-codes switch machine functions: M03 starts the spindle, M08 turns on flood coolant, M06 changes the tool and M30 ends and rewinds the program. For the Fanuc meaning of each code and its notes, see the Fanuc M-code list.

Codes shown in colour link to a full page with a worked example, controller differences and what goes wrong on the shop floor. Sort by any column or type to filter.

49 of 49

Program control 21

Stops and ends (M00, M01, M02, M30), mirror image (M21 to M23), part counters (M36, M37), feed override lock-out (M48, M49), pallet change (M60), the Haas M97 local call, and the printer-side stepper and message codes.

Controllers
M00Program StopUnconditional program stop. Machine stops and waits for operator to press cycle start. Spindle, coolant, and feed are stopped.Program ControlMill · Lathe · 3D printerAll 7
M01Optional StopConditional program stop. Machine stops only if Optional Stop switch is ON. Allows operator to skip stops during production runs.Program ControlMill · Lathe · 3D printerAll 7
M02Program EndEnds the program. Stops spindle, coolant, and feed. Cursor stays at M02 line. Does not rewind program.Program ControlMill · Lathe · 3D printerAll 7
M21Mirror X-Axis OnEnables X-axis mirroring. All X coordinates are reversed. Used for symmetric parts.Program ControlMillFanuc
M22Mirror Y-Axis OnEnables Y-axis mirroring. All Y coordinates are reversed. Used for symmetric parts.Program ControlMillFanuc
M23Mirror OffCancels both X and Y axis mirroring. Returns to normal coordinate interpretation.Program ControlMillFanuc
M30Program End and RewindEnds the program and rewinds to the beginning. Stops spindle, coolant, and feed. Standard program ending code.Program ControlMill · Lathe · 3D printerAll 7
M36Part Counter IncrementIncrements the part counter by one. Used for production tracking and batch counting.Program ControlMill · LatheFanuc
M37Part Counter DecrementDecrements the part counter by one. Used to correct count after scrapped parts.Program ControlMill · LatheFanuc
M48Enable Feedrate OverrideEnables feedrate override. Allows operator to adjust feed rate percentage during cutting.Program ControlMill · Lathe · 3D printerFanuc, Siemens, Mazak, Grbl, Marlin
M49Disable Feedrate OverrideDisables feedrate override. Machine runs at exactly programmed feed rate, ignoring override knob.Program ControlMill · Lathe · 3D printerFanuc, Siemens, Mazak, Grbl, Marlin
M60Pallet ChangeExecutes automatic pallet change on machines with pallet changer. Swaps workholding pallet for automated production.Program ControlMillFanuc
M82Absolute ExtrusionSets extruder to absolute positioning mode. E values represent total filament extruded from start.Program Control3D printerMarlin, Grbl
M83Relative ExtrusionSets extruder to relative positioning mode. E values represent filament for each move only.Program Control3D printerMarlin, Grbl
M84Disable SteppersDisables stepper motors after a period of inactivity, or immediately if no time specified. Saves power and reduces noise.Program Control3D printerMarlin, Grbl
M97Local Subprogram CallCalls a local subprogram within the same program file. Jumps to a block with the specified N number and executes until M99 is encountered, then returns.Program ControlMill · LatheHaas
M117Display MessageDisplays a text message on the printer's LCD screen. Useful for showing progress updates, instructions, or status messages during a print.Program Control3D printerMarlin, Grbl
M200Set Filament DiameterSets the filament diameter for volumetric extrusion mode. When enabled, E values represent cubic millimeters instead of linear filament length.Program Control3D printerMarlin
M400Wait for Moves to FinishWaits for all buffered moves to complete before processing the next command. Ensures synchronization.Program Control3D printerMarlin, Grbl
M420Bed Leveling StateControls the bed leveling compensation. Can enable/disable stored mesh and show leveling data.Program Control3D printerMarlin
M600Filament ChangeInitiates a filament change sequence. Pauses print, retracts filament, and prompts user to load new filament.Program Control3D printerMarlin

Spindle control 9

M03, M04 and M05 start and stop the spindle, M13 and M14 start it with coolant in the same block, M19 orients it, M29 switches rigid tapping on and M41, M42 pick the gear range.

Controllers
M03Spindle On CWStarts the spindle rotating clockwise (when viewed from above on a vertical mill, or from the tailstock on a lathe). Standard direction for right-hand tooling.Spindle ControlMill · Lathe · 3D printerAll 7
M04Spindle On CCWStarts the spindle rotating counter-clockwise. Used for left-hand tooling, left-hand tapping, and specific operations.Spindle ControlMill · Lathe · 3D printerAll 7
M05Spindle StopStops the spindle rotation. Should be called before tool changes and at program end.Spindle ControlMill · Lathe · 3D printerAll 7
M13Spindle CW + Coolant OnStarts spindle clockwise and turns on coolant simultaneously. Combines M03 and M08 in one command.Spindle ControlMill · LatheFanuc
M14Spindle CCW + Coolant OnStarts spindle counter-clockwise and turns on coolant simultaneously. Combines M04 and M08.Spindle ControlMill · LatheFanuc
M19Spindle OrientationOrients the spindle to a specific angular position and locks it. Required for tool changes with orientation, some boring cycles, and live tooling operations.Spindle ControlMill · Lathe · 3D printerAll 7
M29Rigid TappingActivates rigid tapping mode where the spindle and Z-axis are electronically synchronized. Provides more accurate threading than floating tap holders, especially in harder materials.Spindle ControlMillFanuc, Siemens
M41Low Gear SelectSelects low gear range on machines with gear-driven spindles. Provides higher torque at lower RPM.Spindle ControlMill · LatheFanuc, Haas, Siemens, Okuma
M42High Gear SelectSelects high gear range on machines with gear-driven spindles. Provides higher RPM at lower torque.Spindle ControlMill · LatheFanuc, Haas, Siemens, Okuma

Coolant 5

M07 mist, M08 flood and M09 off, plus the M106 and M107 part-cooling fan on printers. Which pump a number drives is decided by the machine builder, not the control.

Controllers
M07Mist Coolant OnActivates mist coolant (air/oil mixture). Provides lubrication with minimal coolant volume. Good for aluminum and where flood coolant is undesirable.Coolant ControlMill · Lathe · 3D printerAll 7
M08Flood Coolant OnActivates flood coolant. Standard coolant delivery for most machining operations. Provides cooling, lubrication, and chip evacuation.Coolant ControlMill · Lathe · 3D printerAll 7
M09Coolant OffTurns off all coolant (both mist and flood). Should be called before tool changes and at program end.Coolant ControlMill · Lathe · 3D printerAll 7
M106Part Cooling Fan OnTurns on the part cooling fan at the specified speed. Essential for PLA, bridges, and overhangs.Coolant Control3D printerMarlin, Grbl
M107Part Cooling Fan OffTurns off the part cooling fan. Equivalent to M106 S0.Coolant Control3D printerMarlin, Grbl

Tool change 1

M06 hands over to the machine's own tool change sequence. What retracts, orients and swaps is the builder's macro or ladder, so the same M06 runs differently on every machine.

Controllers
M06Tool ChangeExecutes automatic tool change. Swaps the current tool for the tool specified by the preceding T command. Machine goes through its tool change sequence.Tool ChangeMill · Lathe · 3D printerAll 7

Clamps and fixtures 4

M10 and M11 clamp and release a rotary axis or fixture; M50 and M51 do the same for a pallet.

Controllers
M10ClampActivates workholding clamp or 4th axis clamp. Specific function varies by machine configuration.Clamps & FixturesMill · Lathe · 3D printerAll 7
M11UnclampReleases workholding clamp or 4th axis clamp. Specific function varies by machine configuration.Clamps & FixturesMill · Lathe · 3D printerAll 7
M50Pallet ClampClamps the pallet on machines with pallet systems. Ensures pallet is secured before machining.Clamps & FixturesMillFanuc
M51Pallet UnclampUnclamps the pallet for removal or pallet change.Clamps & FixturesMillFanuc

Subprograms 2

M98 calls a subprogram and M99 returns from it, or loops the main program when there is nothing to return to.

Controllers
M98Subprogram CallCalls a subprogram. Execution transfers to the subprogram and returns to the next line after M98 completes.SubprogramMill · Lathe · 3D printerFanuc, Haas, Siemens, Mazak, Grbl, Marlin
M99Subprogram ReturnReturns from a subprogram to the calling program. Execution continues at the line after the M98 call.SubprogramMill · Lathe · 3D printerFanuc, Haas, Siemens, Mazak, Grbl, Marlin

Lubrication and printer temperatures 7

Way lubrication (M32, M33) and the printer heater codes M104 to M190.

Controllers
M32Lubrication OnActivates automatic lubrication cycle. Lubricates machine slideways and ballscrews.OtherMill · LatheFanuc
M33Lubrication OffDeactivates automatic lubrication or cancels manual lube cycle.OtherMill · LatheFanuc
M104Set Extruder TemperatureSets the target temperature for the extruder (hotend). Does not wait for temperature to be reached - continues immediately.Other3D printerMarlin, Grbl
M105Report TemperaturesReports current temperatures of all heaters (extruder, bed, chamber). Output includes current and target temperatures. Used for monitoring and host communication.Other3D printerMarlin, Grbl
M109Wait for Extruder TemperatureSets extruder temperature and waits for it to be reached before continuing. Blocks execution until at temperature.Other3D printerMarlin, Grbl
M140Set Bed TemperatureSets the target temperature for the heated bed. Does not wait - continues immediately. Use M190 to wait.Other3D printerMarlin, Grbl
M190Wait for Bed TemperatureSets bed temperature and waits for it to be reached. Blocks execution until bed is at target temperature.Other3D printerMarlin, Grbl

Descriptions are the one-line entries from the app's reference database. Controller support marks whether a code exists in that dialect, not that it behaves identically; the full pages cover the differences.

By controller

The same list filtered to one control, with the dialect notes that matter on that machine.

Frequently asked questions

What is the difference between M00 and M01?

M00 stops the program every time: spindle, coolant and feed stop, and the machine waits for Cycle Start. M01 does the same only when the optional stop switch on the control panel is on; with the switch off the block is skipped. Put an M00 where the operator must act (flip the part, deburr, inspect) and an M01 where a stop helps on a proving run but would slow a production run.

Is M30 the same as M02?

Both end the program and stop the spindle, coolant and feed. M30 also rewinds to the top, so the program is ready to run again; M02 leaves the cursor on the M02 block. On a Haas, Setting 56 (M30 Restore Default G) decides whether M30 also puts the modal G codes back to their defaults, which is why a program that relies on modal state can behave differently on its second run.

Is M08 the same on Fanuc and Haas?

M08 is flood coolant on and M09 is coolant off on both. M07 is where they part: on a Fanuc-based mill M07 is mist, while on a Haas mill M07 is the optional shower coolant, so a post that writes M07 for mist runs the shower pump instead. Through-spindle coolant is separate again, M88 on and M89 off on a Haas. See M07, M08 and M09: coolant.

Why does M06 behave differently on different machines?

Because M06 is not a control function. On a Fanuc, parameter 6071 holds the M code that calls program O9001, so the tool change is a subprogram written by the machine builder, and the retract, orient and arm sequence is theirs. Siemens selects with T and activates the tool and its offset with M6. Grbl v1.1 does not support M6 at all and stops the stream with error:20; Marlin changes tools with the T word alone. See M06: tool change.

Do Grbl and Marlin use the same M-codes as a Fanuc?

Only the low numbers, and not all of those. Grbl v1.1 has M8 and M9 built in but M7 only when ENABLE_M7 is uncommented in config.h, and no M6. Marlin has M7, M8 and M9 only with COOLANT_CONTROL enabled, and a stock printer build answers "Unknown command" and carries on. Both use the T word rather than an M code to select a tool, and Marlin's own M104 to M190 heater codes have no equivalent on a machine tool.

Updated 24 Oct 2026