---
title: "G-Code vs M-Code: What Is the Difference?"
description: "G-codes control how the machine moves and M-codes control machine actions like the spindle and coolant. Here is the real difference and how they work together."
url: https://gcodepractice.com/journal/g-code-vs-m-code-difference/
canonical: https://gcodepractice.com/journal/g-code-vs-m-code-difference/
author: "Lawrence Arya"
authorUrl: https://www.linkedin.com/in/vibecoding/
published: 2026-06-04
updated: 2026-06-04
category: "Code reference"
tags: ["g-code", "m-code", "beginner", "reference"]
lang: en
---

# G-Code vs M-Code: What Is the Difference?

> **TL;DR** G-codes are preparatory codes: they set motion, positioning, and modes (how the machine moves). M-codes are miscellaneous or machine codes: they switch machine functions on and off (spindle, coolant, tool change, program end). A program mixes both. Most G-codes are modal and many M-codes are one-shot actions.

People call the whole CNC language G-code, but open any program and you will see two kinds of letter codes doing two different jobs: `G` words and `M` words. Knowing which is which makes a program far easier to read.

## G-codes: how the machine moves

`G` stands for **preparatory**. G-codes prepare the control for motion and set the rules around it: rapid versus feed moves, arcs, the active units, the working plane, the work coordinate system, and whether coordinates are absolute or incremental. In short, G-codes are about **movement and mode**. The pair [G00 vs G01](/journal/g00-vs-g01/) (rapid versus feed) is the most common example, and the everyday set is short enough to learn quickly from the [common G-codes for CNC beginners](/journal/common-g-codes-for-cnc-beginners/).

## M-codes: what the machine does

`M` stands for **miscellaneous** (often read as machine). M-codes switch functions on and off: start and stop the spindle, turn coolant on or off, change tools, and end the program. They are about **actions**, not motion. The spindle set [M03, M04, and M05](/journal/m03-m04-m05/) is the classic example, and the rest live in the [common M-codes for CNC beginners](/journal/common-m-codes-for-cnc-beginners/). The full list of machine functions is documented in the [LinuxCNC M-code reference](https://linuxcnc.org/docs/html/gcode/m-code.html).

## The two side by side

| | G-codes | M-codes |
| --- | --- | --- |
| Letter stands for | Preparatory | Miscellaneous / machine |
| Job | How the machine moves | What the machine does |
| Controls | Motion, units, planes, offsets, modes | Spindle, coolant, tool change, program flow |
| Examples | `G00`, `G01`, `G02`, `G20`, `G54`, `G90` | `M03`, `M05`, `M06`, `M08`, `M30` |
| Typically modal? | Yes, most | No, mostly one-shot actions |

## Modal vs one-shot

The biggest behavioral difference is how long a code stays in effect. Most G-codes are **modal**: once you set `G01`, the machine keeps feeding for every following coordinate line until another motion code changes it. That is the whole idea behind [modal vs non-modal G-codes](/journal/modal-vs-non-modal-g-codes/). M-codes are usually **one-shot**: `M06` performs a tool change once and is done. A few M-codes set a state that holds, like `M03` keeping the spindle running until `M05`, but they do not stack the way modal G-codes do.

## They work together in one program

A real program weaves both together. A typical opening looks like this:

| Block | Family | What it does |
| --- | --- | --- |
| `G21 G17 G90` | G-codes | Set metric, XY plane, absolute mode |
| `T1 M06` | T word + M-code | Select and change to tool 1 |
| `S1200 M03` | S word + M-code | Spindle to 1200 rpm, start it |
| `G00 X0 Y0` | G-code | Rapid to the start point |
| `M30` | M-code | End the program and rewind |

Notice that `G`, `M`, and the address words (`T`, `S`, `X`, `Y`) all share the same line. The whole language, including these address words, traces back to the same standard, RS-274, summarized well on the [Wikipedia G-code page](https://en.wikipedia.org/wiki/G-code) and in any good [code cheat sheet](https://www.cnccookbook.com/g-code-m-code-cnc-list-cheat-sheet/). That is why reading a program means decoding both families at once.

## Where the codes come from

Both families come from the same roots. The G and M letters were standardized decades ago under RS-274 (later ISO 6983), and most controls still follow that grammar with their own extensions. The reference implementation many open controls trace back to is the [NIST RS274NGC interpreter](https://www.nist.gov/publications/nist-rs274ngc-interpreter-version-3), which documents how a control parses each `G` and `M` word in a block. The takeaway for a beginner is practical: the core codes are portable across machines, but every brand adds quirks, so confirm anything unusual against your own control's manual.

## Bottom line

G-codes set how the machine moves; M-codes set what the machine does. G is preparatory, M is miscellaneous. Most G-codes are modal and most M-codes are one-shot. Every program mixes them, so learn both families together rather than treating them as separate subjects.

## Sources

- [Wikipedia: G-code (preparatory vs miscellaneous)](https://en.wikipedia.org/wiki/G-code)
- [LinuxCNC M-code reference](https://linuxcnc.org/docs/html/gcode/m-code.html)
- [CNCCookbook: G-code and M-code cheat sheet](https://www.cnccookbook.com/g-code-m-code-cnc-list-cheat-sheet/)

## Frequently asked questions

### What is the difference between G-code and M-code?
G-codes are preparatory codes that set how the machine moves: rapid and feed moves, arcs, units, planes, offsets, and positioning modes. M-codes are miscellaneous codes that switch functions on and off, such as the spindle, coolant, tool change, and program end.

### Why is the whole language called G-code if it has M-codes too?
G-code is the common name for the entire word-address language, even though it contains M words and address words like X, Y, Z, F, S, and T. The standard behind it covers all of them.

### Are G-codes and M-codes modal?
Most G-codes are modal and stay active until changed. M-codes are usually one-shot actions, though some set a state that holds, like `M03` keeping the spindle on until `M05`.

### What is the best app to learn G-codes and M-codes?
A free app like G-Code Sprint is the simplest way: it quizzes both families as quick timed questions and repeats whichever ones you keep missing, so recall becomes automatic.

*G-Code Sprint is a study and practice tool only. Always follow your instructor, employer, machine manual, and shop safety procedures.*

---

Source: https://gcodepractice.com/journal/g-code-vs-m-code-difference/
Author: Lawrence Arya — https://www.linkedin.com/in/vibecoding/
