FAQ about G-Code

 Our FAQ about M-Code page is here.

Specific G-Code Command Information


What is G-Code?

G-Code is the industry standard programming language used for CNC equipment. It is stored in a text file, and run line by line.

Here is a good article by MachMotion about Mach3 and Mach4's use of G-Codes.  Consider it required reading.

Here is another MachMotion manual documenting G-Codes and M-Codes in Mach3.

Here is another MachMotion manual documenting G-Codes and M-Codes in Mach4

Here is a GE Fanuc manual that goes into great detail about the different G-Codes (starting on p.31).  It is a 819 page operator's manual, so it is a deep pool of knowledge.  While the information contained in this manual may or may not apply to your system, it is still a useful point of reference. 

Here is the Wikipedia article, about G-Code and M-Code. Not all information in this Wikipedia article is implemented Mach3 or Mach4.

A simple command that you can type into the input line of the MDI screen is "F10 G1 X1"

  • With the F10 command we are manually defining the feedrate to be 10 inches per minute (or mm per minute if your system is set to mm).  A value of 20 would advance the tool twice as fast.  [If this was a rotational axis, the feedrate would be inches per revolution or mm per rev.]
  • G1 will command a linear move, or a straight line move for the current position to the end position.  We are only specifying X1, which would be 1 inch (or mm) on the X axis, and the other axes would maintain their current position.  We could also specify the other axes to have positions also by doing this: "F10 G1 X1.0 Y0.5 Z2.325" The allowable axes are X, Y, Z, A, B and C.




Where can I learn more about General G-Code commands?

A really good course/tutorial is here, by CNC Cookbook.  This is the intro page, and at the bottom is a table of contents.  There is a lot to read and learn!



What can I do to prevent mistakes that waste material?

There are multiple things you can do to prevent mistakes that waste material:

  1. Air cut!  Run your machine without a tool, or without material.  You will be 'cutting air' but this will help you become comfortable with your equipment.  Another option it to use a marker instead of a bit, and watch the shape that it traces.
  2. Look at your tool path and make sure it looks correct.  If things don't look right in the tool path, they probably won't look right after cutting.
  3. Understand the setting in your CAD/CAM processor (Computer Aided Design / Manufacturing software).  There are many options and settings that will impact your file creation.
  4. Set up each of your jobs consistently.  That means that the start of EACH AND EVERY G-Code file should include these commands:
    • G20 to use inches (imperial mode) or G21 for mm (metric mode) for length units. 
    • G90 is used for absolute distance mode (coordinates represent absolute positions relative to the origin (0,0,0).    G91 is used for incremental distance mode, or how far you should move from the current position.
    • Home your machine each and every time you start it, and every time after your press the EStop button.  Also home any time you think you may have lost your current position.
    • If you need to pause your machine, press the Feed hold button, and the the Stop button in Mach.  This will preserve your current position.


I keep getting weird (crop) circles instead of arcs

This is likely due to your IJ mode being in Absolute instead of Inc.   In Mach3, go to Mach3 -> Menu -> Config -> General Config...

IJ Mode



This will explain the following G-Codes in depth:

G90 is used for absolute distance mode (coordinates represent absolute positions relative to the origin (0,0,0).    G91 is used for incremental distance mode, or how far you should move from the current position.  (BLUE arrow in the picture.) 

G90.1 is for Absolute Arc (IJK) mode.  G91.1 is used for Incremental Arc (IJK) mode.  (GREEN arrow in the picture.)   These are similar, but represent the motion moves differently.  Which one you will be working with depends on how your CAD/CAM processor is setup.

Your G2 CW Arc commands (Clockwise circular/helical interpolation)  and G3 CCW Arc commands (Counterclockwise circular/Helical interpolation) will be generated by your CAM software in regards to the expected modes (G90/G91 and G90.1 and G91.1).

Here is a good article explaining the basics of circular arcs.




G10 and G11 - Programmable Data Input Mode -OR- Parameter Entry Mode -OR- Fixture and Tool Offset Setting -OR- Coordinate System Origin Setting

There is the G10  Programmable Data Input Mode, which uses G10 (start data input mode) and G11 (end or cancel data input mode).  If you use a G10, you will need to close it out with a G11 in Mach4 (although it was not required in Mach3). 

In Mach4, you cannot set parameters (L50) in G10 mode (although it may be added by Mach sometime after July 2017).  If you wish to do this, you should set the #vars (in the Mach4 register) directly.

L2   - Fixture offsets G54-G59 Define P1-P6
L20 - Fixture offsets g54.1 P01 thru P300
L10 - Geometry offsets (length and radius compensation)
L11 - Wear offsets (length and radius compensation)
L50 - Parameter entry

Here is one example:

G10 L2 P1 X0.350 Y0.50
G10 L2 P2 X0.725 Y1.50
G10 L2 P3 X24.975 Y1.50
G10 L2 P4 X0.725 Y19.0
G10 L2 P5 X0.725 Y13.5
G10 L2 P6 X0.725 Y8.0
G10 L2 P7 X0.725 Y2.5
G10 L2 P8 X24.975 Y19.0
G10 L2 P9 X24.975 Y13.5
G10 L2 P10 X24.975 Y8.0
G10 L2 P11 X24.975 Y2.5

%%COPY1 First 55 Left

 However, since G10 is modal, you can write it much cleaner like this:

G10 L2 P1 X0.350 Y0.50
L2 P2 X0.725 Y1.50
L2 P3 X24.975 Y1.50
L2 P4 X0.725 Y19.0
L2 P5 X0.725 Y13.5
L2 P6 X0.725 Y8.0
L2 P7 X0.725 Y2.5
L2 P8 X24.975 Y19.0
L2 P9 X24.975 Y13.5
L2 P10 X24.975 Y8.0
L2 P11 X24.975 Y2.5

%%COPY1 First 55 Left




G31 or G31.x (G31.0, G31.1, G31.2 or G31.3) - Probing -OR- Skip Function

The format is G31 X-0.5 F10.  You may use the X, Y, Z or A (U) axis and provide and endpoint for that axis.  You may assign any Feed Rate you wish, otherwise the last commanded Feed Rate will be used (which could be a disaster).  The probing command will be executed until a probe strike occurs or the allotted distance is traveled.

In Mach3 you may only use G31 (assuming you have that probe enabled and configured). 

In Mach4 you may use G31, G31.0, G31.1, G31.2 or G31.3 (assuming you have those probes enabled and configured).G31 and G31.0 are for Probe0, G31.1 is for Probe1, G31.2 is for Probe2 and G31.3 is for Probe3.

In Mach4 when a probing operation completes (or fails) the current positions are then recorded into the following Mach4 Registers (Variables):

Probing Result Work Coordinates Variables Machine Coordinates Variables

X Axis

5061 5071
Y Axis 5062 5072
Z Axis 5063 5073
A (U) Axis 5064 5074
B (V) Axis 5065 5075
C (W) Axis 5066 5076


Go to top