G-code reference
The common G and M codes for mills and lathes, in our own words. Codes whose meaning or format changes from one control to another are marked Control-specific. Your machine’s own manual always wins.
Each code below has been checked against at least two public sources (listed in the last column and at the bottom of the page). We have left out codes we could not confirm in two places, and the many maker-specific codes (pocketing cycles, probing, bolt-hole cycles and so on).
| Code | What it does | Watch out for | Checked against |
|---|---|---|---|
| G0 | Move at the machine’s full rapid rate to the given point. Not for cutting. | Plan rapid moves well clear of the work and clamps. | LinuxCNC, Grbl, Haas |
| G1 | Straight-line cutting move at the current feed rate F. | LinuxCNC, Grbl, Haas | |
| G2 / G3 | Arc clockwise (G2) or anticlockwise (G3), looking down on the active plane from its positive side. Give the end point and either the centre (I, J, K) or a radius (R). Adding a move on the third axis makes a helix. | By default I/J/K are distances from the arc’s start point. Radius-format arcs are unreliable near a half or full circle; centre format is safer. | LinuxCNC, Grbl, Haas |
| G4 | Dwell: pause for a set time. | Control-specific The unit of the time word (seconds or milliseconds, and whether a decimal point is allowed) varies by control. | LinuxCNC, Grbl, Haas |
| G17 / G18 / G19 | Choose the plane for arcs and compensation: XY, XZ or YZ. Lathes normally work in G18. | LinuxCNC, Grbl, Haas | |
| G20 / G21 | Program in inches (G20) or millimetres (G21). | Put it at the start of every program, before any moves. | LinuxCNC, Grbl, Haas |
| G28 | Go to a reference position, usually through any intermediate point given on the same line. | Control-specific What the reference position is, and whether the intermediate point is used, depends on the control and its settings. | LinuxCNC, Grbl, Haas |
| G40 | Cancel cutter (or tool nose) radius compensation. | LinuxCNC, Grbl, Haas | |
| G41 / G42 | Cutter radius compensation with the tool to the left (G41) or right (G42) of the path, looking along the direction of travel. On lathes the same codes are tool nose compensation. | Control-specific Lead-in rules, how the radius is called up and tip direction settings vary. Some hobby controls (for example Grbl) do not have G41/G42. | LinuxCNC, Haas |
| G43 | Apply a tool length offset, normally with an H number. | Control-specific Grbl uses its own G43.1 form instead. | LinuxCNC, Haas |
| G49 | Cancel tool length offset. | LinuxCNC, Grbl, Haas | |
| G53 | Move in machine coordinates for this line only. | LinuxCNC, Grbl, Haas | |
| G54 to G59 | Select one of six work offsets (work coordinate systems). | LinuxCNC, Grbl, Haas | |
| G76 | A multi-pass lathe threading cycle. | Control-specific The format varies a lot: a two-block form on many Fanuc-style lathes, a one-block form on others (for example Haas and LinuxCNC), with different letters and meanings. On some mills G76 is a fine boring cycle instead. | LinuxCNC, Haas, Tutorials |
| G80 | Cancel a canned (drilling) cycle. | LinuxCNC, Grbl, Haas | |
| G81 | Drilling cycle: rapid to R, feed to Z, rapid back out. | Control-specific Not available on Grbl. | LinuxCNC, Haas |
| G82 | As G81 with a dwell at the bottom. | Control-specific Dwell units vary, as for G4. Not available on Grbl. | LinuxCNC, Haas |
| G83 | Peck drilling: feeds down in steps of Q, retracting between pecks to clear chips. | Control-specific How far it retracts between pecks varies by control and settings. Not available on Grbl. | LinuxCNC, Haas |
| G90 / G91 | Absolute (G90) or incremental (G91) positions on mills and most routers. | Control-specific On many Fanuc-style and Haas lathes, G90 is a turning cycle instead and incremental moves use U and W. | LinuxCNC, Grbl, Haas |
| G94 / G95 | Feed per minute (G94) or per revolution (G95) on mills. | Control-specific On many Fanuc-style and Haas lathes, G94 is a facing cycle and feed modes are G98/G99. | LinuxCNC, Grbl, Haas |
| G96 / G97 | Constant surface speed on (G96) or off, so S is rev/min (G97). Mainly used on lathes. | Control-specific Set a maximum spindle speed before using G96. How the limit is set varies by control. | LinuxCNC, Haas |
| G98 / G99 | On mills: after a drilling cycle return to the start height (G98) or only to the R plane (G99). | Control-specific On many Fanuc-style and Haas lathes, G98 and G99 mean feed per minute and feed per revolution. | LinuxCNC, Haas |
| M0 / M1 | Program stop (M0); optional stop that only acts when the operator has it switched on (M1). | LinuxCNC, Grbl, Haas | |
| M2 / M30 | End of program. On many controls M30 also resets the program to the start. | LinuxCNC, Grbl, Haas | |
| M3 / M4 / M5 | Spindle forwards (clockwise), reverse (anticlockwise) and stop, at speed S. | LinuxCNC, Grbl, Haas | |
| M6 | Tool change to the tool chosen with T. | Control-specific Lathes with turrets often change tool with the T word alone. | LinuxCNC, Haas |
| M7 / M8 / M9 | Coolant: M8 flood on, M9 all coolant off. M7 is a second coolant output. | Control-specific What M7 drives (mist, shower or something else) varies by machine. | LinuxCNC, Grbl, Haas |
Words used with the codes
X, Y, Z are positions. I, J, K are arc centre distances. R is an arc radius or, in a drilling cycle, the height the feed starts from. F is the feed rate, S the spindle speed, T the tool, H a length offset number and P and Q are used for dwell times, peck depths and cycle settings. A word in brackets ( ) is a comment.
Sources
We read these public pages for facts only (checked 25/10/2026). No wording, tables or examples were copied from them.
- LinuxCNC: the G-code and M-code reference pages in the LinuxCNC documentation, linuxcnc.org/docs.
- Grbl: the Grbl v1.1 commands page on the project’s GitHub wiki.
- Haas: the public mill G-code, lathe G-code and mill M-code lists and the lathe G76 page on haascnc.com.
- Tutorials: the public two-block G76 explanations on gcodetutor.com and cncprogramminghub.com, for the Fanuc-style two-block format.
Codes are general reference only and are not an official description of any control. See the terms of use.
FANUC, Haas, Siemens, Heidenhain, LinuxCNC and Grbl are names or trademarks of their respective owners. They are mentioned only to describe which controls a code format relates to. Lathe Calculator is not affiliated with or endorsed by any of them. Trademarks.
Try the G-code viewer or the generators for bolt holes, helical boring, thread milling and G76 threading.