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

Common preparatory codes
CodeMeaning
G00Rapid. Not a straight line you can trust between points on every control.
G01Straight feed. Needs a feedrate (F).
G02 / G03Arc clockwise / counterclockwise. Plane and the IJK or R word decide the center.
G17 / G18 / G19Plane XY / XZ / YZ. Arcs and comp live in the active plane.
G20 / G21Inch / millimeter. Put it near the top of the program and leave it.
G90 / G91Absolute / incremental. G91 left on is how a drill walks off the part.
G94 / G95Feed per minute / feed per revolution. Lathes often want G95.
G54–G59Work 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.

Tool length, drilling, and M codes

Length comp, cycles, and a few M words
CodeMeaning
G43 HnApply tool length offset n. G49 cancels it.
G40Cancel cutter compensation.
G80Cancel a canned cycle. Leave it on and the next G00 becomes a drill.
G81Simple drill cycle.
G83Peck drill. Use it when chips pack the hole.
G84Tapping 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 / M05Spindle clockwise / counterclockwise / stop.
M06Tool change. Many machines want the spindle stopped and the Z retracted first.
M08 / M09Coolant on / off.
M30End 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.