---
title: "Can You Put Two M-Codes on the Same Line of G-Code?"
description: "The one-M-per-block rule is the historical default; some controls allow more under conditions. Why the restriction exists, and the rule that is always safe."
url: https://gcodepractice.com/journal/can-you-put-two-m-codes-on-the-same-line/
canonical: https://gcodepractice.com/journal/can-you-put-two-m-codes-on-the-same-line/
author: "Lawrence Arya"
authorUrl: https://www.linkedin.com/in/vibecoding/
published: 2026-06-07
updated: 2026-06-07
category: "Guides"
tags: ["m-codes", "syntax", "blocks", "dialects"]
lang: en
---

# Can You Put Two M-Codes on the Same Line of G-Code?

> **TL;DR** It depends on the control, and the dependable answer is the conservative one: the traditional rule is one M-code per block, some Fanuc-family controls permit multiple M-codes per line when configured for it, LinuxCNC allows several from different modal groups, and hobby firmware varies. The restriction exists because M-codes throw physical switches whose sequencing the control must resolve, two switches on one line forces an ordering decision the block does not express. One M per line is legal everywhere, reads unambiguously, and is what most posts emit.

This question has a dialect answer and a wisdom answer, and they point the same direction. The dialect answer: it depends on the control, with the traditional rule being one M-code per block and various controls relaxing it under defined conditions. The wisdom answer: one M per line is legal on everything ever built, reads unambiguously at 3 a.m., and costs exactly one extra line, which is why it is the convention worth keeping regardless of what your control permits.

## Why M-codes got a quota in the first place

G words mostly configure interpretation; [M words throw switches](https://en.wikipedia.org/wiki/G-code): spindle, coolant, clamps, program flow. A block carrying one switch command has one event to schedule against its motion. A block carrying two forces the control to resolve an ordering the line does not express, does the spindle start before the coolant, simultaneously, after?, and early controls answered the design question by forbidding it: one M per block, order expressed by line order, ambiguity impossible. The restriction was never about parsing difficulty; it was about making physical sequences explicit, the same concern that makes [M8 placement around cycles](/journal/coolant-won-t-turn-on-during-drill-cycle-g-code/) matter.

## The dialect landscape

| World | The rule | The fine print |
| --- | --- | --- |
| Traditional Fanuc-family | One M-code per block | The historical default; programs and habits built on it |
| Fanuc-family, configured | Multiple M-codes per line where enabled | Capability and limits are configuration-dependent: the manual owns it |
| LinuxCNC | Several M-codes per line, different modal groups | Documented in the M-code reference, with group rules |
| Hobby firmware | Varies | The published supported-codes list is the authority |

The [LinuxCNC M-code documentation](https://linuxcnc.org/docs/html/gcode/m-code.html) is the readable public example of the permissive end: multiple M words coexist on a line when they come from different modal groups, because the groups encode exactly the conflicts the one-per-block rule was preventing wholesale. The Fanuc-family middle row is where inherited programs get interesting: a file written for a multiples-enabled machine can alarm, or worse, partially execute, on a machine configured traditionally, one of the [block-structure rules](https://linuxcnc.org/docs/html/gcode/overview.html) that make the same bytes mean different things on different iron.

## The failure modes when it goes wrong

The benign failure is an alarm naming the block: annoying, instantly diagnosable, fixed by splitting the line. The expensive failure is silent partial execution, one M honored, its linemate dropped, which presents later as a process problem: the spindle without coolant, the clamp that never released, a [coolant-in-cycle mystery](/journal/coolant-won-t-turn-on-during-drill-cycle-g-code/) with a perfectly innocent-looking program. Inherited and cross-machine programs carry the risk, which folds this check into the standard first-run read: tool changes and M-dense lines get a glance for exactly this, the same [reading-for-error-species habit](/journal/how-to-read-g-code-to-find-errors/) that catches the rest of the dialect class.

Contradiction pairs deserve their own mention because legality does not rescue them: M03 with M04 on one line is nonsense everywhere, and order-sensitive pairs, spindle and coolant, clamp and move, are precisely where the one-per-line convention stops being style and becomes documentation: separate lines state the order; a shared line hides it behind the control's resolution rules.

## The convention, and why posts already follow it

Watch what CAM posts emit: overwhelmingly, one M per line, sequenced deliberately, spindle started before coolant, both established before the cycle. Post authors write for the union of controls their output might meet, and one-per-line is the form that runs everywhere and reads as a sequence. Hand-written programs inherit the same logic for free by copying it, and the habit costs nothing, lines are no longer rationed by [tape length](/journal/does-g-code-need-spaces-between-letters/). Where you genuinely need a control's multiples feature, production cycle-time tuning on a machine you own, the machine's documentation defines the resolution order, and a comment stating the intent keeps the next reader inside it. The fluency that makes any of these calls quick, knowing the M families and their conflicts on sight, is standard recall material, drilled free in the 60-second rounds on the [G-code practice page](/g-code-practice/).

## Sources

- [LinuxCNC: M-code reference](https://linuxcnc.org/docs/html/gcode/m-code.html)
- [LinuxCNC: G-code overview](https://linuxcnc.org/docs/html/gcode/overview.html)
- [Wikipedia: G-code](https://en.wikipedia.org/wiki/G-code)

## Frequently asked questions

### Can you put two M-codes on the same line in G-code?

On some controls, with conditions: the traditional rule is one M-code per block, some Fanuc-family controls permit multiples when configured for it, LinuxCNC accepts several from different modal groups, and hobby firmware varies. One M per line is legal everywhere and unambiguous.

### Why is there a one-M-code-per-block rule at all?

Because M-codes throw physical switches, and two switch commands on one line force an ordering the line does not express. Early controls forbade the situation; modern ones that allow it define resolution rules in documentation.

### What happens if I put two M-codes on a line where it is not allowed?

Typically an alarm naming the block, or on some setups, silent partial execution, one code honored, the other dropped, surfacing later as a process problem.

### Which M-code combinations are dangerous even where multiples are legal?

Contradictions like M03 with M04, and order-sensitive pairs like spindle with coolant. Where order matters, separate lines make it explicit, which is the deeper argument for the convention.

---

Source: https://gcodepractice.com/journal/can-you-put-two-m-codes-on-the-same-line/
Author: Lawrence Arya — https://www.linkedin.com/in/vibecoding/
