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 (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.

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 is the classic example, and the rest live in the common M-codes for CNC beginners. The full list of machine functions is documented in the LinuxCNC M-code reference.

The two side by side

G-codesM-codes
Letter stands forPreparatoryMiscellaneous / machine
JobHow the machine movesWhat the machine does
ControlsMotion, units, planes, offsets, modesSpindle, coolant, tool change, program flow
ExamplesG00, G01, G02, G20, G54, G90M03, M05, M06, M08, M30
Typically modal?Yes, mostNo, mostly one-shot actions

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. 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:

BlockFamilyWhat it does
G21 G17 G90G-codesSet metric, XY plane, absolute mode
T1 M06T word + M-codeSelect and change to tool 1
S1200 M03S word + M-codeSpindle to 1200 rpm, start it
G00 X0 Y0G-codeRapid to the start point
M30M-codeEnd 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 and in any good code 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, 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

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.