Fanuc M-codes33 codes

Fanuc M-code List

The G-Code Guru reference lists thirty-odd M-codes for Fanuc, and this table has every one: stops and ends, spindle, coolant, tool change, clamps, pallets and subprogram calls. Fanuc itself sets the meaning of M00, M01, M02, M30, M98 and M99; every other number in the table, M03 to M09 included, is decoded by the builder's PMC ladder.

Fanuc M-code: 33 codes

Codes in colour link to a full page with a worked example and controller differences; the rest link to their row on the M-code list.

CodeFunctionNotes
M00Program StopUnconditional program stop. Machine stops and waits for operator to press cycle start. Spindle, coolant, and feed are stopped.Use for mandatory operator intervention: part flip, inspection, manual deburr.
M01Optional StopConditional program stop. Machine stops only if Optional Stop switch is ON. Allows operator to skip stops during production runs.Controlled by Optional Stop switch on control panel. Ignored when switch is off.
M02Program EndEnds the program. Stops spindle, coolant, and feed. Cursor stays at M02 line. Does not rewind program.Use M30 instead for most applications - it rewinds to program start.
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.Always verify S value is set before M03. Allow dwell (G04) after spindle start for heavy cuts.
M04Spindle On CCWStarts the spindle rotating counter-clockwise. Used for left-hand tooling, left-hand tapping, and specific operations.Used with left-hand taps (G74), left-hand helix end mills, and specific boring operations.
M05Spindle StopStops the spindle rotation. Should be called before tool changes and at program end.Spindle continues to coast - may need dwell for complete stop before tool change.
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.CRITICAL: Ensure safe Z position before M06. Many machines auto-retract, but always verify.
M07Mist Coolant OnActivates mist coolant (air/oil mixture). Provides lubrication with minimal coolant volume. Good for aluminum and where flood coolant is undesirable.Not all machines have mist coolant capability. Check machine configuration.
M08Flood Coolant OnActivates flood coolant. Standard coolant delivery for most machining operations. Provides cooling, lubrication, and chip evacuation.Turn on after spindle start, turn off before spindle stop to prevent splashing.
M09Coolant OffTurns off all coolant (both mist and flood). Should be called before tool changes and at program end.Always turn off coolant before spindle stop to prevent coolant spray.
M10ClampActivates workholding clamp or 4th axis clamp. Specific function varies by machine configuration.Function is machine-specific. May control rotary axis clamp, pallet clamp, or custom fixture.
M11UnclampReleases workholding clamp or 4th axis clamp. Specific function varies by machine configuration.Function is machine-specific. May control rotary axis clamp, pallet clamp, or custom fixture.
M13Spindle CW + Coolant OnStarts spindle clockwise and turns on coolant simultaneously. Combines M03 and M08 in one command.Convenience code. Not available on all controllers.
M14Spindle CCW + Coolant OnStarts spindle counter-clockwise and turns on coolant simultaneously. Combines M04 and M08.Convenience code for left-hand operations with coolant.
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.Required before G76 fine boring, some ATC machines, and B-axis live tooling on lathes.
M21Mirror X-Axis OnEnables X-axis mirroring. All X coordinates are reversed. Used for symmetric parts.Useful for machining symmetric parts. Cancel with M23.
M22Mirror Y-Axis OnEnables Y-axis mirroring. All Y coordinates are reversed. Used for symmetric parts.Useful for machining symmetric parts. Cancel with M23.
M23Mirror OffCancels both X and Y axis mirroring. Returns to normal coordinate interpretation.Always cancel mirroring at program end.
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.Requires spindle encoder for synchronization. No need for tension/compression tap holder. On Haas, rigid tapping is default in G84.
M30Program End and RewindEnds the program and rewinds to the beginning. Stops spindle, coolant, and feed. Standard program ending code.Preferred over M02 for most applications. Program ready to run again after M30.
M32Lubrication OnActivates automatic lubrication cycle. Lubricates machine slideways and ballscrews.Usually automatic. Manual call for extended operations.
M33Lubrication OffDeactivates automatic lubrication or cancels manual lube cycle.Machine usually controls this automatically.
M36Part Counter IncrementIncrements the part counter by one. Used for production tracking and batch counting.Place after successful program completion. Counter visible on control.
M37Part Counter DecrementDecrements the part counter by one. Used to correct count after scrapped parts.Use when part is scrapped to maintain accurate count.
M41Low Gear SelectSelects low gear range on machines with gear-driven spindles. Provides higher torque at lower RPM.Not all machines have gear ranges. Required on some older or heavy-duty machines.
M42High Gear SelectSelects high gear range on machines with gear-driven spindles. Provides higher RPM at lower torque.High gear for finishing operations and smaller tools that need high RPM.
M48Enable Feedrate OverrideEnables feedrate override. Allows operator to adjust feed rate percentage during cutting.
M49Disable Feedrate OverrideDisables feedrate override. Machine runs at exactly programmed feed rate, ignoring override knob.Use for critical feed rates like threading or tapping where override would cause problems.
M50Pallet ClampClamps the pallet on machines with pallet systems. Ensures pallet is secured before machining.Machine-specific. Verify pallet is clamped before cutting.
M51Pallet UnclampUnclamps the pallet for removal or pallet change.Use before M60 pallet change or manual pallet removal.
M60Pallet ChangeExecutes automatic pallet change on machines with pallet changer. Swaps workholding pallet for automated production.Machine-specific. Requires pallet changer option. Similar to M06 but for pallets.
M98Subprogram CallCalls a subprogram. Execution transfers to the subprogram and returns to the next line after M98 completes.Subprogram must end with M99. Useful for repeated patterns and tool paths.
M99Subprogram ReturnReturns from a subprogram to the calling program. Execution continues at the line after the M98 call.Must be at end of every subprogram. In main program, M99 loops back to start.

Where Fanuc differs

  • M06 is not a control function. Parameter 6071 holds the M code that calls program O9001, so M06 and M98 P9001 mean the same thing once 6 is written into it, and the retract, orient and arm sequence is the builder's, not Fanuc's.
  • M07, M08 and M09 are decoded by the PMC ladder. The ladder pulls in the pump contactor and returns the completion signal, so whether M30 leaves the pump running, and which number drives which pump, is ladder logic and differs between two machines on the same 0i control.
  • A turret lathe has no tool change block. T0101 indexes the turret and applies offset 01 in the same word, tool number first, offset second.
  • The reference lists M13 and M14 as spindle and coolant on in one block, for Fanuc and Haas only, and the app's note says they are not available on every control. On a Fanuc they are builder codes like any other: on a Fanuc-controlled Doosan HP5100, M13 is intermittent coolant on and M14 a collet air blow.
  • The reference lists M32 and M33 as way lubrication for Fanuc and Mazak only, and the app's note says the machine usually runs the lube itself. The numbers are the builder's: on the same Doosan HP5100, M33 is a tool data compare.
  • Subprograms are called with M98 P and returned with M99, and the control handles both itself. M97 is the Haas local call, not a Fanuc one: the control sends it to the PMC ladder like any other builder number, so a Haas post that writes M97 never jumps to the N block, and what happens instead is the builder's ladder logic.

Frequently asked questions

Which M-codes are standard on every Fanuc?

Fanuc sets the meaning of M00, M01, M02, M30, M98, M99 and M198, and even there the builder decides details such as what M30 switches off. Every other number, M03 to M09 included, is only a request to the builder's PMC ladder, so anything outside that set has to be checked against the machine's own list.

Does M06 on a Fanuc call a macro?

Not always. The control does not know how to change a tool, so the builder supplies the sequence. Where parameter 6071 holds 6, M06 calls program O9001, which the builder writes to retract, orient and swap for that particular changer, and M98 P9001 does the same thing. Other builders run the whole change in the PMC ladder instead.

Why does the same M-code do different things on two Fanuc machines?

Because anything above the basic set is decoded by the builder's PMC ladder, not by Fanuc. Two machines on an identical 0i control can use different coolant numbers, run different tool change sequences and treat M30 differently, all because their builders wired and programmed them differently.

What is the difference between M98 and M99?

M98 P calls a subprogram by number and M99 returns from it. M99 at the end of a main program loops back to the top instead, which is how a program is made to run again without the operator pressing Cycle Start. See M-code list for the subprogram group.

Other controller lists

Last updated 11 Oct 2026