Milling know-how
What is G-code? CNC basics for beginners
In short: G-code is the machine language of CNC routers, lasers and 3D printers. Every line is one command: move to position X/Y/Z, at feed rate F, spindle on at speed S. The controller executes the file line by line — there is no more magic to it.
G-code is rarely written by hand today. A CAM program or a generator like step2gcode creates it from the CAD geometry. Being able to read it is still worthwhile: if you know the most important commands, you spot mistakes before the machine executes them.
Compare two G-code revisions: to the diff viewer →
How to read your first G-code file
- Open the file in a text editor — G-code is plain text, usually with the extension .nc, .gcode or .tap.
- Look at the header: it sets units (G21 = millimetres), absolute positioning (G90) and the spindle start (M3 with speed S).
- Find the rapids: G0 moves at maximum speed without material contact, typically at a safe height.
- Follow the cutting moves: G1 mills in straight lines at feed rate F, G2 and G3 travel along arcs.
- Check the end: M5 stops the spindle, then the machine retracts and the program ends (M2 or M30).
The most important commands at a glance
With these eight commands you can already understand most G-code files:
| Command | Meaning |
|---|---|
| G0 | Rapid move: fast positioning without material contact |
| G1 | Cutting move: straight milling motion at feed rate |
| G2 / G3 | Arc clockwise / counter-clockwise |
| G21 | Units in millimetres (G20 would be inches) |
| G90 | Absolute positioning: coordinates refer to the origin |
| M3 / M5 | Spindle on (at speed S) / spindle off |
| F | Feed rate in mm/min |
| S | Spindle speed in rpm |
Why dialects exist
Almost all controllers understand the core commands the same way. The differences are in the details: program start and end, tool changes, comment syntax and special functions. GRBL, Mach3 and LinuxCNC therefore expect slightly different files — in the generator you simply pick the matching post-processor.
Do I need to write G-code myself?
No. CAM programs and generators handle the creation; at most, small special programs such as warm-up cycles are written by hand. Being able to read and roughly check it, however, is invaluable: a look at the header, the depths (Z values) and the feed rates (F values) tells you whether the program matches your workpiece.