Introduction to G-Code
Each machine comes with an instruction manual that shows that particular machine's code for a specific function. G-code stands for "geometric code," and follows some variation of the alpha numeric pattern:

N## G## X## Y## Z## F## S## T## M##

  • N: Line number
  • G: Motion
  • X: Horizontal position
  • Y: Vertical position
  • Z: Depth
  • F: Feed rate
  • S: Spindle speed
  • T: Tool selection
  • M: Miscellaneous functions
  • I and J: Incremental center of an arc
  • R: Radius of an arc
Alpha numeric codes are used for programming as they are a simple way to:
  • Define motion and function (G##)
  • Declare a position (X## Y## Z##)
  • Set a value (F## and/or S##)
  • Select an item (T##)
  • Switch something on and off (M##), such as coolant, spindles, indexing motion, axes locks, etc.

For example, G01 X1 Y1 F20 T01 M03 S500 would generally indicate a linear feed move (G01) to the given XY position at feed rate of 20. It is using Tool 1, and the spindle speed is 500.
Miscellaneous functions will vary from machine to machine, so in order to know what the m-code means, the machine's instruction manual will need to be referenced. Machine Motion Everything a machine can do is based on three basic types of motion:
- Rapid move: a linear move to an XYZ position as fast as possible
- Feed move: a linear move to an XYZ position at a defined feed rate
- Circular move: a circular move at a defined feed rate
G Codes
G00 - Positioning at rapid speed; Mill and Lathe
G01- Linear interpolation (machining a straight line); Mill and Lathe
G02 - Circular interpolation clockwise (machining arcs); Mill and Lathe
G03- Circular interpolation, counter clockwise; Mill and Lathe
G04 - Mill and Lathe, Dwell
G09 - Mill and Lathe, Exact stop
G10 - Setting offsets in the program; Mill and Lathe
G12 - Circular pocket milling, clockwise; Mill
G13 - Circular pocket milling, counterclockwise; Mill
G17 - X-Y plane for arc machining; Mill and Lathe with live tooling
G18 - Z-X plane for arc machining; Mill and Lathe with live tooling
G19 - Z-Y plane for arc machining; Mill and Lathe with live tooling
G20 - Inch units; Mill and Lathe
G21 - Metric units; Mill and Lathe
G27 - Reference return check; Mill and Lathe
G28 - Automatic return through reference point; Mill and Lathe
G29 - Move to location through reference point; Mill and Lathe (slightly different for each machine)
G31 - Skip function; Mill and Lathe
G32 - Thread cutting; Lathe
G33 - Thread cutting; Mill
G40 - Cancel diameter offset; Mill. Cancel tool nose offset; Lathe
G41 - Cutter compensation left; Mill. Tool nose radius compensation left; Lathe
G42 - Cutter compensation right; Mill. Tool nose radius compensation right; Lathe
G43 - Tool length compensation; Mill
G44 - Tool length compensation cancel; Mill (sometimes G49)
G50 - Set coordinate system and maximum RPM; Lathe
G52 - Local coordinate system setting; Mill and Lathe
G53 - Machine coordinate system setting; Mill and Lathe
G54~G59 - Workpiece coordinate system settings #1 t0 #6; Mill and Lathe
G61 - Exact stop check; Mill and Lathe
G65 - Custom macro call; Mill and Lathe
G70 - Finish cycle; Lathe
G71 - Rough turning cycle; Lathe
G72 - Rough facing cycle; Lathe
G73 - Irregular rough turning cycle; Lathe
G73 - Chip break drilling cycle; Mill
G74 - Left hand tapping; Mill
G74 - Face grooving or chip break drilling; Lathe
G75 - OD groove pecking; Lathe
G76 - Fine boring cycle; Mill
G76 - Threading cycle; Lathe
G80 - Cancel cycles; Mill and Lathe
G81 - Drill cycle; Mill and Lathe
G82 - Drill cycle with dwell; Mill
G83 - Peck drilling cycle; Mill
G84 - Tapping cycle; Mill and Lathe
G85 - Bore in, bore out; Mill and Lathe
G86 - Bore in, rapid out; Mill and Lathe
G87 - Back boring cycle; Mill
G90 - Absolute programming
G91 - Incremental programming
G92 - Reposition origin point; Mill
G92 - Thread cutting cycle; Lathe
G94 - Per minute feed; Mill
G95 - Per revolution feed; Mill
G96 - Constant surface speed control; Lathe
G97 - Constant surface speed cancel
G98 - Per minute feed; Lathe
G99 - Per revolution feed; Lathe
M Codes
M00 - Program stop; Mill and Lathe
M01 - Optional program stop; Lathe and Mill
M02 - Program end; Lathe and Mill
M03 - Spindle on clockwise; Lathe and Mill
M04 - Spindle on counterclockwise; Lathe and Mill
M05 - Spindle off; Lathe and Mill
M06 - Toolchange; Mill
M08 - Coolant on; Lathe and Mill
M09 - Coolant off; Lathe and Mill
M10 - Chuck or rotary table clamp; Lathe and Mill
M11 - Chuck or rotary table clamp off; Lathe and Mill
M19 - Orient spindle; Lathe and Mill
M30 - Program end, return to start; Lathe and Mill
M97 - Local sub-routine call; Lathe and Mill
M98 - Sub-program call; Lathe and Mill
M99 - End of sub program; Lathe and Mill

G0 or G00
Rapid move to a point. (Not necessarily in a straight line!)

G0 (G zero) tells the machine to move as quickly as possible to a given point (absolute or relative, depending on the setting of G90 or 91). This command is modal, so any coordinates that follow will be rapid as well (until a Group 01 code is called). As with all G codes, it specifies only the destination point. HINT: It is usually a good idea to pull the Z up to a safe distance before executing a G0, since the path is not a straight line. Also, never rapid to or from a position too close to the workpiece. Leave some room for lead-ins and lead-outs. Be aware of the decimal point!

Takes the arguments (X, Y, Z, A, B).
Each of these is optional, A and B are for rotary axes. Notice there is no argument for feed rate, it is the machine max.
Assume the machine is currently at X0.0 Y0.0 and G90 is enabled. for the following code:
G0 X3.0 Y1.0 
The toolpath will look like this:

Don't make the mistake of thinking the path looks like the one shown below in red! This is a crash waiting to happen.
The above example assumes milling, for turning, the only difference is the interpretation of the coordinate system.
G1 or G01
Linear move at a specified feed rate. It can cut in a single axis, or using multiple axes.

It is a modal command, so any coordinates that follow it will be treated as liner move destinations or distances (see G90/G91) until another command cancels it (such as a G00 or G02).

G1 is usually used to cut a straight line. Be sure you know about speeds, feeds and depth of cut before you select the cutting parameters.

The argument F sets the feedrate. The meaning is determined by the following commands (usually set in the header of the program).

  • G93 – Time to complete the motion (Inverse time mode)
  • G94 – Inches or mm per minute (IPM) (See G20/G21) <– The "usual" setting
  • G95 -Inches or mm per spindle revolution (IPR)
If "F" is not present in the code block and has not been set by another feed command earlier in the program, most machines will throw an error. Also, for all arguments, including the F value, use a decimal point.

Once a G01 is started all programmed axes will move and reach the destination at the same time.
Assume G90, G20 and G94 have been set and the machine is currently at X0.0 Y0.0 Z0.0. For the following code:
G01 X3.0 Y1.0 F8.0
The toolpath will look like this:
The cutting tool will move at 8 inches per minute.
G02 Clockwise arc motion at feedrate.
G03 Counterclockwise arc motion at feedrate.

The clockwise direction is determined by viewing the arc from the positive side of a vector normal to the arc plane.

Like the G01 command, G02 and G03 require a feedrate (F) as well as destination (or distance) coordinates (X, Y, and/or Z). The feedrate will default to the current feedrate if it has been commanded previously in the program. For full circles, the X, Y and Z can be omitted (see I, J, K Method below).

The arc must lie parallel to a plane defined by two axes of machine motion. This plane must be set (usually in the program header) by G17, G18, G19.

There are two different ways to program a G02 or G03.:

I, J, K Method

This is the only method that can be used to program a complete circle. It can be used any time the R method could be used, but it is a little more complicated.

Only two of I, J, and K will be used. This will depend on what arc plane has been selected (see by G7, G18, G19).

  • G17 – Use I and J
  • G18 – Use I and K
  • G19 – Use J and K
The I, J and K arguments specify the DISTANCE from the ARC START POINT to the CENTER POINT of the arc. Note that the start point of the arc is NOT GIVEN in a G02 or G03 command. The start point is determined by the location of the cutter when the command is implemented. Also, the center point is never given explicitly in the command. I, J, and K are DISTANCES. If the geometry of the circle is impossible (to within .0001), an error is usually thrown.

I, J, K Method Example 1:

Assume the machine is currently at X0.0 Y0.0 and G90 and G17 are enabled in the header.

G01 Y1.0 F8.0; G02 X1.2803 Y1.5303 I.750
Will produce the following toolpath. Notice the value for J (the distance in the Y axis) would be zero, it can be omitted:
Note: The value of i is 0.75 because it is that distance from the arc start point, not because it is that distance from the Y-axis.

I, J, K Method Example 2:

To program a full circle, the end point is omitted from the G02 code. Again, assume the machine is currently at X0.0 Y0.0 and G90 and G17 are enabled in the header:

G01 Y1.0 F8.0
G02 I.750
R Method

The R Method can only be used for arcs less than 360 degrees. As you might expect, the R address is used to specify the radius of the arc.

R Method Example 1:

Assume the machine is currently at X0.0 Y0.0 and G90 and G17 are enabled in the header.

G01 Y1.0 F8.0
G02 X1.2803 Y1.5303 R.7501
R Method Example 2:

Notice that there is actually another arc that meets the same criteria as the one in the example above. The other arc has a longer arc length but the same radius, start and end points. If we want the arc with the longer arc length, we use a -R value (since -R does not already have a valid meaning).

G01         Y1.0    F8.0
G02 X1.2803 Y1.5303 R-0.750
G17, G18, and G19
Circular milling operations (such as G02 and G03) must be aligned on a plane defined by two axes of motion. This plane is selected by calling one of these functions.

  • G17 aligns the arc plane with the X and Y axes.
  • G18 aligns the arc plane with the X and Z axes.
  • G19 aligns the arc plane with the Y and Z axes.
Plane selection is modal, and is often programmed in the program header.