{"id":11629,"date":"2026-05-31T13:45:45","date_gmt":"2026-05-31T05:45:45","guid":{"rendered":"https:\/\/www.cncmachiningshops.com\/?p=11629"},"modified":"2026-07-16T11:31:31","modified_gmt":"2026-07-16T03:31:31","slug":"m-code","status":"publish","type":"post","link":"https:\/\/www.cncmachiningshops.com\/fr\/m-code\/","title":{"rendered":"Le code M dans l'usinage CNC : \u00e0 quoi sert-il et comment l'utiliser correctement ?"},"content":{"rendered":"<div data-page-id=\"QIhVd8ekToM0zmxW37scrJD5nIe\" data-lark-html-role=\"root\" data-docx-has-block-data=\"true\">\n<blockquote><p><strong>Quick Answer:<\/strong> M-code (miscellaneous code) controls all non-movement functions in a CNC machine: spindle start and stop (M03\/M04\/M05), coolant on and off (M08\/M09), tool changes (M06), program pauses (M00\/M01), and program end (M30). While G-code tells the machine where to move, M-code tells it what state the machine must be in to do useful work \u2014 without M03 the spindle doesn&#8217;t rotate, without M08 the cutting zone overheats, and without M05 before M06 a tool change is attempted with the spindle still spinning. M-code sequencing errors are one of the most common causes of tool breakage, surface finish failures, and machine crashes in CNC production. Core M-codes are largely standard across Fanuc, Haas, and Siemens controllers; advanced and auxiliary functions vary by machine builder.<\/p><\/blockquote>\n<hr \/>\n<h2>What Is M-Code?<\/h2>\n<p>M-code (short for miscellaneous code) is the section of CNC programming language that controls machine state rather than tool path geometry. Every CNC machine running ISO 6983 \/ EIA RS-274 compliant code uses two parallel layers of instructions:<\/p>\n<p><strong>G-code<\/strong> \u2014 the motion and geometry layer. G-code defines axes positions, interpolation modes (linear, circular, helical), feed rates, coordinate systems, and cutting cycles. G-code tells the machine where to go and how to get there.<\/p>\n<p><strong>M-code<\/strong> \u2014 the machine control layer. M-code defines whether the spindle is rotating and in which direction, whether coolant is flowing, which tool is loaded, and whether the program is paused or terminated. M-code tells the machine what state it must be in to perform useful machining.<\/p>\n<p>The physical consequence of this division: G-code moves the tool to position X50 Y20 \u2014 but if M03 (spindle on) was not issued before that G01 move, the spindle is stationary when the tool reaches the workpiece. The tool engages the material while not rotating, generating friction instead of cutting, burning the tool edge within seconds, and potentially scoring the workpiece surface.<\/p>\n<p>G-code defines the path. M-code makes the path produce parts.<\/p>\n<hr \/>\n<h2>M-Code vs G-Code: The Critical Difference<\/h2>\n<table>\n<thead>\n<tr>\n<th>Function<\/th>\n<th>G-Code<\/th>\n<th>M-Code<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Controls axis movement (X, Y, Z)<\/td>\n<td>Yes<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>Controls feed rate<\/td>\n<td>Yes<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>Controls spindle rotation<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Controls coolant<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Controls tool changes<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Controls program flow (pause, end)<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Controls machine auxiliary functions<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Defines geometry (circular arcs, canned cycles)<\/td>\n<td>Yes<\/td>\n<td>No<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Neither code type functions independently for real machining:<\/p>\n<ul>\n<li>G-code without M-code: the machine follows a motion path with the spindle off and coolant off \u2014 no material removal, and likely tool or workpiece damage on contact.<\/li>\n<li>M-code without G-code: the spindle rotates, coolant flows, tools change \u2014 but no cutting motion occurs.<\/li>\n<\/ul>\n<p>A complete CNC program interleaves both: M-code sets the machine into the correct operating state, G-code executes the cutting geometry, M-code transitions between operations and terminates the program.<\/p>\n<hr \/>\n<h2>The Standard M-Code Reference<\/h2>\n<h3>Spindle Control: M03, M04, M05<\/h3>\n<p><strong>M03 \u2014 Spindle ON, clockwise rotation<\/strong> The most fundamental machining M-code. Issued before any cutting motion, typically with an S-word (spindle speed in RPM): <code>M03 S3000<\/code> starts the spindle at 3000 RPM in the clockwise direction. Standard for all right-hand cutting tools \u2014 end mills, drills, boring bars, taps with conventional thread direction.<\/p>\n<p><strong>M04 \u2014 Spindle ON, counterclockwise rotation<\/strong> Used for left-hand tools, reverse threading, and some special operations. Issuing M04 when M03 was intended (or vice versa) produces the wrong cutting direction \u2014 for a drill this means the cutting edges are trailing rather than leading, resulting in rubbing, heat generation, and rapid edge damage.<\/p>\n<p><strong>M05 \u2014 Spindle STOP<\/strong> Stops spindle rotation. This must be issued before any tool change (M06) \u2014 a tool change with the spindle rotating creates a mechanical collision between the rotating tool and the tool changer mechanism, a frequently catastrophic event for the spindle. M05 must also be issued before the program end (M30) to prevent the machine from completing its cycle with the spindle still running.<\/p>\n<h3>Coolant Control: M07, M08, M09<\/h3>\n<p><strong>M08 \u2014 Coolant ON (flood)<\/strong> Activates flood coolant \u2014 the primary coolant mode for most CNC machining. Must be issued before the cutting tool contacts the workpiece. Coolant provided after cutting begins means the first portion of the cut runs without thermal control, producing the worst surface finish and highest tool wear in that early period.<\/p>\n<p>The thermal consequence of missing M08: in steel machining, cutting zone temperatures reach 500\u2013800\u00b0C without coolant. Above approximately 600\u00b0C, high-speed steel begins to lose hardness; carbide retains hardness longer but heat accelerates crater wear. The chips that should carry heat away from the cutting zone instead re-weld to the tool rake face (built-up edge), degrading cutting geometry and surface finish.<\/p>\n<p><strong>M07 \u2014 Mist coolant (where supported)<\/strong> Air-oil mist rather than flood coolant, used for materials where flood coolant is counterproductive (cast iron where flood causes thermal shock) or in applications requiring lubrication without the chip re-welding of dry cutting.<\/p>\n<p><strong>M09 \u2014 Coolant OFF<\/strong> Stops all coolant. Issued after cutting moves complete, before spindle stop and tool changes.<\/p>\n<h3>Tool Change: M06<\/h3>\n<p><strong>M06 \u2014 Tool change<\/strong> Executes an automatic tool change, moving the currently loaded tool to the magazine and loading the tool specified by the T-word: <code>M06 T3<\/code> unloads the current tool and loads Tool 3. On most machining centers, the tool carousel pre-selects the next tool (using the T-word) while the current operation runs, so the tool change itself takes only the time for the actual swap rather than time to find the tool.<\/p>\n<p>Critical sequencing requirement: the spindle must be stopped (M05) before M06 is issued. On most controllers, issuing M06 without a prior M05 will either trigger a fault or force a spindle stop before proceeding \u2014 but some machines will attempt the tool change immediately, creating a collision risk.<\/p>\n<p>M06 also returns the Z-axis to the tool change position (typically machine zero or a defined safe height) before executing the swap. Programmers who issue M06 without ensuring the tool is at safe Z can cause the outgoing tool to contact the workpiece or fixture during the tool change motion.<\/p>\n<h3>Program Control: M00, M01, M30<\/h3>\n<p><strong>M00 \u2014 Program stop (unconditional)<\/strong> Halts program execution completely and requires operator action to continue. Used for in-process inspection \u2014 pause after roughing to measure a critical dimension, pause to reposition the part, pause to clear chips from deep pockets. The operator typically presses CYCLE START to resume.<\/p>\n<p><strong>M01 \u2014 Optional stop (conditional)<\/strong> Functions like M00 only when the machine controller&#8217;s &#8220;Optional Stop&#8221; switch is enabled. When the switch is off, M01 is ignored and the program continues. Used for steps the programmer wants available for debugging or inspection but doesn&#8217;t want to interrupt normal production runs.<\/p>\n<p><strong>M30 \u2014 Program end and reset<\/strong> Ends the program and returns the control to the beginning of the program, resetting the machine state. This is the standard program terminator. Ending a program without M30 leaves the machine in an undefined state \u2014 subsequent programs may start with incorrect spindle states, coolant conditions, or tool offsets.<\/p>\n<h3>Summary: Core M-Code Reference<\/h3>\n<table>\n<thead>\n<tr>\n<th>M-Code<\/th>\n<th>Function<\/th>\n<th>Typical Usage Context<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>M00<\/td>\n<td>Unconditional program stop<\/td>\n<td>In-process inspection, part repositioning<\/td>\n<\/tr>\n<tr>\n<td>M01<\/td>\n<td>Optional program stop<\/td>\n<td>Debug pause, conditional inspection<\/td>\n<\/tr>\n<tr>\n<td>M03 S___<\/td>\n<td>Spindle ON, clockwise at __ RPM<\/td>\n<td>Before all standard cutting operations<\/td>\n<\/tr>\n<tr>\n<td>M04 S___<\/td>\n<td>Spindle ON, counterclockwise at __ RPM<\/td>\n<td>Left-hand tools, reverse tapping<\/td>\n<\/tr>\n<tr>\n<td>M05<\/td>\n<td>Spindle stop<\/td>\n<td>Before tool change, at operation end<\/td>\n<\/tr>\n<tr>\n<td>M06 T__<\/td>\n<td>Tool change to tool #<\/td>\n<td>Between machining operations<\/td>\n<\/tr>\n<tr>\n<td>M07<\/td>\n<td>Mist coolant on<\/td>\n<td>Cast iron, sensitive materials<\/td>\n<\/tr>\n<tr>\n<td>M08<\/td>\n<td>Flood coolant on<\/td>\n<td>Before all cutting operations<\/td>\n<\/tr>\n<tr>\n<td>M09<\/td>\n<td>All coolant off<\/td>\n<td>After cutting, before tool change<\/td>\n<\/tr>\n<tr>\n<td>M30<\/td>\n<td>Program end and reset<\/td>\n<td>Last line of every program<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>The M-Code Sequence in a Complete Machining Program<\/h2>\n<p>Understanding M-code is most useful in context \u2014 the specific order in which M-codes appear within a program directly determines machining quality and machine safety. The following represents a standard two-operation program (milling followed by drilling):<\/p>\n<pre><code>T1 M06              ; Pre-select and change to Tool 1 (end mill)\r\nM03 S3000           ; Spindle ON, 3000 RPM\r\nM08                 ; Flood coolant ON\r\nG00 Z5              ; Rapid to Z clearance\r\nG01 X50 Y20 F200    ; Milling cut\r\nG01 X100 Y20 F200   ; Continue milling\r\nG00 Z50             ; Retract to safe Z\r\nM09                 ; Coolant OFF\r\nM05                 ; Spindle STOP\r\nT2 M06              ; Change to Tool 2 (drill)\r\nM03 S2000           ; Spindle ON, 2000 RPM\r\nM08                 ; Coolant ON\r\nG81 X30 Y40 Z-15 R5 F100 ; Drilling canned cycle\r\nG80                 ; Cancel canned cycle\r\nG00 Z50             ; Retract to safe Z\r\nM09                 ; Coolant OFF\r\nM05                 ; Spindle STOP\r\nM30                 ; Program end and reset\r\n<\/code><\/pre>\n<p>Each M-code in this sequence serves a specific purpose:<\/p>\n<ul>\n<li>M03 before any G01 cutting move ensures the spindle is rotating before tool engagement<\/li>\n<li>M08 issued before the first cutting move ensures coolant is flowing before the tool contacts the workpiece<\/li>\n<li>M09 before M05 ensures coolant is off before spindle stops (prevents coolant pooling on non-rotating tooling)<\/li>\n<li>M05 before M06 ensures the spindle is stopped before the tool change<\/li>\n<li>M30 at program end resets the machine to ready state<\/li>\n<\/ul>\n<p>The order matters. Moving M08 to after the first G01 means the first cut runs dry. Moving M06 before M05 risks a mechanical collision.<\/p>\n<hr \/>\n<h2>What Happens When M-Code Is Wrong<\/h2>\n<p>M-code programming errors are physical errors \u2014 they produce immediate, measurable consequences in the machine:<\/p>\n<table>\n<thead>\n<tr>\n<th>Error<\/th>\n<th>Root Cause<\/th>\n<th>Physical Consequence<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Spindle not rotating during cutting<\/td>\n<td>Missing M03 or M04<\/td>\n<td>Tool rubs, burns, edge chipping; workpiece surface scoring<\/td>\n<\/tr>\n<tr>\n<td>Overheating during cutting<\/td>\n<td>Missing or late M08<\/td>\n<td>Accelerated tool wear, built-up edge, Ra degrades (e.g., Ra 1.6 \u2192 Ra 3.2+ \u00b5m)<\/td>\n<\/tr>\n<tr>\n<td>Wrong tool loaded<\/td>\n<td>Incorrect T-word with M06<\/td>\n<td>Wrong geometry machined, tool breakage, scrap part<\/td>\n<\/tr>\n<tr>\n<td>Tool change attempted with spindle running<\/td>\n<td>Missing M05 before M06<\/td>\n<td>Mechanical collision, tool changer damage, potential spindle damage<\/td>\n<\/tr>\n<tr>\n<td>Coolant continues after program<\/td>\n<td>Missing M09 before M30<\/td>\n<td>Minor (coolant pool in machine), but indicates incomplete sequencing<\/td>\n<\/tr>\n<tr>\n<td>Machine not reset for next run<\/td>\n<td>Missing M30<\/td>\n<td>Next cycle starts in undefined state \u2014 wrong offsets, wrong tool, wrong spindle speed<\/td>\n<\/tr>\n<tr>\n<td>Spindle wrong direction<\/td>\n<td>M04 used when M03 required<\/td>\n<td>Reverse cutting \u2014 immediate tool damage and poor surface finish<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The most expensive M-code error in production is the spindle-running tool change: the tool changer arm moves to engage the tool in the spindle while the spindle is rotating, causing a collision between the arm and the rotating tool. This event can damage the spindle taper, the tool changer arm, and the tool \u2014 a repair cost that can reach $5,000\u2013$50,000 in downtime and parts, preventable entirely by the two characters &#8220;M05&#8221; before &#8220;M06&#8221;.<\/p>\n<hr \/>\n<h2>M-Code Variation Between CNC Controllers<\/h2>\n<p>Most fundamental M-codes are standardized across the dominant CNC controller platforms (Fanuc, Haas, Siemens, Mitsubishi, Okuma). The core set \u2014 M03, M04, M05, M06, M07, M08, M09, M30 \u2014 behaves identically on essentially all production CNC machines.<\/p>\n<p>The divergence begins with machine-specific auxiliary functions:<\/p>\n<table>\n<thead>\n<tr>\n<th>Function<\/th>\n<th>Standard?<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Spindle on\/off (M03\/M05)<\/td>\n<td>Yes<\/td>\n<td>Universal<\/td>\n<\/tr>\n<tr>\n<td>Flood coolant (M08\/M09)<\/td>\n<td>Yes<\/td>\n<td>Universal<\/td>\n<\/tr>\n<tr>\n<td>Tool change (M06)<\/td>\n<td>Yes<\/td>\n<td>Universal mechanism; implementation varies<\/td>\n<\/tr>\n<tr>\n<td>Through-spindle coolant<\/td>\n<td>No<\/td>\n<td>Often M-code assigned by machine builder (e.g., Haas M52, varies on others)<\/td>\n<\/tr>\n<tr>\n<td>Air blast<\/td>\n<td>No<\/td>\n<td>Machine-dependent code<\/td>\n<\/tr>\n<tr>\n<td>Chip auger \/ conveyor<\/td>\n<td>No<\/td>\n<td>Machine-specific<\/td>\n<\/tr>\n<tr>\n<td>Pallet changer<\/td>\n<td>No<\/td>\n<td>Machine-specific<\/td>\n<\/tr>\n<tr>\n<td>Door open\/close<\/td>\n<td>No<\/td>\n<td>Machine-specific<\/td>\n<\/tr>\n<tr>\n<td>Probing cycles<\/td>\n<td>No<\/td>\n<td>Some standard in FANUC 0i, varies elsewhere<\/td>\n<\/tr>\n<tr>\n<td>Part catcher (lathe)<\/td>\n<td>No<\/td>\n<td>Machine-specific<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>When a program written for one machine is transferred to another, all standard M-codes will function. Any machine-specific M-code will produce either a fault (unknown M-code), execute a different function than intended, or be silently ignored \u2014 all of which can produce unexpected behavior. Programs transferred between machines must have all machine-specific M-codes reviewed and updated before running.<\/p>\n<hr \/>\n<h2>Common Programming Mistakes and How to Prevent Them<\/h2>\n<h3>Missing spindle start before cutting motion<\/h3>\n<p>The most basic error: a G01 or G02 move executes with M05 still active (spindle stopped). Prevention: require M03 or M04 before any G01\/G02\/G03 command in the program review checklist. On modern CNC controllers, this can also be caught by feedrate interlock logic, but this protection is machine-dependent.<\/p>\n<h3>Coolant activated after first cut engagement<\/h3>\n<p>M08 appears in the program but after the first G01 move rather than before it. The first cut runs without coolant, producing the worst surface quality and highest tool wear of the entire operation. Prevention: position M08 immediately before the first cutting motion, not after any other G-code commands in the same block or following block.<\/p>\n<h3>Incorrect tool number with M06<\/h3>\n<p>T2 M06 is issued but the T2 pocket in the carousel contains the wrong tool, or the tool offset (H\/D) for T2 was not entered. Prevention: verify tool setup sheet against program before execution; use tool length offset verification cycles where available.<\/p>\n<h3>Skipping M05 before M06<\/h3>\n<p>Discussed above \u2014 the most expensive common M-code mistake. Prevention: make M05 before M06 an inviolable programming rule; review every tool change block in program verification.<\/p>\n<h3>Omitting M30<\/h3>\n<p>The program runs to the last G-code line and stops without resetting. The next execution starts from the last line&#8217;s position rather than from the program beginning. Prevention: require M30 as the mandatory last line in every program.<\/p>\n<h3>Program checklist for M-code verification:<\/h3>\n<table>\n<thead>\n<tr>\n<th>Check<\/th>\n<th>Requirement<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>M03 or M04 before first cutting move?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>M08 before first cut engagement?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>M05 before every M06?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>M09 after last cutting move?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>M05 after last spindle rotation?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>M30 as last program line?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>T-word and H\/D offsets verified for all M06?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Machine-specific M-codes verified for this controller?<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>Key Takeaways<\/h2>\n<ul>\n<li><strong>M-code controls machine state, not geometry<\/strong>: spindle rotation, coolant flow, tool changes, and program flow are all M-code functions. G-code cannot substitute for M-code, and M-code cannot substitute for G-code.<\/li>\n<li><strong>M-code sequencing is as important as toolpath correctness<\/strong>: M05 must precede M06; M03 and M08 must precede cutting motions; M09 and M05 must follow cutting motions. The order is physical \u2014 wrong sequence causes tool damage, scrap parts, or machine crashes.<\/li>\n<li><strong>Missing M08 is a direct surface quality and tool life failure<\/strong>: cutting temperatures of 500\u2013800\u00b0C without coolant in steel machining cause built-up edge formation, accelerated tool wear, and Ra degradation \u2014 all preventable by correct M08 placement.<\/li>\n<li><strong>Core M-codes are standard across controllers<\/strong>: M03\/M05\/M06\/M08\/M09\/M30 behave consistently on Fanuc, Haas, Siemens, and most production CNC platforms. Advanced and auxiliary M-codes are machine-specific and are not portable.<\/li>\n<li><strong>The most expensive single M-code error is tool change with spindle running<\/strong>: missing M05 before M06 can cause spindle damage costing $5,000\u2013$50,000 \u2014 preventable with two characters.<\/li>\n<li><strong>M-code knowledge is relevant beyond programmers<\/strong>: machinists, operators, and manufacturing engineers who understand M-code can diagnose spindle, coolant, and sequence issues without requiring programmer intervention.<\/li>\n<li><strong>For OEM procurement teams<\/strong>: CNC programs supplied with custom parts should include M-code verification as part of first-article inspection \u2014 specifically confirming that coolant sequences, tool change sequences, and program termination are correctly programmed for the production machine.<\/li>\n<\/ul>\n<hr \/>\n<h2>Frequently Asked Questions<\/h2>\n<h3>What does M-code control in CNC machining?<\/h3>\n<p>M-code controls all non-movement machine functions in CNC programming. It manages: spindle rotation state and direction (M03 clockwise, M04 counterclockwise, M05 stop), coolant activation and deactivation (M08 flood on, M09 off), automatic tool changes (M06 with a T-word specifying the tool number), program pauses for operator action (M00 unconditional, M01 optional), and program termination and reset (M30). These functions are not optional \u2014 without M03 the spindle doesn&#8217;t rotate so no cutting occurs; without M08 the cutting zone overheats; without M05 before M06 a tool change is attempted with the spindle spinning, risking mechanical collision.<\/p>\n<h3>What is the difference between M-code and G-code?<\/h3>\n<p>G-code defines geometry and motion \u2014 axis positions (X, Y, Z), interpolation modes (G00 rapid, G01 linear, G02\/G03 circular), feed rates, and canned machining cycles. M-code defines machine state \u2014 whether the spindle is rotating and how fast, whether coolant is flowing, which tool is loaded, and whether the program is running, paused, or terminated. Both are required for functional machining. G-code without M-code moves the tool but cannot cut (spindle off). M-code without G-code activates machine functions but produces no cutting motion. In a complete program, they interleave: M-code establishes the operating state, G-code executes the geometry.<\/p>\n<h3>What are the most important M-codes to know?<\/h3>\n<p>The eight most critical M-codes for CNC machining are: M03 (spindle on, clockwise) \u2014 required before every cutting operation; M05 (spindle stop) \u2014 required before every tool change and at program end; M06 with T-word (tool change) \u2014 changes to the specified tool; M08 (flood coolant on) \u2014 required before cutting operations in steel and most metals; M09 (coolant off) \u2014 required after cutting completes; M30 (program end and reset) \u2014 terminates and resets every program; M00 (unconditional stop) \u2014 for in-process inspection; M04 (spindle on, counterclockwise) \u2014 for left-hand tools. These eight codes cover the vast majority of practical CNC machining requirements.<\/p>\n<h3>Can a wrong M-code crash a CNC machine?<\/h3>\n<p>Yes. The most common M-code crash scenario is issuing M06 (tool change) without first issuing M05 (spindle stop). The tool changer arm attempts to engage the rotating spindle, creating a mechanical collision that can damage the spindle taper, tool changer arm, retention knob, and cutting tool simultaneously \u2014 repair costs range from thousands to tens of thousands of dollars. Other dangerous M-code errors include: wrong spindle direction (M04 when M03 intended) causing immediate tool edge failure; machine-specific M-codes that trigger unexpected machine motions when run on a different controller; and missing Z-retract before M06 causing the outgoing tool to contact the workpiece or fixture during the tool change approach.<\/p>\n<h3>Do all CNC machines use the same M-codes?<\/h3>\n<p>The standard core M-codes (M03, M04, M05, M06, M07, M08, M09, M30) are consistent across essentially all production CNC machines running Fanuc, Haas, Siemens, Mitsubishi, and Okuma controllers. Machine-specific M-codes for auxiliary functions diverge significantly: through-spindle coolant, air blast, chip conveyor control, pallet changers, door operations, and robotic integration all use M-codes assigned by the machine builder that vary between machines. A program transferred from a Haas machining center to a Fanuc-controlled machine will have its core M-codes function correctly, but any Haas-specific M-codes will either fault or behave differently. All machine-specific M-codes must be verified against the target machine&#8217;s manual before running a transferred program.<\/p>\n<hr \/>\n<p><em>Written by the CMS engineering team with 15+ years of precision CNC machining experience programming and operating milling centers and turning centers under Fanuc, Haas, and Siemens control systems for automotive, aerospace, medical, electronics, and industrial OEM manufacturing applications. Technical references: ISO 6983-1 (Numerical Control of Machines \u2014 Program Format and Definitions), EIA RS-274-D (Interchangeable Variable Block Data Format), Fanuc 0i Series Programming Manual, Haas CNC Programming Workbook.<\/em><\/p>\n<hr \/>\n<p><strong>Sourcing Precision CNC Machined Components With Optimized Programming?<\/strong><\/p>\n<p>At CMS, we produce precision milled and turned components in aluminum, steel, stainless steel, and engineering plastics with fully documented CNC programs. Every program includes verified M-code sequences \u2014 correct spindle, coolant, and tool change sequencing \u2014 and first-article inspection before production release.<\/p>\n<p>[Request a CNC machining quote and programming review \u2192]<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>M-code CNC machining: what it controls, M-code vs G-code, complete M-code list, sequence errors, machine compatibility &#038; programming mistakes to avoid.<\/p>","protected":false},"author":1,"featured_media":11930,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[],"class_list":["post-11629","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cnc-machining-guide"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.5 (Yoast SEO v28.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>M-Code in CNC Machining: Complete Reference Guide<\/title>\n<meta name=\"description\" content=\"M-code CNC machining: what it controls, M-code vs G-code, complete M-code list, sequence errors, machine compatibility &amp; programming mistakes to avoid.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cncmachiningshops.com\/fr\/m-code\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"M-Code in CNC Machining: What It Does and How to Use It Correctly\" \/>\n<meta property=\"og:description\" content=\"M-code CNC machining: what it controls, M-code vs G-code, complete M-code list, sequence errors, machine compatibility &amp; programming mistakes to avoid.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cncmachiningshops.com\/fr\/m-code\/\" \/>\n<meta property=\"og:site_name\" content=\"CNC Machining Shops\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-31T05:45:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-16T03:31:31+00:00\" \/>\n<meta name=\"author\" content=\"cncmachiningshops\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"cncmachiningshops\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/\"},\"author\":{\"name\":\"cncmachiningshops\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#\\\/schema\\\/person\\\/2593a2e2de68be71300e10f486236551\"},\"headline\":\"M-Code in CNC Machining: What It Does and How to Use It Correctly\",\"datePublished\":\"2026-05-31T05:45:45+00:00\",\"dateModified\":\"2026-07-16T03:31:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/\"},\"wordCount\":2982,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/M-Code-in-CNC-Machining-800x600-1.jpg\",\"articleSection\":[\"CNC Machining Guide\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/\",\"url\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/\",\"name\":\"M-Code in CNC Machining: Complete Reference Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/M-Code-in-CNC-Machining-800x600-1.jpg\",\"datePublished\":\"2026-05-31T05:45:45+00:00\",\"dateModified\":\"2026-07-16T03:31:31+00:00\",\"description\":\"M-code CNC machining: what it controls, M-code vs G-code, complete M-code list, sequence errors, machine compatibility & programming mistakes to avoid.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/M-Code-in-CNC-Machining-800x600-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/wp-content\\\/uploads\\\/2026\\\/06\\\/M-Code-in-CNC-Machining-800x600-1.jpg\",\"width\":800,\"height\":600,\"caption\":\"M-Code in CNC Machining 800x600\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/m-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"M-Code in CNC Machining: What It Does and How to Use It Correctly\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#website\",\"url\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/\",\"name\":\"CNC Machining Shops\",\"description\":\"10+ Years CNC Machining Service Supplier\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#organization\"},\"alternateName\":\"CMS\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#organization\",\"name\":\"CNC Machining Shops\",\"alternateName\":\"CMS\",\"url\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/CMS_Logo_1000x1000.png\",\"contentUrl\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/CMS_Logo_1000x1000.png\",\"width\":800,\"height\":800,\"caption\":\"CNC Machining Shops\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"description\":\"Shenzhen CMS Technology Co., Ltd. is located in Shenzhen, Guangdong, China. It was established in 2012 with a factory area of \u200b\u200b3,000 square meters. It is a company specializing in CNC machining and precision parts manufacturing. We have passed ISO9001, IATF16949, ISO13485 certification and are your trusted partner.\",\"email\":\"info@cncmachiningshops.com\",\"telephone\":\"+8617196430663\",\"legalName\":\"Shenzhen CMS Technology Co., Ltd.\",\"foundingDate\":\"2012-07-22\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"11\",\"maxValue\":\"50\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.cncmachiningshops.com\\\/#\\\/schema\\\/person\\\/2593a2e2de68be71300e10f486236551\",\"name\":\"cncmachiningshops\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/36a63d96ed08f8805561107422de4e83bbf8d1669dbc9655acab534bc3e1ed17?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/36a63d96ed08f8805561107422de4e83bbf8d1669dbc9655acab534bc3e1ed17?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/36a63d96ed08f8805561107422de4e83bbf8d1669dbc9655acab534bc3e1ed17?s=96&d=mm&r=g\",\"caption\":\"cncmachiningshops\"},\"sameAs\":[\"https:\\\/\\\/cncmachiningshops.com\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Le code M dans l'usinage CNC : guide de r\u00e9f\u00e9rence complet","description":"Usinage avec le code M CNC : ce qu'il contr\u00f4le, comparaison entre le code M et le code G, liste compl\u00e8te des codes M, erreurs de s\u00e9quence, compatibilit\u00e9 des machines et erreurs de programmation \u00e0 \u00e9viter.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cncmachiningshops.com\/fr\/m-code\/","og_locale":"fr_FR","og_type":"article","og_title":"M-Code in CNC Machining: What It Does and How to Use It Correctly","og_description":"M-code CNC machining: what it controls, M-code vs G-code, complete M-code list, sequence errors, machine compatibility & programming mistakes to avoid.","og_url":"https:\/\/www.cncmachiningshops.com\/fr\/m-code\/","og_site_name":"CNC Machining Shops","article_published_time":"2026-05-31T05:45:45+00:00","article_modified_time":"2026-07-16T03:31:31+00:00","author":"cncmachiningshops","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"cncmachiningshops","Dur\u00e9e de lecture estim\u00e9e":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#article","isPartOf":{"@id":"https:\/\/www.cncmachiningshops.com\/m-code\/"},"author":{"name":"cncmachiningshops","@id":"https:\/\/www.cncmachiningshops.com\/#\/schema\/person\/2593a2e2de68be71300e10f486236551"},"headline":"M-Code in CNC Machining: What It Does and How to Use It Correctly","datePublished":"2026-05-31T05:45:45+00:00","dateModified":"2026-07-16T03:31:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cncmachiningshops.com\/m-code\/"},"wordCount":2982,"commentCount":0,"publisher":{"@id":"https:\/\/www.cncmachiningshops.com\/#organization"},"image":{"@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#primaryimage"},"thumbnailUrl":"https:\/\/www.cncmachiningshops.com\/wp-content\/uploads\/2026\/06\/M-Code-in-CNC-Machining-800x600-1.jpg","articleSection":["CNC Machining Guide"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cncmachiningshops.com\/m-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cncmachiningshops.com\/m-code\/","url":"https:\/\/www.cncmachiningshops.com\/m-code\/","name":"Le code M dans l'usinage CNC : guide de r\u00e9f\u00e9rence complet","isPartOf":{"@id":"https:\/\/www.cncmachiningshops.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#primaryimage"},"image":{"@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#primaryimage"},"thumbnailUrl":"https:\/\/www.cncmachiningshops.com\/wp-content\/uploads\/2026\/06\/M-Code-in-CNC-Machining-800x600-1.jpg","datePublished":"2026-05-31T05:45:45+00:00","dateModified":"2026-07-16T03:31:31+00:00","description":"Usinage avec le code M CNC : ce qu'il contr\u00f4le, comparaison entre le code M et le code G, liste compl\u00e8te des codes M, erreurs de s\u00e9quence, compatibilit\u00e9 des machines et erreurs de programmation \u00e0 \u00e9viter.","breadcrumb":{"@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cncmachiningshops.com\/m-code\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#primaryimage","url":"https:\/\/www.cncmachiningshops.com\/wp-content\/uploads\/2026\/06\/M-Code-in-CNC-Machining-800x600-1.jpg","contentUrl":"https:\/\/www.cncmachiningshops.com\/wp-content\/uploads\/2026\/06\/M-Code-in-CNC-Machining-800x600-1.jpg","width":800,"height":600,"caption":"M-Code in CNC Machining 800x600"},{"@type":"BreadcrumbList","@id":"https:\/\/www.cncmachiningshops.com\/m-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cncmachiningshops.com\/"},{"@type":"ListItem","position":2,"name":"M-Code in CNC Machining: What It Does and How to Use It Correctly"}]},{"@type":"WebSite","@id":"https:\/\/www.cncmachiningshops.com\/#website","url":"https:\/\/www.cncmachiningshops.com\/","name":"Ateliers d'usinage CNC","description":"Fournisseur de services d'usinage CNC depuis plus de 10 ans","publisher":{"@id":"https:\/\/www.cncmachiningshops.com\/#organization"},"alternateName":"CMS","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cncmachiningshops.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.cncmachiningshops.com\/#organization","name":"Ateliers d'usinage CNC","alternateName":"CMS","url":"https:\/\/www.cncmachiningshops.com\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.cncmachiningshops.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.cncmachiningshops.com\/wp-content\/uploads\/2025\/11\/CMS_Logo_1000x1000.png","contentUrl":"https:\/\/www.cncmachiningshops.com\/wp-content\/uploads\/2025\/11\/CMS_Logo_1000x1000.png","width":800,"height":800,"caption":"CNC Machining Shops"},"image":{"@id":"https:\/\/www.cncmachiningshops.com\/#\/schema\/logo\/image\/"},"description":"La soci\u00e9t\u00e9 Shenzhen CMS Technology Co., Ltd. est implant\u00e9e \u00e0 Shenzhen, dans la province du Guangdong, en Chine. Fond\u00e9e en 2012, elle dispose d'une usine d'une superficie de 3 000 m\u00e8tres carr\u00e9s. Il s'agit d'une entreprise sp\u00e9cialis\u00e9e dans l'usinage CNC et la fabrication de pi\u00e8ces de pr\u00e9cision. Nous sommes certifi\u00e9s ISO 9001, IATF 16949 et ISO 13485, et sommes votre partenaire de confiance.","email":"info@cncmachiningshops.com","telephone":"+8617196430663","legalName":"Shenzhen CMS Technology Co., Ltd.","foundingDate":"2012-07-22","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"11","maxValue":"50"}},{"@type":"Person","@id":"https:\/\/www.cncmachiningshops.com\/#\/schema\/person\/2593a2e2de68be71300e10f486236551","name":"ateliers d&#039;usinage cnc","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/secure.gravatar.com\/avatar\/36a63d96ed08f8805561107422de4e83bbf8d1669dbc9655acab534bc3e1ed17?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/36a63d96ed08f8805561107422de4e83bbf8d1669dbc9655acab534bc3e1ed17?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/36a63d96ed08f8805561107422de4e83bbf8d1669dbc9655acab534bc3e1ed17?s=96&d=mm&r=g","caption":"cncmachiningshops"},"sameAs":["https:\/\/cncmachiningshops.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/posts\/11629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/comments?post=11629"}],"version-history":[{"count":0,"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/posts\/11629\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/media\/11930"}],"wp:attachment":[{"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/media?parent=11629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/categories?post=11629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cncmachiningshops.com\/fr\/wp-json\/wp\/v2\/tags?post=11629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}