CNC Machine S Language Definition: How the Controller Reads Your Code
A CNC machine s language definition starts with one idea: the control reads a program as a list of addressed words, not as English. This page explains how addresses, G codes, M codes and modal state fit together, so you can tell why a posted program behaves the way it does.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
The CNC machine s language definition in one paragraph
Programs are written in a word-address format that grew out of RS-274, later standardized as ISO 6983. Each word is one letter plus a number: G01, X25.4, F250, S8000, T07. The control parses the line left to right, assigns each letter to a register, then executes the block as a single motion command.
The letter is the address, and the address decides what the number means. X is always a position on the X axis, F is always feed, S is always spindle speed. Change the letter and the same digits mean something else. That is the whole trick of the language: a small alphabet, reused for many purposes.
Blocks are separated by an end-of-block character, usually a semicolon or a line feed depending on the control. Some controls accept multiple commands per block, some only one motion per line. A program that runs on a Fanuc-style mill may throw a format error on a Heidenhain or Siemens control without a post edit.
This is why the definition matters at the machine, not just in a manual. When an operator sees an alarm on line N340, they are not reading a sentence. They are reading a register map, and the fix is almost always a wrong address or a wrong modal state.
What each address letter controls
G sets the mode: rapid, feed, arc, canned cycle, coordinate system. M sets a machine function: spindle on, coolant on, tool change, program end. Together G and M carry most of the logic. The rest of the alphabet carries the numbers that logic acts on.
X, Y and Z give the target point in the active work coordinate system. I, J and K give arc center offsets or the depth of a canned cycle, depending on the G code that is active. R gives a retract plane or an arc radius. U, V and W are usually incremental moves on the same axes.
F is feed rate, either per minute (G94) or per revolution (G95). S is spindle speed in rpm, or surface speed when constant surface speed is active with G96. T selects a tool, and on a lathe it often selects the offset as well. N is only a line number. It has no motion meaning at all.
D and H pick a tool radius or length offset from the offset table. P and Q appear in subprogram calls, dwell times and canned cycle parameters. The same letters change meaning across controls, so always check the control manual for your specific machine before you trust a post.
Modal state, default values and why a program drifts
Most G codes are modal. They stay active until another code in the same group replaces them. G01 stays active until G00, G02 or G03 is called. That is efficient, but it also means a missing G code inherits whatever ran before it.
Modal groups are the guard rail. A control will reject two G codes from the same group in one block, because it cannot execute both. Feed modes, plane selection, units and distance mode each live in their own group. If you mix groups, you get an alarm, not a silent error.
Units are the most common trap. G20 is inches, G21 is millimeters. A program posted in inches and run in millimeter mode moves 25.4 times farther than intended. On a part with a ±0.005 mm tolerance, that is a crash, not a scrap part.
Power-on defaults are the second trap. After a reset, the control returns to a default set: usually G00, G17, G21 or G20, G40, G49, G80, G90. If the program assumes a different state and does not state it explicitly, the first few blocks run in the wrong mode. Always declare units, plane and distance mode near the top.
Where a CNC machine s language definition stops being universal
There is no single CNC language. ISO 6983 defines the word structure, not the full vocabulary. Fanuc, Siemens, Heidenhain, Mitsubishi, Mazak and Haas all implement overlapping but different code sets. A G code that means drill cycle on one control may mean something else or nothing on another.
Fanuc-style controls are the closest thing to a common baseline, and most posts default to that dialect. Siemens ShopMill and Sinumerik use more cycle calls and named parameters. Heidenhain uses plain-text conversational blocks that look nothing like G code. Mazak Smooth and Haas have their own extensions.
Macros widen the gap. Fanuc custom macro B, Siemens R parameters and Okuma variables let a programmer write loops and arithmetic inside the program. That is powerful for families of parts, and it also means the program cannot be moved to another control without a rewrite.
The practical rule: treat the post processor and the control manual as one unit. A program is only portable as far as the two agree. When a job moves between our 5-axis centers and a customer's own machine, we post for the target control, not for the one that produced the model.
How the language shows up on the shop floor
The vocabulary on the floor is shorthand for what the program does. A canned cycle is a G81, G83 or G84 block that repeats a drilling or tapping pattern. A subprogram is an M98 call to a stored routine. A macro is a variable-driven block that calculates its own numbers.
A tool offset is the D or H value that tells the control where the cutting edge actually sits. Touch-off is the moment the tool is jogged down until it just contacts the workpiece or a gauge block, and that point becomes the zero reference. Get it wrong and every dimension shifts by the same error.
A crash is any unplanned contact between tool, holder, workpiece or fixture. The cost is not only the tool. It is the spindle, the fixture and the schedule. Simulation before the first run is cheap compared with a broken holder on a 5-axis job.
Dry run with the tool clear of the part, single block, and a raised rapid plane catch most of these problems before the spindle turns. None of it replaces reading the code. The control does exactly what the words say, including the mistakes.
Address letters and what they carry
Common meanings across Fanuc-style controls. Check your own manual for dialect differences.
| Address | Carries | Typical example |
|---|---|---|
| G | Motion mode and cycle selection | G01, G81, G84 |
| M | Machine on/off functions | M03, M08, M30 |
| X Y Z | Target point in active work offset | X25.4 Y0 Z-3.0 |
| I J K | Arc center or cycle depth | I10.0 J0 K-2.5 |
| R | Retract plane or arc radius | R2.0 |
| F | Feed rate per minute or per rev | F250 or F0.15 |
| S | Spindle speed in rpm | S8000 |
| T | Tool number, sometimes offset | T07 |
| H D | Length or radius offset number | H07 D07 |
| N | Line number, no motion meaning | N340 |
When to read the code and when to trust the post
If the program runs on one control and one machine, trust the post and verify the first part. If it moves to a different control, a lathe, or a macro-heavy family of parts, read the blocks yourself before the first rapid move. The code is the only contract the control honors.
Questions engineers ask about CNC code
Is G code the same as ISO 6983?
ISO 6983 defines the word-address structure and a core set of codes. G code is the common name for programs written in that structure. Real controls add, drop or redefine codes, so two machines can both run G code and still not run each other's programs.
Why does my program alarm on one machine and run on another?
Different modal groups, different cycle syntax, or a code that does not exist on that control. Siemens and Heidenhain handle cycles and parameters differently from Fanuc-style controls. Re-post for the target control and check the alarm line against the manual.
Do I need to learn macro programming?
Not for one-off parts. Macros pay off when you machine families of similar parts with changing dimensions, or when you need in-program math and logic. They also lock the program to one control family, so weigh the portability cost.
What does modal mean in practice?
A modal code stays active until another code in the same group replaces it. That is why a missing G01 can leave the machine in rapid, and why units and plane selection should be declared at the top of every program rather than assumed.
How tight can the language hold a tolerance?
The language carries the numbers, not the accuracy. On our 5-axis centers we hold ±0.005 mm and finishes of Ra 0.2–0.8 μm when the geometry and material allow it. The control, the tool and the setup set the real limit.
Can you program from a customer's existing G code?
Yes, if the drawing and the target control are clear. We re-post to our machines, simulate the toolpath, and flag any block that depends on a control-specific function before the first cut.
Send us your drawing and your control
We review the geometry, post to the right dialect, and quote with a free DFM analysis within 12 hours.
12-hour quote100% inspectionNDA on request