G-code is a programming language used to provide instructions to computer numerical control—or CNC—machines. It tells a machine how and where to move, how quickly to travel, and which machining functions to perform while producing a physical part.
In a typical digital manufacturing workflow, computer-aided manufacturing software calculates the toolpaths needed to machine a CAD model. A postprocessor then translates those toolpaths into the machine-specific instructions commonly called G-code.
A simplified workflow looks like this:

CAD model → CAM toolpaths → postprocessor → G-code or NC program → CNC controller → machine movement
G-code is therefore one of the critical connections between a digital product model and a physical manufactured component.
Although it is often described as the language of CNC machines, G-code is not one perfectly universal language. Different machines, controllers, processes and manufacturers may support different commands, formats and extensions. A program that runs correctly on one machine may require modification before it can safely run on another.
What does G-code mean?
The term G-code comes from the letter G used at the beginning of many machining commands.
These G commands are traditionally called preparatory functions. They prepare or configure the controller to perform a particular kind of motion or interpret subsequent information in a particular way.
Common examples include:
- G00 or G0: Rapid positioning
- G01 or G1: Controlled linear movement
- G02 or G2: Clockwise circular movement
- G03 or G3: Counterclockwise circular movement
- G17: Select the XY working plane
- G20: Use inch units on controllers that support this convention
- G21: Use metric units
- G90: Use absolute positioning
- G91: Use incremental positioning
LinuxCNC’s official documentation describes G-code programs as collections of individual lines, also known as blocks. Each block can contain one or more commands and related values.
The term G-code is frequently used to describe the entire CNC program, even though that program may contain many instructions that do not begin with the letter G.
Is G-code an acronym?
No. G-code is not an acronym.
The “G” refers to a category of commands used in numerical control programming. It should not be expanded into a phrase such as “geometry code,” even though G commands frequently control geometric machine movements.
In formal documentation, the language may also be described as:
- Numerical control code
- NC code
- Part-program code
- RS-274
- RS274/NGC
- ISO-style CNC programming
People in manufacturing commonly use G-code as the more familiar umbrella term.
What does a G-code program look like?
A very simple CNC program might contain instructions resembling the following:
G21
G90
G00 X0 Y0
G01 Z-2.0 F150
G01 X40.0 Y0
G00 Z10.0
M30
This simplified example could be interpreted generally as:
- Use metric units
- Use absolute coordinates
- Move rapidly to a starting position
- Feed the cutting tool downward
- Make a controlled straight cut
- Retract the tool
- End the program
Real manufacturing programs may be far longer and more complicated. A program for a complex mold, turbine component, medical implant or aerospace structure could contain thousands or millions of calculated positions.
A block of code may include several types of information:
- Motion command
- Axis coordinates
- Feed rate
- Spindle speed
- Tool number
- Offset
- Coolant command
- Coordinate system
- Repetition or subprogram instruction
- Comments for the operator
The exact format depends on the machine and controller.
What information can G-code control?
Depending on the machine and its CNC controller, a program may control or influence:
- Linear axis movement
- Rotary axis movement
- Rapid positioning
- Controlled cutting movement
- Circular or helical interpolation
- Feed rate
- Spindle speed and direction
- Tool changes
- Coolant
- Dwell time
- Coordinate systems
- Tool-length compensation
- Cutter-radius compensation
- Drilling cycles
- Boring cycles
- Tapping cycles
- Probing routines
- Program pauses
- Subprograms
- End-of-program behavior
Not every function is controlled by a G command. A CNC program also contains other types of commands and data.
What is the difference between G-codes and M-codes?
G-codes generally define movement, positioning modes and machining behavior.
M-codes generally control miscellaneous machine functions.
Common M-code examples include:
- M03: Start the spindle clockwise
- M04: Start the spindle counterclockwise
- M05: Stop the spindle
- M06: Change the tool
- M08: Turn coolant on
- M09: Turn coolant off
- M30: End and reset the program
The exact meaning of an M-code may vary among controllers and machine configurations. Some machine manufacturers also provide custom M-codes for specialized equipment.
A CNC program can therefore contain G-codes, M-codes, coordinates, feed rates, spindle speeds, tool references and other instructions. Calling the entire program “G-code” is convenient, but technically it contains more than G commands.
What do the other letters in G-code mean?
Many CNC instructions use a letter followed by a numerical value.
Common address letters include:
| Letter | Common meaning |
|---|---|
| G | Preparatory or motion-related function |
| M | Miscellaneous machine function |
| X, Y, Z | Linear axis positions |
| A, B, C | Rotary axis positions |
| F | Feed rate |
| S | Spindle speed |
| T | Tool selection |
| N | Block or line number |
| I, J, K | Arc-center or vector information in certain commands |
| R | Radius, retract plane or another command-dependent value |
| P | Time, parameter or another command-dependent value |
The meaning of a letter can depend on the command in which it appears. A value should not be interpreted without understanding the surrounding block and the controller’s programming rules.
How does CAM software create G-code?
CAM software usually does not begin by writing individual G-code commands.
Instead, the programmer uses CAM software to define:
- The CAD model
- Stock material
- Machine tool
- Workholding
- Cutting tools
- Machining operations
- Speeds and feeds
- Toolpath strategies
- Avoidance geometry
- Tolerances
- Entry and exit moves
The CAM software calculates the resulting toolpaths. A postprocessor then converts the CAM system’s internal manufacturing instructions into code formatted for a particular CNC machine and controller.
Autodesk describes this process as converting CAM toolpaths into G-code through postprocessors matched to specific CNC machines. Siemens similarly describes CAM software as generating G-code instructions for CNC equipment.
This distinction is important:
The CAM toolpath represents the intended manufacturing motion.
The postprocessed G-code represents how a particular CNC controller is instructed to execute that motion.
Is a CAM toolpath the same as G-code?
No.
A CAM toolpath is the software’s calculated representation of how a cutting tool should move relative to the part.
G-code is the controller-oriented output used to command a CNC machine.
The CAM toolpath may contain richer information than the final NC program. It can include connections to:
- CAD geometry
- Machining features
- Tool definitions
- Operation parameters
- Stock models
- Fixtures
- Process templates
- Simulation data
Once the toolpath is postprocessed, much of that context may no longer be present in the output file. The CNC controller primarily receives the instructions required to perform the operation.
This loss of context is one reason manufacturers must carefully manage the relationship between CAD models, CAM files, postprocessors and released NC programs.
What is a postprocessor?
A postprocessor is software that translates CAM toolpaths into the code required by a particular CNC machine and controller.
It accounts for factors such as:
- Machine configuration
- Controller syntax
- Supported commands
- Axis arrangement
- Rotary-axis behavior
- Tool-change procedures
- Canned cycles
- Coordinate conventions
- Machine options
- Shop programming standards
- Required safety moves
NIST notes that CNC machines may require programs tailored to the specific mechanics and configuration of the machine.
A postprocessor should not be treated as a generic file exporter. It is a critical part of the manufacturing system.
An unsuitable or poorly configured postprocessor can produce code that:
- Causes unexpected motion
- Uses unsupported commands
- Selects the wrong rotary movement
- Handles tool changes incorrectly
- Creates inefficient positioning
- Fails to activate required machine functions
- Produces a collision or machine overtravel
Postprocessor availability and validation should therefore be investigated during a CAM software evaluation—not after the software has been purchased.
Is G-code the same for every CNC machine?
No.
Although many CNC systems share common G-code concepts, the language contains numerous dialects and controller-specific variations.
Differences may arise from:
- CNC controller manufacturer
- Controller model and software version
- Machine-tool builder
- Milling, turning or mill-turn configuration
- Number and arrangement of axes
- Installed machine options
- Custom macros
- Probing systems
- Tool changers
- Pallet systems
- Automation equipment
- Shop programming conventions
For example, two machines may both recognize G01 as a linear feed movement but differ in how they handle:
- Canned cycles
- Tool offsets
- Rotary axes
- Subprograms
- Variables
- Macros
- Coordinate transformations
- Advanced five-axis functions
NIST has described G-code as a near-universal format for programming computer-based numerical-control machines, while also documenting limitations in portability and information exchange between systems.
“Near-universal” does not mean interchangeable.
Why can’t the same G-code run on every machine?
A CNC program is not defined solely by the finished part.
It also depends on the machine that will manufacture the part.
Machines can differ in:
- Axis travel
- Spindle limits
- Rotary-axis orientation
- Direction of positive motion
- Machine kinematics
- Tool capacity
- Fixture arrangement
- Work-envelope size
- Controller capabilities
- Safety requirements
A five-axis machine with a tilting table behaves differently from one with a swiveling head. A lathe with live tooling behaves differently from a simple two-axis turning center. Two similar machines may still require different initialization, tool-change or probing instructions.
For that reason, moving a program from one machine to another may require reposting the CAM operations using a different postprocessor, followed by new verification and prove-out.
Can G-code cause a CNC machine collision?
Yes.
A CNC machine follows the program it receives within the limits of its controller, configuration and safety systems. Incorrect code can potentially direct a tool, spindle, table, fixture or machine component into an unsafe position.
Problems can arise from:
- Incorrect coordinates
- Wrong work offset
- Incorrect tool-length value
- Unexpected positioning mode
- Wrong unit selection
- Incorrect rotary-axis output
- Missing clearance move
- Incompatible postprocessor
- Manual code-editing error
- Incorrect machine setup
- Unanticipated controller behavior
A program that appears reasonable when read as text may still create unsafe machine movement.
That is why manufacturers use some combination of:
- CAM toolpath verification
- Material-removal simulation
- Machine simulation
- G-code-driven simulation
- NC-code verification
- Controller emulation
- Dry runs
- Single-block operation
- Reduced rapid speed
- Careful prove-out procedures
Siemens distinguishes G-code-driven simulation from basic toolpath animation because the simulation uses the NC output that will drive the machine rather than only the original CAM calculation.
What is G-code-driven simulation?
G-code-driven simulation uses the postprocessed NC program as the input for a virtual machining process.
This can provide a more realistic test than simulating the CAM toolpath alone because the postprocessor may introduce:
- Machine-specific commands
- Rotary-axis decisions
- Tool changes
- Controller cycles
- Positioning moves
- Output formatting
- Machine functions
A simulation based only on the CAM toolpath may show the intended process. A G-code-driven simulation can help show what the machine has actually been instructed to do.
Advanced simulation may model:
- The physical machine
- Linear and rotary axes
- Tool holders
- Fixtures
- Stock
- Workpiece
- Machine enclosure
- Tool changes
- Material removal
This does not eliminate the need for physical program prove-out, but it can identify certain errors before they reach an expensive machine or workpiece.
Do machinists still write G-code manually?
Yes.
The extent of manual programming depends on the shop, machine and complexity of the work.
Manual G-code programming may still be practical for:
- Simple turning operations
- Basic milling
- Drilling patterns
- Small program changes
- Repetitive operations
- Probing routines
- Setup movements
- Shop-floor corrections
- Custom macros
- Conversationally programmed machines
Complex three-dimensional, simultaneous five-axis or high-speed machining is more likely to rely heavily on CAM software because manually calculating and maintaining the required movements would be difficult and time-consuming.
Even when CAM creates the complete program, understanding G-code remains useful. Programmers, machinists and operators may need to:
- Review program behavior
- Diagnose an error
- Confirm units or coordinate modes
- Adjust a feed rate
- Locate an unsafe move
- Understand a controller alarm
- Verify tool changes
- Make approved shop-floor edits
CAM automation reduces the amount of code that must be written manually. It does not necessarily remove the value of knowing how to read it.
Is conversational CNC programming the same as G-code?
Not exactly.
Conversational programming allows an operator to define machining operations through menus, forms, diagrams or plain-language process steps at the CNC control.
Instead of manually entering every movement, the operator may describe:
- A pocket
- A hole pattern
- A contour
- A turning profile
- A drilling cycle
- A stock-removal operation
The controller then creates or executes the required machine instructions.
Some conversational systems generate conventional G-code in the background. Others use proprietary cycles or higher-level instructions.
Siemens SINUMERIK controllers, for example, support G-code programming along with ShopMill and ShopTurn machining-step programming.
Conversational programming can be efficient for certain shop-floor tasks, but it does not necessarily replace CAM for complex parts, extensive simulation, multi-operation planning or enterprise process control.
What is an NC program?
An NC program is a set of instructions used to control a numerically controlled machine.
NC stands for numerical control.
A CNC machine is a computer numerical control machine, meaning that a computerized controller interprets the program and commands the equipment.
The terms G-code, NC code, CNC program and part program are often used interchangeably in ordinary conversation. There can be technical distinctions, but all generally refer to the instructions used to produce machine behavior.
Calling a file a G-code program does not mean every command in the file begins with G.
Is G-code only used for metal machining?
No.
G-code or related numerical-control languages may be used by:
- CNC mills
- CNC lathes
- Mill-turn machines
- CNC routers
- Plasma cutters
- Laser cutters
- Waterjet machines
- Electrical discharge machines
- Grinding machines
- Woodworking equipment
- Additive manufacturing equipment
- Desktop fabrication machines
The commands and programming expectations vary by process.
For example, a machining center may control spindle speed, coolant and tool changes, while an additive machine may interpret instructions related to extrusion, deposition or temperature. The programs may share familiar command structures while serving very different physical processes.
Is G-code a file format?
G-code programs are often stored as plain-text files, but there is no single mandatory file extension used by every system.
Possible extensions include:
.nc.cnc.tap.gcode.ngc.txt- Machine- or company-specific extensions
The extension alone does not determine whether the program is compatible with a machine. Its internal commands, postprocessor, controller dialect and machine configuration matter far more.
Because the files are commonly text-based, they may be opened and examined with an NC editor or ordinary text editor. However, editing production code should be controlled carefully because even a small change can alter machine movement.
Why is editing G-code risky?
A manual edit may appear minor while changing how the controller interprets the remainder of the program.
Some G-code commands are modal, meaning they remain active until another command changes or cancels them.
Examples may include:
- Absolute or incremental positioning
- Unit selection
- Plane selection
- Feed mode
- Motion type
- Cutter compensation
- Coordinate system
- Canned cycle
Deleting or altering one modal command can affect many later blocks.
Other edits can create risk by:
- Changing the sign of a coordinate
- Moving a decimal point
- Removing a clearance position
- Changing a tool number
- Selecting the wrong work offset
- Altering the feed rate
- Removing a spindle or coolant command
- Breaking a subprogram call
- Bypassing postprocessor logic
A manually edited program may also become disconnected from its source CAM file. If the operation is later reposted, the manual correction could disappear unless the postprocessor or CAM process is updated as well.
What is modal G-code?
A modal command remains in effect until it is replaced or canceled.
For example, after a controller is placed in absolute-positioning mode, subsequent coordinates may continue to be interpreted as absolute positions until the program selects incremental positioning.
This allows programs to avoid repeating the same settings on every line. It also means that understanding a particular block may require knowing which commands were activated earlier.
Controllers organize modal commands into groups. Normally, only one command from a modal group can be active at a time.
A safe program commonly includes an initialization or safety line that deliberately establishes important modes rather than assuming the machine remains in a particular state from a previous program.
The precise safety-line conventions depend on the machine, controller and shop.
Is G-code obsolete?
No.
G-code is old by software standards, but it remains deeply embedded in modern manufacturing.
NIST has described it as the typical language used to program CNC machines and has examined its limitations as manufacturers pursue richer, more connected CAM-to-CNC information flows.
Its limitations include the fact that conventional G-code may communicate machine movement without preserving all the manufacturing intent behind that movement.
The NC program may not fully describe:
- Why a particular strategy was selected
- Which CAD feature is being machined
- What tolerance motivated the operation
- Which manufacturing requirement applies
- How the operation relates to the broader process plan
- What changed between revisions
Researchers and standards organizations have explored richer manufacturing-data models, including STEP-NC, to carry more process and product meaning into manufacturing systems.
Nevertheless, G-code continues to be widely used because:
- It is supported by an enormous installed base of CNC equipment
- Manufacturers have extensive experience with it
- It is readable as text
- It can be generated by nearly every major CAM system
- Existing controllers and production processes depend on it
- Replacing established machine infrastructure is difficult and expensive
G-code is therefore not disappearing simply because more advanced alternatives are technically possible.
What is the future of G-code?
The future may involve less direct human interaction with G-code without necessarily eliminating it.
Manufacturing systems are increasingly able to connect:
- CAD models
- Product and manufacturing information
- CAM operations
- Tool libraries
- Machine simulations
- Digital twins
- CNC controllers
- Probing results
- Inspection systems
- Production analytics
- Closed-loop process adjustments
As these connections improve, more intelligence may remain attached to the manufacturing process rather than being reduced to a relatively low-context movement program.
Future systems may increasingly:
- Generate NC code automatically
- Validate code against virtual machine models
- Select or optimize cutting parameters
- Compare expected and actual machine behavior
- Adjust processes using inspection or sensor data
- Maintain stronger links between engineering changes and production
- Use higher-level manufacturing information instead of relying only on axis commands
But manufacturing technologies rarely replace an installed standard overnight.
The more likely path is that G-code continues operating inside a richer digital manufacturing system. Engineers and machinists may see it less frequently, while machines still depend on it—or on a closely related controller language—behind the scenes.
Why does G-code matter when evaluating CAM software?
A CAM demonstration can produce an impressive animated toolpath without proving that the software can successfully program a buyer’s real machines.
During a CAM evaluation, manufacturers should investigate:
- Whether suitable postprocessors already exist
- Whether posts are generic or machine-specific
- Who will customize them
- Who owns and supports the postprocessor
- Whether controller-specific cycles are supported
- Whether the CAM provider can model the actual machine
- Whether simulation uses CAM toolpaths or final G-code
- How postprocessors are tested and validated
- How updates will be managed
- Whether existing programs can be migrated
- What happens when the shop buys another machine
The ability to calculate a toolpath is only part of a CAM system’s value.
The software must also deliver dependable instructions to the equipment that will manufacture the part.
Frequently asked questions about G-code
What is G-code in simple terms?
G-code is a language used to give instructions to CNC machines. It can tell the machine where to move, how quickly to move and which functions to perform while making a part.
What does the G in G-code stand for?
The G identifies preparatory functions used in numerical-control programming. G-code is not an acronym, and the G should not be formally expanded as “geometry.”
Is G-code the same as CNC programming?
G-code is one widely used method of CNC programming. CNC machines may also support conversational programming, proprietary cycles, macros and other controller-specific programming methods.
Does all CNC code begin with G?
No. A CNC program may also contain M-codes, axis coordinates, tool numbers, feed rates, spindle speeds, comments and other instructions.
Does CAM software automatically generate G-code?
CAM software calculates machining toolpaths. A postprocessor then converts those toolpaths into code formatted for a particular CNC machine and controller.
Is G-code universal?
No. Many controllers share common commands, but machines and CNC systems can support different dialects, formats and functions.
Can the same G-code be used on two CNC machines?
Sometimes, but it should not be assumed. Differences in controllers, machine kinematics, axes, tooling and configuration may require the program to be reposted and revalidated.
Can G-code damage a machine?
Incorrect code or an incorrect setup can cause unsafe motion, collisions, damaged tooling, scrapped parts or machine damage. Programs should be verified and proved out using the shop’s approved procedures.
Can people write G-code by hand?
Yes. Manual programming remains useful for simple operations, shop-floor adjustments, macros and troubleshooting. Complex parts are more commonly programmed with CAM software.
Do 3D printers use G-code?
Many do, although additive-manufacturing commands and controller behavior can differ from the G-code used by CNC machine tools.
What is the difference between G-code and M-code?
G-codes generally define motion and machining modes. M-codes generally control supporting machine functions such as the spindle, coolant, tool changes and program completion.
What file extension does G-code use?
Common extensions include .nc, .cnc, .tap, .gcode and .ngc, but naming conventions vary by machine, controller and organization.
Is G-code still used?
Yes. It remains a common method for programming CNC equipment, even as manufacturing systems develop richer and more automated connections among CAD, CAM, simulation and machine controls.
