Request a Personalized Demo

Learn how to accurately convert your designs with Scan2CAD

  • This field is for validation purposes and should be left unchanged.
  • Join thousands of happy customers worldwide

Guide to CAD for CNC: What is G-code?

CAD Guide G Code

If you’re venturing into the world of CNC and CAM manufacturing, or are just looking into beginners CNC kits, you may well have heard of the term “G-code”. G-code is a programming language for computer numerical controlled (CNC) machines. In this short guide, we’ll introduce you to the basics of G-code, and how to start using it. (Spoiler alert: unlike some other programming languages, you won’t have decipher the meaning of all the letters and digits of G-code to use CNC; you only need to choose the right CAM program to generate it for you!)

How is G-code used in CNC machining?

What is G-codeCNC machinists use G-code to instruct CNC machines where and how to move. The code dictates which direction the machine should move in, how fast it should move, how deep it should cut, and so on. The instructions are described using Cartesian coordinate locations (e.g. two units left and three units up.)

To begin with, an initial block of material will be loaded into the machine. Then, following the instructions given by the G-code, the cutting tool cuts away material from the block to produce the finished product.

G-code is one of the most widely used programming languages used to control automated machine tools. Most CNC machines execute G-code, although other CNC languages exist, such as Heidenhain, Mazak, and other proprietary formats.

CNC machinists can either write G-code from scratch, modify existing G-code, or generate G-code using CAM software. CAM software can generate G-code from either images or CAD files. In today’s extensive CAD industry, there are also CAD editing programs that automatically convert CAD files into G-code. There are also richly-featured G-code editors that can be used to simulate G-code, or to translate G-code into conversational CNC.

G-code sample

An example of a CNC editor, where CAM programmers can edit G-code before manufacturing

What other technologies make use of G-code?

How to read and write G-code

A typical line of G-code is quite cryptic for newcomers – it takes years for a CNC machinist to master the language. Whilst the entire language is referred to as G-code, technically speaking a ‘code’ refers to just a single instruction in the language. Each ‘code’ consists of a letter address and a number, and gives a specific instruction to the machine.

Most lines of G-code will begin with the letter G – hence why the language got the name! This is because the letter G signifies preparatory codes. They tell the machine which kind of motion is required, or which offset values to use. The codes beginning with G are therefore almost always found at the start of a line of G-code. G00, for example, tells the machine to move at maximum speed, while G02 tells it to move in a clockwise, circular motion.

G-code sample

Try and read this snippet of G-code! It’s a simple drawing of straight lines

Not all G-codes start with the letter G!

Whilst codes beginning with G are extremely common, all 26 letters of the alphabet are used in G-code. S, for example, defines speed, while F defines feed rate. There are some other important basics to know, such as:

  • The letter X controls the horizontal position or X-axis of the machine
  • The letter Y controls the vertical position or Y-axis of the machine
  • The letter Z controls the depth or Z-axis of the machine
  • The numbers next to these letters determine the distance moved by the machine

You can view a full list of standard G-codes here. Be aware, however, that codes vary by machine type, make, and model.

G-code File Types supported by Scan2CAD

There are dozens of known G-code file extensions. Which file type your CNC machine will support depends on its setup, as well as the make and model. Scan2CAD supports three of the most popular G-code file types – .CNC, .NC and .TAP. The latest release of Scan2CAD, v9, allows you to directly export a vector image file to G-code file format. Now, you can convert scanned sketches and images to vector using Scan2CAD, before saving it as G-code. These files can then be transferred to a CNC machine and used for production.

The CNC Export dialog in Scan2CAD provides you with a range of options:

  • G-code Bezier options – cubic splines (G-code G05), arcs (G-code G02/G03) or polylines (G-code G01). If you select polylines, Bezier curves will be broken into straight-line segments
  • Arc and circle rotation – clockwise or anti-clockwise
  • Z-settings – various parameters relating to the cutting of the exported vectors
  • Scale settings – the relation between vector points and a distance in real-life – e.g. two points on a vector image could represent an inch
Scan2CAD CNC Export Settings Dialog Box

The CNC Export Settings dialog box in Scan2CAD. There are four different settings which can be defined.

Recommended reading:

Join 53,482 designers and engineers who get our best articles once a week.
  • This field is for validation purposes and should be left unchanged.

10 Responses to Guide to CAD for CNC: What is G-code?

  1. Dino Cervantes Nov 16, 2016 at 9:15 PM #

    Very useful. Thanks for sharing!

    • luke
      Luke Kennedy Nov 16, 2016 at 9:34 PM #

      Very happy to hear this article helped, Dino!

  2. Mary May 24, 2017 at 2:48 PM #

    thanks for helping me cheat on my tech ed test bby?

  3. A C M Sep 3, 2017 at 5:47 AM #

    Very informative as for me I’m a beginner .
    Thanks to victoria . How could I connect you for more information?
    Regards 🙂

  4. Faisal Oct 6, 2017 at 8:02 AM #

    I am using cnc machine using aspire 8.0, is there any other software to use free and more helpful easy to use, plz suggest.

  5. M-GHITH ALSABEA Jan 9, 2018 at 3:52 AM #

    First, thanks for this precious site. Then, please can you guide me to any safe online free course that makes me able to improve my skills and start working at the CNC workshops’ environments.

    • jay Jan 9, 2018 at 4:22 AM #

      Hello! We have free tutorial videos available at They show you the basic steps for converting images using Scan2CAD.

  6. Gene Grillot Jun 30, 2018 at 2:40 PM #

    Received a Xone2 3D printer for BD, the included manual was very poor, your posting gives me hope that the Xone2 can do some real stuff, Thanks

Leave a Reply