This website requires JavaScript.
Coupons
Blog

CNC M Code List: Functions and Common Uses

Published Oct 29, 2026, updated Oct 29, 2026

21 min

Table of Contents
  • CNC M Code List and Their Functions
  • How Do M Codes Differ Between CNC Milling and Turning?
  • Example of M Codes in a CNC Program
  • How to Verify M Code Compatibility Before Running a CNC Program
  • FAQs About CNC M Codes

Key Takeaways

  • G codes define motion and machining modes, while M codes trigger auxiliary machine functions.
  • Common M codes include M00/M01 for program stops, M03/M04/M05 for spindle control, and M08/M09 for coolant control.
  • M-code assignments for functions such as chuck control, pallet changes, and live tooling vary by machine builder and model.
  • Always verify machine-specific M codes against the target machine's programming manual before running a CNC program.

An M code (miscellaneous code) is a CNC program command used to control machine functions beyond axis motion. G codes define motion and machining modes, while M codes commonly control spindle operation, coolant, tool changes, and program flow. The same M-code number can have different functions depending on the controller and machine configuration.

Some M codes are common across CNC machines, while others depend on the controller or machine model. The list below covers common M codes and their typical functions.

For a broader explanation of how G codes and M codes work together in a CNC program, see the guide to G code and M code in CNC programming.

CNC M Code List and Their Functions

This CNC M code list combines commonly used commands with documented machine-specific assignments for CNC milling and turning. The codes are organized numerically for quick reference. When the same code has different functions across controls or machine types, each assignment is listed separately.

The common-code descriptions represent widely used conventions, not a universal standard. Machine-specific examples are identified by control or machine type. Refer to the Haas mill M-code list, Haas lathe M-code list, and LinuxCNC M-code reference for the documented implementations shown below. Always verify the exact code definition, machine options, and execution requirements before running a program.

M CodeFunctionController / MachineNotes
M00Unconditional program stopCommon on many controlsPauses program execution. Restart behavior and the state of auxiliary functions depend on the control and machine.
M01Optional program stopCommon on many controlsStops the program when the optional-stop function is enabled.
M02Program endCommon on many controlsEnds the program. Reset and rewind behavior varies by controller.
M03Spindle clockwise/forward startCommon on many controlsTypically used with an S word to specify spindle speed. Confirm the direction convention for the machine.
M04Spindle counterclockwise/reverse startCommon on many controlsUsed where reverse spindle rotation is required; confirm that the operation and tooling permit it.
M05Spindle stopCommon on many controlsStops the spindle. Other machine functions may remain active.
M06Tool changeMany machining centers; LinuxCNCUsually works with a T word to identify the tool. The physical tool-change sequence depends on the machine and tool changer.
M07Mist coolant onLinuxCNCActivates mist coolant where configured. Haas mills use M07 for shower coolant; verify the intended coolant function on the target machine.
M08Coolant onCommon on many controlsOften used for flood coolant. The available coolant functions depend on the machine's equipment.
M09Coolant offCommon on many controlsCancels the applicable coolant functions supported by the control.
M10Fourth-axis brake engageHaas millMachine-specific assignment; not a general chuck command on Haas mills.
M10Chuck clampHaas latheUsed on supported Haas lathes; confirm the chuck configuration and interlocks.
M11Fourth-axis brake releaseHaas millMachine-specific assignment.
M11Chuck unclampHaas latheUsed on supported Haas lathes; verify workholding requirements before use.
M12Fifth-axis brake engageHaas millRequires the corresponding rotary-axis configuration.
M12Automatic jet air blast onHaas lathe, optionalNot a universal tailstock command.
M13Fifth-axis brake releaseHaas millMachine-specific assignment.
M13Automatic jet air blast offHaas lathe, optionalDo not assume this code controls a live-tool spindle.
M14Main spindle brake onHaas lathe, optional C-axisRequires the relevant spindle configuration.
M15Main spindle brake offHaas lathe, optional C-axisMachine-specific assignment.
M16Tool changeHaas millHaas documents M16 as a tool-change command. Do not assume this assignment applies to other controls.
M17Turret rotation forwardHaas latheMachine-specific turret command.
M18Turret rotation reverseHaas latheMachine-specific turret command.
M19Spindle orientCommon on some controls; Haas mill and latheProgrammable orientation angles and prerequisites vary by control and machine.
M21Tailstock advanceHaas lathe, optionalConfirm that a programmable tailstock is installed.
M21–M25Optional user M-function interface with M-FinHaas millUser-configured functions; actual actions depend on the machine interface and configuration.
M22Tailstock retractHaas lathe, optionalNot a universal tailstock command.
M23Thread-exit chamfer onHaas latheSpecific to the Haas lathe implementation.
M24Thread-exit chamfer offHaas latheSpecific to the Haas lathe implementation.
M26Rotary modulo path: shortest pathLinuxCNCRequires a rotary axis configured with ROTARY_MODULO = 1; confirm support in the installed LinuxCNC version.
M27Rotary modulo path: literal pathLinuxCNCControls the signed modulo path on supported rotary axes; confirm support in the installed LinuxCNC version.
M29Set output relay with M-FinHaas millMachine-specific output and handshake function.
M30Program end and resetCommon on many controlsTypically ends the program and resets or rewinds it for another run. Exact behavior varies.
M31Chip conveyor or auger forwardHaas mill and Haas lathe, where equippedRequires the corresponding chip-removal hardware.
M33Chip conveyor or auger stopHaas mill and Haas lathe, where equippedStops the applicable conveyor or auger.
M34Coolant spigot position incrementHaas millChanges the programmable coolant spigot position; it does not mean increasing coolant concentration or tank level.
M35Coolant spigot position decrementHaas millMachine-specific coolant positioning function.
M35Parts catcher part-off positionHaas latheSeparate Haas lathe assignment.
M36Pallet part readyHaas millUsed in the applicable pallet-handling sequence.
M36Parts catcher onHaas lathe, optionalRequires the corresponding parts catcher.
M37Parts catcher offHaas lathe, optionalTurns off the applicable parts catcher function.
M38Spindle speed variation onHaas latheMachine-specific function.
M39Tool turret rotationHaas millHaas mill assignment; do not confuse it with the Haas lathe function.
M39Spindle speed variation offHaas latheCancels the applicable spindle speed variation function.
M41Low gear selection or overrideHaas mill and Haas lathe, where equippedAvailability and behavior depend on the spindle and transmission configuration.
M42High gear selection or overrideHaas mill and Haas lathe, where equippedMachine-specific gear-range function.
M43Turret unlockHaas lathe, service use onlyNot intended as a routine production command; follow the machine's service procedures.
M44Turret lockHaas lathe, service use onlyFollow the machine's service procedures.
M46Conditional jump to a program lineHaas millUses controller-specific Q and P parameters; verify the required syntax.
M48Validate program for the loaded palletHaas millChecks program suitability for the loaded pallet under the supported configuration.
M48Enable feed and spindle speed overridesLinuxCNCEnables the applicable override controls.
M49Disable feed and spindle speed overridesLinuxCNCDisables the applicable override controls.
M50Pallet-change sequenceHaas millInitiates the supported pallet-change sequence; requires the relevant equipment.
M50Feed override controlLinuxCNCUses a P parameter to enable or disable feed override control.
M51–M55Set optional user M-codesHaas millUser-configurable outputs; exact behavior depends on the machine setup.
M51–M56Turn on built-in M-code relayHaas latheThe relay assignment is machine-specific.
M51Spindle speed override controlLinuxCNCControls whether the spindle speed override affects the programmed speed.
M52Adaptive feed controlLinuxCNCUses the configured adaptive-feed input and override behavior.
M53Feed-stop controlLinuxCNCEnables or disables the configured feed-stop function.
M59Set output relayHaas mill and Haas latheOutput selection and parameter syntax depend on the control and machine.
M60Pallet-change pauseLinuxCNCPauses program execution for a pallet change; it does not universally initiate an automatic pallet exchange.
M61Set current tool numberLinuxCNCUpdates the control's current tool number; it does not itself perform a physical tool change.
M61–M65Clear optional user M-codesHaas millCancels the applicable optional user M-code outputs.
M61–M66Turn off built-in M-code relayHaas latheMachine-specific relay function.
M62–M65Digital output controlLinuxCNCOutput behavior and synchronization depend on the specific M code and configuration.
M66Input controlLinuxCNCUsed to wait for or read a configured input according to the documented parameters.
M67Synchronized analog outputLinuxCNCAnalog output is coordinated with motion according to the configured output and parameters.
M68Immediate analog outputLinuxCNCAnalog output behavior differs from M67; check the control documentation.
M69Clear output relayHaas mill and Haas latheClears the applicable output relay.
M70Workholding clampHaas millRequires the appropriate workholding hardware and configuration.
M70Save modal stateLinuxCNCSaves supported modal settings for later restoration.
M71Workholding unclampHaas millUse only when the machine's workholding sequence permits release.
M71Invalidate saved modal stateLinuxCNCInvalidates the saved modal state.
M72Restore modal stateLinuxCNCRestores the supported modal settings previously saved by M70.
M73Tool air blast onHaas millRequires the applicable air-blast hardware.
M73Save and automatically restore modal stateLinuxCNCSaves the supported state and restores it at the relevant program-flow boundary.
M74Tool air blast offHaas millMachine-specific air-blast function.
M75Set G35/G136 reference pointHaas millUsed with the applicable probing or reference-point functions.
M76Control display inactiveHaas millMachine-specific display function.
M77Control display activeHaas millCompanion to M76.
M78Alarm if skip signal is foundHaas mill and Haas latheSkip-signal behavior depends on the control and probing configuration.
M79Alarm if skip signal is not foundHaas mill and Haas latheCompanion to M78.
M80Automatic door openHaas mill, where equippedRequires the corresponding automatic-door hardware and interlocks.
M81Automatic door closeHaas mill, where equippedMachine-specific door function.
M82Tool unclampHaas millTool-clamp hardware and safety requirements apply.
M83Automatic air gun onHaas millRequires the corresponding air-gun hardware.
M84Automatic air gun offHaas millCompanion to M83.
M85Automatic door openHaas lathe, optionalHaas lathe assignment; not interchangeable with the Haas mill M80.
M86Tool clampHaas millHaas mill assignment.
M86Automatic door closeHaas lathe, optionalHaas lathe assignment; check the installed door option.
M88Through-spindle coolant onSupported Haas millsRequires the corresponding through-spindle coolant hardware.
M88High-pressure coolant onHaas lathe, optionalHaas lathe assignment; verify the machine's coolant configuration.
M89Through-spindle coolant offSupported Haas millsCompanion to M88 for the documented mill configuration.
M89High-pressure coolant offHaas lathe, optionalHaas lathe assignment.
M90Fixture clamp input onHaas mill and Haas latheInput behavior depends on the machine configuration.
M91Fixture clamp input offHaas mill and Haas latheCompanion to M90.
M95Sleep modeHaas mill and Haas latheExact timing and machine behavior depend on the control.
M96Jump if no input or signalHaas mill and Haas latheConditional program flow; parameter syntax varies by control.
M97Local subprogram callHaas mill and Haas latheCalls a subprogram within the main program; syntax is control-specific.
M98Subprogram callCommon on supported controlsOften uses a P word for the subprogram number and may use an L word for repeats. Verify the applicable syntax.
M99Subprogram return or loopHaas mill, Haas lathe, and LinuxCNCCan return from a subprogram or perform a control-specific loop/repeat function.
M100–M199User-defined M codesLinuxCNCThese are user-defined commands rather than a universal set of built-in functions. Implementation requires the appropriate configuration or user scripts.
M104Probe arm extendHaas mill and Haas lathe, where equippedRequires the relevant probing hardware.
M105Probe arm retractHaas mill and Haas lathe, where equippedCompanion to M104.
M109Interactive user inputHaas mill and Haas lathePauses for operator input using the supported control interface.
M110Secondary spindle chuck clampHaas lathe, optionalRequires the corresponding secondary spindle configuration.
M111Secondary spindle chuck unclampHaas lathe, optionalConfirm workholding and interlock requirements.
M112Secondary spindle air blast onHaas lathe, optionalRequires the relevant hardware.
M113Secondary spindle air blast offHaas lathe, optionalCompanion to M112.
M114Secondary spindle brake onHaas lathe, optionalMachine-specific brake function.
M115Secondary spindle brake offHaas lathe, optionalCompanion to M114.
M116Vise air blast onHaas mill, where equippedMachine-specific chip-clearing function.
M117Vise air blast offHaas mill, where equippedCompanion to M116.
M119Secondary spindle orientHaas lathe, optionalRequires a supported secondary spindle orientation function.
M121–M126Built-in M-code relays with M-FinHaas latheThe specific relay and handshake behavior depend on the machine configuration.
M129Turn on M-code relay with M-FinHaas latheMachine-specific relay and handshake function.
M130Display mediaHaas mill and Haas latheDisplays supported media content on the control.
M131Cancel media displayHaas mill and Haas latheCancels the M130 display.
M133Live-tool forwardHaas lathe, optionalRequires live tooling; verify spindle speed and tooling requirements.
M134Live-tool reverseHaas lathe, optionalMachine-specific live-tool command.
M135Live-tool stopHaas lathe, optionalStops the applicable live-tool spindle.
M138Spindle speed variation onHaas mill and Haas latheAvailability and behavior depend on the machine and control.
M139Spindle speed variation offHaas mill and Haas latheCompanion to M138.
M143Secondary spindle forwardHaas lathe, optionalRequires a supported secondary spindle.
M144Secondary spindle reverseHaas lathe, optionalVerify spindle direction and transfer sequence.
M145Secondary spindle stopHaas lathe, optionalStops the applicable secondary spindle.
M146Steady rest clampHaas lathe, optionalRequires the corresponding steady-rest configuration.
M147Steady rest unclampHaas lathe, optionalCompanion to M146.
M158Mist condenser onHaas mill and Haas lathe, where equippedRequires the corresponding mist-condenser system.
M159Mist condenser offHaas mill and Haas lathe, where equippedCompanion to M158.
M160Cancel active PulseJet operationHaas mill, where equippedRequires the applicable PulseJet option.
M161PulseJet continuous modeHaas mill, where equippedMachine-specific lubrication function.
M162PulseJet single-event modeHaas mill, where equippedMachine-specific lubrication function.
M163PulseJet modal modeHaas mill, where equippedBehavior depends on the PulseJet implementation.
M170Fourth-axis brake engageHaas lathe, where equippedMachine-specific rotary-axis function.
M171Fourth-axis brake releaseHaas lathe, where equippedCompanion to M170.
M174Programmable main chuck pressure adjustmentHaas lathe, optionalRequires a supported programmable chuck-pressure system.
M175Programmable secondary-spindle chuck pressure adjustmentHaas lathe, optionalRequires a supported secondary-spindle pressure system.
M180Automatic window openHaas mill, where equippedRequires the corresponding automatic-window hardware.
M181Automatic window closeHaas mill, where equippedCompanion to M180.
M199Pallet/part load sequence or program endHaas mill, where supportedExact behavior depends on the machine, automation setup, and control configuration.
M214Live-tool brake onHaas lathe, optionalRequires the corresponding live-tool brake.
M215Live-tool brake offHaas lathe, optionalCompanion to M214.
M219Live-tool orientHaas lathe, optionalRequires the supported live-tool orientation function.
M299APL/part-loading sequence or program endHaas lathe, where supportedBehavior depends on the automation setup and program configuration.
M300APL/robot custom sequenceHaas mill and Haas lathe, where supportedCustom automation sequence; confirm the machine-specific implementation.
M334Programmable coolant nozzle incrementHaas lathe, where equippedP-Cool positioning function.
M335Programmable coolant nozzle decrementHaas lathe, where equippedCompanion to M334.
M373Tool air blast onHaas lathe, where equippedRequires the corresponding tool air-blast option.
M374Tool air blast offHaas lathe, where equippedCompanion to M373.
M388Through-spindle coolant onHaas lathe, optionalRequires the corresponding through-spindle coolant hardware.
M389Through-spindle coolant offHaas lathe, optionalCompanion to M388.

The table covers frequently used commands and a broad range of documented control-specific assignments, but it does not replace the complete programming manual for a particular machine. Additional M codes may be available for options such as automatic part loading, tool probing, custom relays, or machine-builder-specific automation.

When two controls assign different meanings to the same M code, use the row for the exact controller and machine configuration. Do not transfer a code definition from one machine to another based on the number alone.

CNC machine and control panel displaying M codes

CNC machine and control panel displaying M codes

How Do M Codes Differ Between CNC Milling and Turning?

Many commonly used M codes serve the same basic purpose on milling and turning machines. For example, M03/M04/M05 are commonly used for spindle control, while M08/M09 control coolant on supported machines. Exact implementation still depends on the control and machine builder.

The differences are specific to one machine type. Turning centers may include chuck, tailstock, bar-feeder, and subspindle functions. The available M codes depend on the machine's equipment and control configuration.

Chuck and tailstock commands are machine-specific. On Haas lathes, M10/M11 clamp and unclamp the chuck, while M21/M22 advance and retract the tailstock. Do not infer these functions from the code number alone when working with another machine. On a turning center with a subspindle for second-operation machining, M codes control which spindle is active, whether parts transfer between spindles, and how the subspindle synchronizes with the main spindle during part handoff.

Live-tool turning centers use separate commands for the main spindle and the live-tool spindle. On Haas lathes, M133 starts the live tool forward, M134 runs it in reverse, and M135 stops the live tool. M12/M13 control the optional auto jet air blast, while M14/M15 control the main-spindle brake on supported C-axis configurations. Other machine builders may assign different codes, so verify which spindle each command controls in the machine manual.

Pallet-change commands depend on the control and automation package. Haas mills use M50 for the pallet-change sequence. LinuxCNC documents M60 as a pallet-change pause. Whether an actual pallet exchange occurs depends on the configured hardware, external logic, and machine implementation. The two commands are not interchangeable. Follow the sequence specified for the target machine.

Treat common spindle and coolant M codes as a starting reference, not proof of full program compatibility. Before running a program on a specific machine, verify any M code that controls auxiliary hardware and confirm its execution sequence against the machine builder's documentation.

Example of M Codes in a CNC Program

The following simplified CNC milling program illustrates common M-code sequencing on a Fanuc-style vertical machining center with an automatic tool changer and flood coolant. It assumes that tool T02 has a matching H02 tool-length offset and that G54 Z0 is set at the top of the workpiece. The programmed Z50.0 position must provide adequate clearance for the actual setup. M-code behavior and tool-change sequences vary by machine, so verify the program against the target machine's programming manual before use.

O2001                        ; Program number
N010 G21 G17 G40 G49 G80 G94 ; Set metric units, XY plane, and feed per minute; cancel cutter comp, tool length comp, and canned cycles
N020 G28 G91 Z0              ; Return Z to machine reference using incremental mode
N030 G90 G54                 ; Absolute mode and work coordinate system
N040 T02 M06                 ; Load tool 2 (12 mm end mill; confirm H02 matches its measured length)
N050 S3500 M03               ; Set spindle speed and start spindle clockwise
N060 G00 X0 Y0               ; Rapid to XY start position; confirm Z clearance is safe
N070 G43 H02 Z50.0           ; Apply tool length offset H02 and move to safe Z
N080 M08                     ; Flood coolant on
N090 G00 Z5.0                ; Rapid to 5 mm above the workpiece
N100 G01 Z-10.0 F150         ; Feed to cutting depth at 150 mm/min
N110 X80.0 F400              ; Linear cut at 400 mm/min
N120 Y50.0                   ; Continue cutting in Y
N130 X0                      ; Return in X
N140 Y0                      ; Return in Y
N150 G00 Z50.0               ; Retract to safe height
N160 M09                     ; Coolant off
N170 M05                     ; Spindle stop
N180 G49                     ; Cancel tool length compensation
N190 G28 G91 Z0              ; Return Z to machine reference
N200 M30                     ; End program and rewind/reset as supported

Note

The cutting moves and S/F values are illustrative only. Select the entry strategy and cutting parameters for the actual material, tool, stock, and setup.

M-code sequencing affects how the machine executes the program. In this example, coolant starts before the first cutting move and turns off after the tool retracts. The spindle starts before cutting begins and stops after machining is complete. In a multi-tool program, check whether the machine stops the spindle automatically during M06; if not, program M05 before the tool change as required by the machine builder.

For an inspection pause, insert M00 at the intended stop point rather than replacing M30. M00 pauses program execution, while spindle and coolant behavior depends on the machine. After inspection, follow the controller's restart procedure before continuing.

How to Verify M Code Compatibility Before Running a CNC Program

Running a CNC program with unverified M codes is a direct path to unexpected machine behavior. The verification process has four components.

  1. Check the machine builder's programming manual

    This is the authoritative source for M code definitions on a specific machine. The manual lists every M code the machine implements, what it does, any prerequisites (machine must be at home, spindle must be stopped), and whether the code has options or parameters. Documentation from major machine builders such as Haas, Mazak, DMG MORI, and Okuma is often available online; older machines may require a physical manual.

  2. Check the CNC controller documentation

    The controller and the machine builder are sometimes different entities. A machine built by one manufacturer running a Fanuc 31i controller will have both machine-builder-specific M codes and Fanuc-standard M codes. Both documentation sources are needed to understand the full M code behavior on that specific machine.

  3. Verify the CAM post-processor configuration

    CAM software outputs M codes based on the post-processor selected for the target machine. A generic post-processor produces generic M codes that may not match the specific machine. The post-processor should be configured for the exact machine and controller combination, including correct M code numbers for tool change, coolant, and any machine-specific functions used. A post-processor configured for a different machine can output M codes that do not match the target machine. Here's a guide to CNC post-processors explaining how CAM output is converted into code for a specific machine and controller.

  4. Simulate and prove out the program before cutting

    CNC simulation can check tool motion and the M-code behavior supported by its machine model. It may not reproduce every machine-specific auxiliary function, particularly when the control or post-processor has not been configured to represent that hardware. Before the first production run on a new program or machine, follow the machine builder's prove-out procedure. Where appropriate, use graphics mode or a controlled dry run with rapid override reduced and the tool clear of the workpiece. Confirm that the spindle and coolant respond as programmed, and verify the actual tool-change sequence before machining material. Investigate any unexpected behavior before the cutting run.

JLCCNC Logo

Precision CNC Machining Service

Upload your CAD file to get a fast quote starting from $1, with lead times as short as 3 days.

Get Instant Quote

FAQs About CNC M Codes

What Is the Difference Between M00 and M01?

M00 always stops the program until the operator restarts it. M01 stops the program only when Optional Stop is enabled.

What Is the Difference Between M02 and M30?

Both end a CNC program. M02 ends the program, while M30 usually ends it and resets the program to the start. Exact behavior depends on the controller.

What Do M03 and M04 Do?

M03 starts the spindle clockwise, while M04 starts it counterclockwise. M05 stops the spindle. The S code sets the spindle speed.

Are M Codes the Same on All CNC Machines?

No. Common M codes are similar across many machines, but codes for functions like pallet changes and through-spindle coolant can vary. Check the machine's programming manual.

What Do M08 and M09 Do?

M08 typically turns on flood coolant, while M09 turns off the applicable coolant functions. M07 may control mist coolant or shower coolant, depending on the control and machine.

Can More Than One M Code Appear in the Same Program Block?

Some controllers allow multiple M codes in one block, but their execution order can vary. Using separate blocks helps ensure machine functions run in the correct sequence.

Keep Learning