FAQ about G-Code

 Our FAQ about M-Code page is here.

Weird behavior with G-Code


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 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.




Go to top