G-code (NC-code)

G-code (NC-code)
G-code (NC-code), which has many variants, is the common name for the most widely used numerical control (NC) programming language. It is used mainly in computer-aided manufacturing for controlling automated machine tools. G-code is sometimes called G programming language.

In fundamental terms, G-code is a language in which people tell computerized machine tools how to make something. The how is defined by instructions on where to move, how fast to move, and through what path to move. The most common situation is that, within a machine tool, a cutting tool is moved according to these instructions through a toolpath, cutting away excess material to leave only the finished workpiece. The same concept also extends to noncutting tools such as forming or burnishing tools, photoplotting, additive methods, and measuring instruments.


The first implementation of a numerical control programming language was developed at the MIT Servomechanisms Laboratory in the late 1950s. In the decades since, many implementations have been developed by many (commercial and noncommercial) organizations. G-code has often been used in these implementations. The main standardized version used in the United States was settled by theElectronic Industries Alliance in the early 1960s. A final revision was approved in February 1980 as RS-274-D. In other countries, the standard ISO 6983 is often used, but many European states use other standards. For example, DIN 66025 is used in Germany, and PN-73M-55256 and PN-93/M-55251 are used in Poland.

Extensions and variations have been added independently by control manufacturers and machine tool manufacturers, and operators of a specific controller must be aware of differences of each manufacturer's product.

One standardized version of G-code, known as BCL, is used only on very few machines.

During the 1970s through 1990s, many CNC machine tool builders attempted to overcome compatibility difficulties by standardizing on machine tool controllers built by Fanuc. Siemens was another market dominator in CNC controls, especially in Europe. In the 2010s, controller differences and incompatibility are not as troublesome because machining operations are developed with CAD/CAM applications that can output the appropriate G-code for a specific machine tool.

Some CNC machines use "conversational" programming, which is a wizard -like programming mode that either hides G-code or completely bypasses the use of G-code. Some popular examples are Southwestern Industries' ProtoTRAK, Mazak's Mazatrol, Hurco's Ultimax, Haas' Intuitive Programming System (IPS), and Mori Seiki's CAPS conversational software.

G-code began as a limited type of language that lacked constructs such as loops, conditional operators, and programmer-declared variables with natural -word-including names (or the expressions in which to use them). It was thus unable to encode logic; it was essentially just a way to "connect the dots" where many of the dots' locations were figured out longhand by the programmer. The latest implementations of G-code include such constructs, creating a language somewhat closer to a high-level programming language. Additionally, all primary manufacturers (e.g. Fanuc, Siemens, Heidenhain) provide access to PLC data, such as axis positioning data and tool data, via variables which can be used by NC programs. These constructs make it easier to develop automation applications.

Specific codes

G-codes are also called preparatory codes, and are any word in a CNC program that begins with the letter G. Generally it is a code telling the machine tool what type of action to perform, such as:

  • Rapid move (transport the tool through space to the place where it is needed for cutting; do this as quickly as possible)
  • Controlled feed move in a straight line or arc
  • Series of controlled feed moves that would result in a hole being bored, a workpiece cut (routed) to a specific dimension, or a profile (contour) shape added to the edge of a workpiece
  • Set tool information such as offset
  • Switch coordinate systems

There are other codes; the type codes can be thought of like registers in a computer.

Students and hobbyists have pointed out over the years that the term "G-code" referring to the language overall (using the mass sense of "code") is imprecise. It comes metonymically from the literal sense of the term, referring to one letter address among many in the language (G address, for preparatory commands) and to the specific codes (count sense) that can be formed with it (for example, G00, G01, G28). But every letter of the English alphabet is used somewhere in the language(although some letters' use is less common), so the name seems unfitting to people searching for strictly logical etymology. Nevertheless, "G-code" is indelibly established as the common name of the language.

Letter addresses

Some letter addresses are used only in milling or only in turning; most are used in both. Bold below are the letters seen most frequently throughout a program.

Sources: Smid 2008; Smid 2010; Green et al. 1996.

©2023 All rights reserved