Guide
CNC programming languages: G-code, M-codes and controller dialects
What are the CNC programming languages? G-code (ISO 6983), M-codes, Fanuc, Siemens and Heidenhain dialects, woodWOP, Xilog, CAM and post-processors.
Published: 8 min read
A CNC machine does not read drawings; it reads commands, one line at a time. The language those commands are written in is loosely called a CNC programming language. In practice there is no single language: there is a common core (G-code) and on top of it the dialects each controller maker has added. In the furniture and wood router world, some machine builders skip G-code altogether and use their own program formats. This article gives the machine operator and the CAM user the frame they need: what G-code is, what M-codes are, where the dialects split, and why today the code is mostly written by software.
G-code: the common language (ISO 6983 / RS-274)
G-code is the programming language developed for numerically controlled machines and still the foundation today. It is defined in the US as EIA RS-274 (commonly RS-274-D) and internationally as ISO 6983, which is why Europeans often call it "ISO code". A program is made of blocks (lines); each block is built from one or more address + number pairs:
- N: block (line) number — optional.
- G: preparatory command — motion type, plane, units, coordinate system.
- X, Y, Z (A, B, C): target coordinates and rotary axes.
- I, J, K / R: arc centre or radius.
- F: feed rate (usually mm/min), S: spindle speed (rpm).
- T: tool number, D / H: tool radius and length offset registers.
- M: miscellaneous (machine) function — spindle, coolant, tool change, program end.
Most G-codes are modal: once G01 is written it stays active on the following lines until another motion code replaces it. That is why reading a program from the middle can mislead you; to know which modes are active on a given line you have to look further up.
Core G-codes and M-codes at a glance
The codes below mean the same thing on the large majority of milling and router controls. Some still differ by maker and machine type (unit selection is G20/G21 on Fanuc but G70/G71 on Siemens, for example); the final word is always the machine's own programming manual.
| Code | Meaning | Note |
|---|---|---|
| G00 | Rapid positioning | Moves at full speed without cutting |
| G01 | Linear cutting move | Straight line at the feed rate given by F |
| G02 / G03 | Circular move (clockwise / counter-clockwise) | Centre given by I/J/K or R |
| G04 | Dwell | The time address depends on the controller |
| G17 / G18 / G19 | Working plane XY / XZ / YZ | Arcs and compensation are computed in this plane; routers mostly use G17 |
| G20 / G21 | Inch / millimetre (Fanuc style) | G70/G71 on Siemens |
| G28 | Return to reference point | Fanuc style |
| G40 / G41 / G42 | Cutter radius compensation: cancel / left / right | Decide once whether CAM or the control applies it |
| G43 / G49 | Tool length compensation on / cancel | With an H register |
| G54–G59 | Work offsets (part zero points) | Separate zeros for different table stations |
| G80 / G81 / G83 | Cancel cycle / drilling / peck drilling | Canned drilling cycles |
| G90 / G91 | Absolute / incremental coordinates | The most dangerous pair to mix up |
| M03 / M04 / M05 | Spindle clockwise / counter-clockwise / stop | Together with S |
| M06 | Tool change | Magazine behaviour on routers is builder-specific |
| M08 / M09 | Coolant on / off | On wood routers usually dust extraction or unused |
| M00 / M01 | Program stop / optional stop | For operator confirmation |
| M30 | Program end and rewind | M02 on some controls |
A small example: a 100 × 60 mm rectangular contour
The Fanuc-style program below cuts the outside contour of a 100 × 60 mm rectangle to 6 mm depth with cutter radius compensation. Each line is followed by what it does:
- O1000 (RECTANGLE 100X60) — program number and comment
- G21 G17 G90 G40 G80 — millimetres, XY plane, absolute; compensation and cycles cancelled (safe start)
- T1 M06 — load tool 1
- G54 G00 X-10. Y-10. S18000 M03 — first work offset, rapid to the entry point outside the part, spindle on at 18,000 rpm
- G43 H1 Z20. — go to safe height with tool length compensation
- G00 Z5. — approach height
- G01 Z-6. F2000 — plunge to 6 mm depth outside the part
- G41 D1 X0. Y0. F6000 — switch on left compensation and move to the corner (outside contour, climb direction)
- X100. → Y60. → X0. → Y0. — the four sides
- G40 G01 X-10. Y-10. — cancel compensation and move away from the part
- G00 Z20. — retract to safe height
- M05 — stop the spindle
- M30 — end of program
Controller dialects: Fanuc, Siemens, Heidenhain, Osai
The core commands are shared, but every controller maker has extended the language. A program written for one machine generally will not run unchanged on another control; the differences sit mostly in the header, the tool call, the canned cycles and the use of variables.
- Fanuc: one of the most widespread control families; many builders use "Fanuc-compatible" syntax. The example above is in this style.
- Siemens Sinumerik: besides ISO commands it has its own high-level language elements (variables, named cycles such as CYCLE81) and shop-floor conversational interfaces such as ShopMill/ShopTurn.
- Heidenhain: known for its own Klartext (plain-language, conversational) format: lines like L X+100 Y+0 RL F6000 are structured differently from G-code. Most Heidenhain controls can also run ISO programs.
- Osai, Fagor, Mitsubishi, Haas and others: ISO-based, with maker-specific cycles and M-codes. Osai and Asian controls (such as LNC and Syntec) are common on smaller wood routers.
The furniture router side: woodWOP, Biesse and Xilog
On the big-brand panel processing machines the operator often never sees G-code. The builder's software uses its own program format that stores operations as macro blocks:
| Machine / software | Program format | Structure |
|---|---|---|
| Homag / Weeke — woodWOP | .mpr | Part size, variables and operation blocks (contour, drilling, grooving) |
| Biesse — BiesseWorks / bSolid | .bpp, .cix | The builder's own operation and variable structure |
| SCM — Xilog / Maestro | .xxl, .pgm | Xilog language; drilling and routing macros |
| Generic routers | .nc, .iso, .tap etc. | Plain G-code |
What these formats share is that they are parametric: part length and width are held as variables and holes are positioned from them. Extensions and syntax depend on the machine software release.
Manual programming or CAM?
A plain rectangle or a handful of holes can be typed in at the machine. As jobs grow more complex, manual programming quickly hits its limits:
| Manual programming | CAM-generated | |
|---|---|---|
| Suitable for | Simple contours, hole patterns, a single repeating part | Free curves, decorative doors, nesting, 3D surfaces |
| Speed | Quick for short programs, very slow for long ones | Minutes once the drawing exists |
| Error risk | A typo goes straight to the machine | Seen beforehand in simulation |
| Changes | Edited line by line | Change the drawing, regenerate the code |
| Know-how needed | Deep knowledge of the control | CAM software plus the right post |
The realistic picture in a furniture shop: the operator should be able to read G-code (to diagnose an error or check the zero point), but the code is written by CAM software. For how CAM packages are categorised see Types of CAM software: by process, axes, integration and industry; for where Alphacam fits in the chain see What is Alphacam? A CAD/CAM guide for furniture and wood CNC.
The post-processor: translator between CAM and language
CAM software computes the toolpath in a machine-independent internal form. Whether that path becomes Fanuc-style G-code, Heidenhain Klartext or a woodWOP .mpr file is decided by the post-processor. So the answer to "which language are we speaking" lives in the post: the same drawing can output for different machines just by choosing a different post.
- It writes the program header and footer (units, plane, safe height).
- It issues the tool change in the command the control expects.
- It turns holes into G81/G83 cycles or the builder's drilling block.
- It decides whether compensation happens in CAM or in the control — with both on, the tool is offset twice.
Choosing a post, testing it and the common mistakes are covered separately: What is an Alphacam post-processor? Producing NC code for your machine.
Parametric and macro programming
Plain G-code works with fixed numbers. Controllers add variables, arithmetic, conditions and loops on top to allow parametric programming. The best-known example is Fanuc's Custom Macro B: numbered variables such as #100, IF [...] GOTO conditions, WHILE [...] DO loops and sub-program calls with G65. Siemens R parameters and user variables, and Heidenhain Q parameters, do the same job. Furniture machine formats such as woodWOP and Xilog also keep part dimensions as variables.
A parametric program lets you write one program that "cuts the door once width and height are given" — but the logic lives inside the machine, tied to that control's language. The CAM-side equivalent is the parametric drawing macro: it takes the dimensions, builds the geometry in the CAM program, and the post still writes the NC code, so the same macro works on every machine. How such macros work in Alphacam: How Alphacam-based parametric door and cabinet door macros work.
CNC programming with Alphacam Router
In a furniture shop running Alphacam Router the flow is: draw the door or cabinet part (or import a DXF), assign operations (by hand or with Auto Style), check them in simulation, and let the chosen post write the file in the machine's language. The operator's job is not to memorise the language but to read and verify the output's header, zero point and tool call. Most of the time goes into drawing — and that is the step GMacros macros speed up inside Alphacam Router: they draw door, panel and cabinet parts from dimensions while your own post still produces the code. See the packages on the products page.
Frequently asked
Which language should I learn to program CNC machines?
Start with the core of ISO G-code (G00–G03, G17, G40–G42, G54, G90/G91 and the basic M-codes); it underlies every dialect. Then study the differences listed in your controller's manual.
What is the difference between G-code and M-code?
G-codes define motion and geometry (linear, circular, plane, coordinate system); M-codes control the machine's auxiliary functions (spindle, coolant, tool change, program end).
Do Homag or Biesse machines use G-code?
Operators usually work in the builder's own format (woodWOP .mpr, Biesse .bpp/.cix). CAM software can produce that format directly with the right post.
Do I need to know G-code if I use CAM?
You do not need to write it, but you should be able to read it: checking units, absolute/incremental mode, zero point and tool call lets you catch a bad program before it reaches the machine.
Related products
Tools that do the work described here with one click inside Alphacam: the GMacros add-in and macro packages. Purchasing and licensing are explained on How it works.
Written by the GMacros team. Alphacam is a registered trademark of Hexagon AB; this guide is independent.