What Is G-Code?

G-code is the language of CNC machines. Its series of lines filled with letters and numbers direct the exact movements of a CNC machine, from moving the tool towards the material for the very first time to creating surface finishes. In this article, you will learn exactly how G-code is created, what it does, and why it’s important.

What does G-code stand for?

The term G-code is most commonly used to describe a series of different types of code, each with a specific function:

  • G: general machine motion
  • M: miscellaneous machine action
  • F: feeds
  • S: spindle speeds
  • T: tools

The “G” commands are used most often, and so the name G-code came to be used for all commands.

How does G-code work?

G-code directs every little machine motion and setting before and during machining. Before any cutting even takes place, G-code is controlling how the tool moves towards the material, how fast it is spinning, and which tool is on the tool holder. When G-code is created, it is done in long lines of code organized into blocks. Each line directs one action, like S500 would set the spindle speed to 500 revolutions per minute. Lines are organized into blocks, which each direct one full machining operation. These blocks are demarcated by labels like N02, N04, etc. to help keep everything organized. Series of blocks take a machine through every step of machining until a finished part is ready to be taken off.

G-code examples

Let’s look at some of the simplest and most common G-code commands.

G00 – Rapid Travel

This is the most basic G-code command, because it merely directs the tool to move quickly through open space. The tool is not engaged with the material during this command. G00 is most often used when bringing the tool close to the material to begin cutting or when returning to home to switch out tools. The full code will include the axis of travel and length of travel, ie: G00 Y80 would direct the tool to travel 80 units (often millimeters) up the Y-axis.

G01 – Linear Interpolation

Linear interpolation controls the tool cutting in a straight line. During the G01 command, the tool is rotating and engaged with the material. A command of G01 X-20 would send the cutting tool 20 units to the left, along the X-axis.

G02 and G03 – Circular Interpolation

These codes are very similar to G01 in that they control simple cutting movements. The only difference is that G02 controls clockwise cuts along a circle or arc, and G03 controls counterclockwise cuts. Additional values (I, J, or K) define the central point of the arc, and an R value defines the radius.

The code continues and gets progressively more complex, controlling aspects like cutter compensation, incremental positioning, and setting coordinate systems.

How does G-code work with CAD/CAM software?

Consider the overwhelming feat it would be to calculate the exact code to direct a machine to cut an irregular hole at a certain speed and to a certain depth. Now imagine doing it again and again for every geometry on a single part. And then again for every part that comes through a shop. Manual G-code computing is possible, but often it’s a waste of programmer time. CAD/CAM software automates this process by translating the toolpaths selected on a computer to the actual machine motion.

Try our CAD/CAM software

Download the free Mastercam Learning Edition today to explore what it’s like to use our software to solve your manufacturing challenges.