Get a Free Quote

G and M Codes: Understanding the CNC Programming Languages

Avatar of Jason Chen
By Jason Chen

Senior Engineering Manager at Kemal, with 20+ years in mold design, injection molding and tooling.

G and M Codes- Understanding the CNC Programming Languages

 

G Code is the programming language of around 99% of machine tools, plus layer upon layer of increasingly complex machines that the original language developers could not have imagined.

If you use a CNC mill or lathe, 3D printer, EDM or wirecut machine, laser or waterjet cutter, router or any of the vast number of other machines that use this language, then G code is an essential tool and you simply have to understand its basics.

G code CNC programming is the language that drives the machines that make everything. Without this language, the whole manufacturing process just stops.

G Code instructs machines in long sequences of code that tell them:

  • Where to move to
  • What to do while axes move
  • What to do when they arrive

 

G code (and the associated M codes) are among the oldest programming languages. G code is the only language that has seen uninterrupted and continuous use for 70+ years.

In CNC (computer numerical code) lathes or mills, a spinning cutter is directly instructed in following a toolpath, removing material to extract a net-shape from a billet of material.

Similarly, in a 3D printer, laser cutter etc the machine is directed in precise geometric actions using G code. The operations it performs are specialist, and these are generally directed with M Codes, machine type/family specific instructions used within G code.

 

What is G Code and M Code?

 

 

What is G Code?

 

Is the Instruction set that tells machine tools what to do and how to do it. The G-code lines control how and where to move the machine’s functional devices (spindle cutters, lasers, knives, 3D print extruders etc.) following a predetermined route, or toolpath specifying all aspects of the machine’s orthogonal motion operations such as speed, direction, and cutter offset.

G code is written as a sequence of text commands, read sequentially. These are interpreted by the machine’s controller and executed to perform the planned operations in written order with no overlap.