Fanuc M-codes33 codes
Fanuc M-code List
The Fanuc M-code list below holds every M-code the G-Code Guru reference gives for Fanuc, M00 to M99: 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, 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.
| Code | Function |
|---|---|
| M00 | Program StopUnconditional program stop. Machine stops and waits for operator to press cycle start. Spindle, coolant, and feed are stopped. |
| M01 | Optional StopConditional program stop. Machine stops only if Optional Stop switch is ON. Allows operator to skip stops during production runs. |
| M02 | Program EndEnds the program. Stops spindle, coolant, and feed. Cursor stays at M02 line. Does not rewind program. |
| M03 | Spindle 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. |
| M04 | Spindle On CCWStarts the spindle rotating counter-clockwise. Used for left-hand tooling, left-hand tapping, and specific operations. |
| M05 | Spindle StopStops the spindle rotation. Should be called before tool changes and at program end. |
| M06 | Tool ChangeExecutes automatic tool change. Swaps the current tool for the tool specified by the preceding T command. Machine goes through its tool change sequence. |
| M07 | Mist Coolant OnActivates mist coolant (air/oil mixture). Provides lubrication with minimal coolant volume. Good for aluminum and where flood coolant is undesirable. |
| M08 | Flood Coolant OnActivates flood coolant. Standard coolant delivery for most machining operations. Provides cooling, lubrication, and chip evacuation. |
| M09 | Coolant OffTurns off all coolant (both mist and flood). Should be called before tool changes and at program end. |
| M10 | ClampActivates workholding clamp or 4th axis clamp. Specific function varies by machine configuration. |
| M11 | UnclampReleases workholding clamp or 4th axis clamp. Specific function varies by machine configuration. |
| M13 | Spindle CW + Coolant OnStarts spindle clockwise and turns on coolant simultaneously. Combines M03 and M08 in one command. |
| M14 | Spindle CCW + Coolant OnStarts spindle counter-clockwise and turns on coolant simultaneously. Combines M04 and M08. |
| M19 | Spindle OrientationOrients the spindle to a specific angular position and locks it. Required for tool changes with orientation, some boring cycles, and live tooling operations. |
| M21 | Mirror X-Axis OnEnables X-axis mirroring. All X coordinates are reversed. Used for symmetric parts. |
| M22 | Mirror Y-Axis OnEnables Y-axis mirroring. All Y coordinates are reversed. Used for symmetric parts. |
| M23 | Mirror OffCancels both X and Y axis mirroring. Returns to normal coordinate interpretation. |
| M29 | Rigid 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. |
| M30 | Program End and RewindEnds the program and rewinds to the beginning. Stops spindle, coolant, and feed. Standard program ending code. |
| M32 | Lubrication OnActivates automatic lubrication cycle. Lubricates machine slideways and ballscrews. |
| M33 | Lubrication OffDeactivates automatic lubrication or cancels manual lube cycle. |
| M36 | Part Counter IncrementIncrements the part counter by one. Used for production tracking and batch counting. |
| M37 | Part Counter DecrementDecrements the part counter by one. Used to correct count after scrapped parts. |
| M41 | Low Gear SelectSelects low gear range on machines with gear-driven spindles. Provides higher torque at lower RPM. |
| M42 | High Gear SelectSelects high gear range on machines with gear-driven spindles. Provides higher RPM at lower torque. |
| M48 | Enable Feedrate OverrideEnables feedrate override. Allows operator to adjust feed rate percentage during cutting. |
| M49 | Disable Feedrate OverrideDisables feedrate override. Machine runs at exactly programmed feed rate, ignoring override knob. |
| M50 | Pallet ClampClamps the pallet on machines with pallet systems. Ensures pallet is secured before machining. |
| M51 | Pallet UnclampUnclamps the pallet for removal or pallet change. |
| M60 | Pallet ChangeExecutes automatic pallet change on machines with pallet changer. Swaps workholding pallet for automated production. |
| M98 | Subprogram CallCalls a subprogram. Execution transfers to the subprogram and returns to the next line after M98 completes. |
| M99 | Subprogram ReturnReturns from a subprogram to the calling program. Execution continues at the line after the M98 call. |
Where Fanuc differs
- M06 is not a control function. Parameter 6071 holds the M code that calls program O9001, so
M06andM98 P9001mean 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.
T0101indexes 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.
- The reference lists M19 as spindle orientation, and Fanuc builders do use that number: M19 is spindle orientation on a Doosan HP5100 (31i-MB) and on a Makino Pro 3 (16i/18i). It is still the builder's code, and orientation is a CNC option: on an Alpha series spindle amplifier, an orientation command with the option parameter not set shows status error 05.
- The reference lists M50 and M51 as pallet clamp and unclamp. Those are builder numbers as well: on a Makino Pro 3 (Fanuc 16i/18i), M50 sets the AC and SL coefficients and the pallet change is M60.
- 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.
Which M-code orients or locks the spindle on a Fanuc?
Usually M19, because builders chose it: the Doosan HP5100 and Makino Pro 3 lists both give M19 as spindle orientation, and orientation needs the CNC option fitted. A clamp or brake that holds a lathe spindle for live tooling is a separate builder code, so the machine's own M-code list is the reference. See M03, M04 and M05: spindle control.
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 2 Nov 2026