Reference
G-code quick reference
Fanuc-style words. Haas, LinuxCNC, Mach, Grbl, and Siemens agree on many of these and disagree on others. The control manual wins.
G28 Z0 in absolute mode can crash the tool. G28 goes to the point you name, then to the machine home. In G90, Z0 is usually the top of the part. The usual safe pattern is G91 G28 Z0, then G90.
Motion, units, and distance
| Code | Meaning |
|---|---|
| G00 | Rapid. Not a straight line you can trust between points on every control. |
| G01 | Straight feed. Needs a feedrate (F). |
| G02 / G03 | Arc clockwise / counterclockwise. Plane and the IJK or R word decide the center. |
| G17 / G18 / G19 | Plane XY / XZ / YZ. Arcs and comp live in the active plane. |
| G20 / G21 | Inch / millimeter. Put it near the top of the program and leave it. |
| G90 / G91 | Absolute / incremental. G91 left on is how a drill walks off the part. |
| G94 / G95 | Feed per minute / feed per revolution. Lathes often want G95. |
| G54–G59 | Work coordinate offsets. The numbers in the program are relative to the active one. |
G41 and G42 cutter compensation
G41 offsets the tool to the left of the programmed path. G42 offsets it to the right. "Left" and "right" are as you look in the direction of travel.
With a right-hand cutter, climb milling an outside profile is usually G41, and conventional milling is usually G42. An inside profile flips that. Draw the arrow. Do not memorize the letter.
- The lead-in line has to be longer than the tool radius or the control alarms, or worse, it takes a shortcut.
- Cancel with G40 on a lead-out, not while the flute is buried.
- Some controls treat the D value as a radius, some as a diameter. Check the offset page before the first part.
- A wear offset of zero on a new program is a good way to cut the part undersize or into the fixture. Dry-run above the work in single block.
Tool length, drilling, and M codes
| Code | Meaning |
|---|---|
| G43 Hn | Apply tool length offset n. G49 cancels it. |
| G40 | Cancel cutter compensation. |
| G80 | Cancel a canned cycle. Leave it on and the next G00 becomes a drill. |
| G81 | Simple drill cycle. |
| G83 | Peck drill. Use it when chips pack the hole. |
| G84 | Tapping cycle. The spindle has to reverse in sync with the feed. A rigid tap and a floating holder are not the same setup. |
| M03 / M04 / M05 | Spindle clockwise / counterclockwise / stop. |
| M06 | Tool change. Many machines want the spindle stopped and the Z retracted first. |
| M08 / M09 | Coolant on / off. |
| M30 | End program and rewind. |
A face pass, as an example only
Do not run this. It shows the order: safe start, offset, length comp, a feed move, then a G91 G28 home.
O1000 (EXAMPLE ONLY — FACE PASS)
G17 G20 G40 G49 G80 G90
G54
T1 M06 (1/2 IN FLAT ENDMILL)
G00 G90 G54 X-0.35 Y0.25 S4000 M03
G43 H01 Z1.0 M08
G00 Z0.1
G01 Z-0.02 F15.
G01 X2.35 F30.
G00 Z1.0 M09
M05
G91 G28 Z0
G90
M30
0.02 in is 0.51 mm. 30 in/min is 762 mm/min. Whether 4000 RPM is right depends on the diameter and the material — see the feeds and speeds page, then the tool catalog.
Gear tooth programs and hob data are a different problem. Calculations belong on gearcalculators.com. A gear you need cut belongs at Evolvent Design.