Table of Contents

What Is G-Code? CNC Commands, Programming & Examples

G-code is the machine programming language used to tell CNC equipment where and how to move during a machining operation. A G-code program can define tool positions, coordinates, linear and circular movements, feed conditions, machining cycles, and other instructions required to convert a digital machining strategy into physical machine movement.

In modern CNC machining, G-code sits near the end of a digital manufacturing workflow. A designer creates the component geometry in CAD, a CNC programmer develops the machining strategy in CAM software, a post processor converts the calculated toolpaths into machine-compatible code, and the CNC controller executes those instructions to manufacture the part.

For engineers purchasing custom machined parts, understanding every line of a Gcode program is normally unnecessary. However, understanding the basic G code meaning, how CNC programs are generated, and how programming affects tolerances, surface finish, machining time, and manufacturing risk can help explain how a CAD model becomes a finished precision component.

What Is G-Code in CNC Machining?

G-code is a programming format used by CNC machines to control machining movements and operating modes. The CNC controller reads the program block by block and converts its instructions into movements of the machine axes.

In CNC milling, these instructions may tell a cutting tool to move rapidly above a workpiece, feed into material, machine a straight slot, interpolate around a radius, or drill a pattern of holes. In CNC turning, the program coordinates cutting-tool movement relative to a rotating workpiece to create diameters, faces, grooves, bores, and threads.

This means G-code is not the same as a CAD model. The CAD model describes what the finished component should look like, while the CNC program describes how the machine should move to manufacture it.

If you are asking what is Gcode, what is a Gcode, of what is G code in a CNC machine, the simplest definition is that G-code is the machine-readable programming language used to control CNC machining movements and operating functions.

What Does G-Code Mean?

G commands used in CNC programming are generally classified as preparatory functions. Each command combines the letter G with a numerical value, such as G00, G01, G21, or G80, to place the CNC controller into a particular motion or operating mode.

You may also see G-code described online as geometric code because many commonly used G commands control tool motion and geometry. However, describing G commands as preparatory functions is more technically appropriate in CNC programming.

A practical G-code definition is:

G-code is a machine programming language used to define CNC tool movements, coordinate modes, interpolation methods, machining cycles, and other machine instructions.

G-code is also only one part of a complete CNC program. Other addresses and commands provide coordinate values, feed rates, spindle information, tool numbers, offsets, and auxiliary machine functions.

How Does G-Code Work?

The basic CNC programming workflow can be summarized as:

CAD Model → CAM Programming → Toolpath → Post Processor → G-Code → CNC Controller → Machine Movement → Finished Part

CAD Model

The CAD model defines the intended geometry of the component, including surfaces, pockets, holes, slots, radii, bosses, and other machined features.

An engineering drawing may provide additional requirements that cannot always be communicated by the 3D model alone, such as dimensional tolerances, threads, surface roughness, geometric tolerances, and critical inspection dimensions.

CAM Programming

The CAD model is imported into CAM software, where the CNC programmer develops the machining strategy.

Programming decisions may include:

  • Machine setup and machining orientation
  • Workholding and fixture arrangement
  • Cutting-tool selection
  • Roughing and finishing strategies
  • Drilling and threading operations
  • Depth of cut
  • Step-over
  • Feeds and speeds
  • Tool entry and exit movements
  • Tool changes

The CAM system uses this information to calculate toolpaths.

Post Processing

A CAM toolpath cannot always be sent directly to any CNC machine. It normally needs to pass through a post processor that converts the CAM data into the programming format expected by the target machine and controller.

A post processor may account for:

  • CNC machine type
  • Controller type
  • Available machine axes
  • Machine kinematics
  • Supported G codes
  • Machine-specific syntax

This is why you should not assume that every CNC machine interprets every G code in exactly the same way.

CNC Controller

Once the program is transferred to the CNC machine, the controller interprets each program block and converts it into commands for the machine axes, spindle, and other functions.

The machine then follows the programmed sequence to perform positioning, rough machining, drilling, finishing, and other required operations.

What Does a G-Code Program Look Like?

The following is a simplified Gcode example for educational purposes:

%
O1001
G21 G90
G00 X0 Y0
G00 Z5.0
G01 Z-2.0 F100
G01 X40.0 F300
G00 Z5.0
M30
%

In a compatible CNC milling environment:

  • O1001 identifies the program.
  • G21 selects metric units.
  • G90 selects absolute positioning.
  • G00 commands rapid positioning.
  • X, Y, and Z define axis positions.
  • G01 commands linear interpolation.
  • F specifies feed rate.
  • M30 ends and resets the program.

This sample Gcode is intended only to explain basic G-code programming. A real production program also depends on tooling, work offsets, spindle conditions, tool compensation, fixtures, machine limits, and controller-specific requirements.

You should never copy a G-code example from the internet and run it on a CNC machine without verifying it for the actual equipment and setup.

What Information Is Contained in a G-Code Block?

A CNC program normally uses several types of address letters to describe machining instructions.

Address Typische betekenis Voorbeeld
G Preparatory function G01
X X-axis value X25.0
Y Y-axis value Y10.0
Z Z-axis value Z-5.0
F Voedingssnelheid F300
S Spindle speed value S5000
T Tool designation T01
M Miscellaneous machine function M03

Bijvoorbeeld:

G01 X50.0 Y20.0 F300

On a compatible CNC controller, this block can command a controlled linear movement toward the specified X and Y coordinates at the programmed feed rate.

Understanding how these addresses work together is one of the most important G code programming basics.

Common G-Code Commands List

There are many CNC G codes, and supported functions can vary between CNC machines and controllers. However, the following commands are commonly encountered in CNC milling.

G Code Common Function
G00 Rapid positioning
G01 Linear interpolation
G02 Clockwise circular interpolation
G03 Counterclockwise circular interpolation
G20 Select inch units
G21 Select metric units
G40 Cancel cutter compensation
G41 Cutter compensation left
G42 Cutter compensation right
G43 Tool length compensation
G54 Select work coordinate system
G80 Cancel canned cycle
G81 Drilling canned cycle
G90 Absolute positioning on many milling controls
G91 Incremental positioning on many milling controls

This G code commands list should be used as a general reference only. Always verify the actual CNC programming manual because the meaning of some G codes in CNC can change between machines and controllers.

What Does G00 Mean in G-Code?

G00, also commonly searched as G0 G code of G code G0, is widely used for rapid positioning.

Instead of performing a controlled cutting move at the programmed machining feed rate, G00 is typically used to move the tool quickly between positions where material is not intended to be removed.

Typical G00 applications include moving:

  • Between separate machining features
  • Above the workpiece
  • To a safe approach position
  • Away from the component after cutting

Bijvoorbeeld:

G00 X50 Y20

can command a rapid positioning movement toward the specified coordinates on a compatible machine.

Rapid movements must be programmed with adequate clearance. A poorly planned G00 path can cause the cutter or tool holder to collide with the workpiece or fixture.

What Does G01 Mean in G-Code?

G01, sometimes written as G1, is commonly used for controlled linear interpolation.

A typical G01 G code command might look like:

G01 X50.0 Y20.0 F300

This can instruct a compatible CNC machine to make a controlled linear move toward the specified coordinate at the programmed feed rate.

De G1 G code meaning is therefore very different from G00. G00 is normally used for rapid positioning, while G01 is commonly used for controlled machining movement.

G00 vs G01

Command Hoofdfunctie Typisch gebruik
G00 Rapid positioning Non-cutting movement
G01 Controlled linear interpolation Cutting movement

Correct use of G00 and G01 helps balance machining efficiency with safe and controlled tool movement.

What Do G20 and G21 Mean in G-Code?

On many common CNC controls, G20 selects inch units and G21 selects metric units.

Bijvoorbeeld:

G21
G90
G01 X25.0 F200

In an appropriate controller environment, G21 tells the machine that the programmed dimensional values are being interpreted using metric units.

The distinction between G20 Gcode and G21 G code is critical because an incorrect unit setting can cause serious dimensional and machine-movement errors.

Unit mode should therefore be established and verified before machining begins.

What Is G80 in CNC?

G80 is commonly used to cancel an active canned cycle on CNC equipment.

For example, a drilling operation may use a canned cycle such as G81 to drill multiple holes. Subsequent X and Y positions can repeat the same drilling sequence without rewriting every individual drilling movement.

A simplified example is:

G81 X10 Y10 Z-8 R2 F120
X30 Y10
X50 Y10
G80

In this example, G80 cancels the active drilling cycle after the required hole positions have been completed.

Understanding the G80 CNC code, G80 code CNC, of G80 G code is important because failing to cancel a canned cycle can cause later coordinate commands to produce unintended machine actions.

The exact function and syntax must still be verified against the controller documentation.

What Is G70 in CNC Programming?

G70 is a good example of why CNC programmers should not assume every G code has one universal meaning.

On some CNC lathe controls, G70 is used as a finishing cycle and can follow a roughing operation. On other types of machines or controllers, G70 may perform a completely different function.

Therefore, if you search for G code G70, you should always identify whether the information applies to a CNC mill, CNC lathe, or a particular controller.

This is also why a generic list of CNC G codes cannot replace machine-specific programming documentation.

What Is the Difference Between G-Code and M-Code?

G-code and M-code often appear in the same CNC program, but they usually have different purposes.

G commands primarily control machining modes and movement functions such as positioning, interpolation, coordinate systems, and canned cycles.

M commands generally control auxiliary machine functions such as spindle operation, coolant, program stops, and program completion.

Code Typical Function
G00 Rapid positioning
G01 Linear interpolation
G21 Metric units
G80 Cancel canned cycle
M03 Spindle clockwise
M05 Spindle stop
M08 Coolant on
M09 Coolant off
M30 Program end/reset

A complete G code CNC programming workflow therefore involves much more than G commands alone.

How Do Coordinates Work in G-Code?

A CNC machine needs a coordinate system to understand where the cutting tool and workpiece are located relative to each other.

A typical CNC milling machine uses three linear axes:

  • X axis
  • Y axis
  • Z axis

The programmer also establishes a work coordinate system so machining positions can be referenced from a defined origin on the component or fixture.

For example, a programmer may use the center of a component or a particular corner of the stock as the work origin. The CAM-generated toolpath is then calculated relative to that reference.

The machine itself also has its own machine coordinate system, so machine zero and work zero should not be confused.

What Is the Difference Between G90 and G91?

On many CNC milling controls, G90 is used for absolute positioning and G91 is used for incremental positioning.

G90 Absolute Positioning

G90
G01 X50
G01 X100

In absolute mode, each coordinate is measured relative to the defined work origin.

G91 Incremental Positioning

G91
G01 X50
G01 X50

In incremental mode, each coordinate describes movement relative to the current position.

Confusing absolute and incremental modes can produce completely different tool movements and may cause dimensional errors, scrap, or even collisions.

Again, command meanings should be checked for the actual machine. Some G-code numbers can have different meanings on CNC lathes than they do on CNC milling machines.

How Do G02 and G03 Create Arcs?

G02 and G03 are commonly used for circular interpolation.

  • G02 — clockwise circular interpolation
  • G03 — counterclockwise circular interpolation

These commands can be used to machine features such as:

  • Internal and external radii
  • Circular contours
  • Curved profiles
  • Pocket transitions
  • Circular machining paths

Depending on the CNC controller, an arc may be defined using an endpoint together with center offsets or radius information.

For complex geometry, CAM software normally calculates these circular and 3D tool movements automatically.

How Do You Generate G-Code?

For most complex production components, manufacturers generate G code with CAM software instead of manually writing every tool movement.

A typical process is:

  1. Import the CAD model.
  2. Define the machining setup.
  3. Select cutting tools.
  4. Define roughing and finishing operations.
  5. Set appropriate machining parameters.
  6. Generate CNC toolpaths.
  7. Simulate machining operations.
  8. Post-process the toolpaths.
  9. Generate the machine program.
  10. Verify the program before machining.

For simple components, manually written G code programs may be practical. For complex precision parts, freeform surfaces, molds, or multi-axis components, CAM-generated programs may contain thousands of individual movements.

How Do You Write Basic G-Code?

If you want to learn how to write G code, it is better to understand the programming structure before trying to memorize a large number of commands.

A basic educational workflow is:

  1. Define the unit system.
  2. Select the required positioning mode.
  3. Establish the work coordinate system.
  4. Position the cutting tool safely.
  5. Set the required spindle and machining conditions.
  6. Approach the workpiece.
  7. Perform controlled cutting movements.
  8. Retract to a safe position.
  9. End the machining operation.
  10. Simulate and verify the program.

However, real production Gcode programming involves significantly more than these basic steps.

A production programmer must also consider:

  • Werkstukklemming
  • Tool selection
  • Tool length
  • Tool diameter
  • Offsets
  • Speeds and feeds
  • Cutting forces
  • Machine travel limits
  • Tool-holder clearance
  • Fixture clearance
  • Material behavior
  • Collision risks

Knowing the syntax of G00 or G01 does not by itself make a CNC machining process safe or efficient.

What Is a G-Code File?

A G-code file is a text-based machine program containing instructions that a CNC controller can interpret.

Depending on the CNC software, controller, and machine environment, programs may use file extensions such as:

  • .gcode
  • .nc
  • Other controller-specific extensions

Therefore, .gcode should not be considered the only file extension used for CNC machining programs.

More important than the file extension is whether the program has been generated and post-processed correctly for the intended CNC machine.

Can You Write G-Code Manually?

Yes. Manual G-code programming is still useful for relatively simple operations and machine-program adjustments.

Typische toepassingen omvatten:

  • Simple positioning
  • Basic drilling patterns
  • Straightforward turning operations
  • Simple linear cuts
  • Program modifications
  • Machine setup adjustments

However, CAM programming becomes much more practical when the component contains complex geometry.

CAM is particularly useful for:

  • Complex 3D surfaces
  • Large pocketing toolpaths
  • Molds and dies
  • Multi-feature precision components
  • 4-axis machining
  • 5-assige bewerking

In actual CNC manufacturing, manual programming and CAM-generated programs can be used together. A programmer may generate the main toolpaths in CAM and still review or modify sections of the final program when required.

How Is G-Code Used in CNC Milling?

In CNC milling, a rotating cutting tool removes material while the machine controls relative movement between the cutter and the workpiece.

Gcode for CNC milling machine operations can control machining processes such as:

  • Oppervlakfrezen
  • Zakfrezen
  • Slot machining
  • Boren
  • Boren
  • Draadfrezen
  • Contour milling
  • Afvlakken
  • Profile machining
  • 3D-oppervlakteafwerking

A 3-axis CNC milling machine generally coordinates movement in X, Y, and Z. More advanced equipment may add rotary axes for 4-axis or 5-axis machining.

As the number of axes and component complexity increase, CAM programming and correct post processing become increasingly important.

How Is G-Code Used in CNC Turning?

In CNC turning, the workpiece normally rotates while the cutting tool moves relative to it.

G-code-based CNC programs can control operations including:

  • Oppervlaktebehandeling
  • OD turning
  • ID boring
  • Groeven
  • Boren
  • Draadwerk
  • Rough turning
  • Finish turning

CNC mills and CNC lathes use many of the same general programming concepts, but individual CNC G codes and their exact meanings can vary.

This is why programmers must know the target machine and controller before interpreting or editing a CNC program.

How Does G-Code Affect CNC Part Quality?

Customers normally do not see the CNC program when purchasing a machined component, but programming decisions can directly affect how efficiently and consistently that component is manufactured.

Dimensionale nauwkeurigheid

The toolpath must correspond correctly to the intended component geometry and machining setup.

Incorrect coordinates, tool offsets, compensation, or work offsets can result in dimensions that do not match the engineering drawing.

Programming is therefore one part of dimensional control, although final machining accuracy also depends on machine capability, workholding, cutting tools, material behavior, and inspection.

Surface Finish

The programmed toolpath determines how the cutting edge moves across the component.

Feed conditions, step-over, cutter engagement, interpolation, finishing direction, and machining strategy can all affect visible tool marks and achievable surface quality.

Levensduur van het gereedschap

A poor toolpath may create excessive cutting engagement, heat, or unstable cutting conditions.

A better CAM strategy can help maintain more appropriate tool engagement and reduce unnecessary loading on the cutting edge.

Cyclustijd

A CNC program contains both cutting and non-cutting movements.

Reducing unnecessary positioning, optimizing tool sequences, and selecting efficient cutting strategies can reduce CNC machining time without simply increasing feed rates.

Collision Risk

Programming errors can cause interference between the machine, cutting tool, tool holder, fixture, and workpiece.

Unsafe clearance heights, incorrect coordinate modes, or incorrect work offsets can all increase collision risk.

Good CNC programming is therefore not simply about making the machine move. It is about manufacturing the intended component accurately, safely, efficiently, and repeatedly.

What Are Common G-Code Programming Errors?

Wrong Units

Confusing G20 and G21 may cause dimensions to be interpreted using the wrong unit system.

Incorrect Coordinate Mode

Using the wrong absolute or incremental programming mode can change the intended toolpath.

Incorrect Work Offset

If the machine uses an origin different from the programmed origin, features may be machined in the wrong position.

Incorrect Tool Offset

An incorrect tool length or diameter compensation value can affect both tool position and finished dimensions.

Incorrect Feed Rate

A feed rate unsuitable for the material, cutter, or machining operation can reduce surface finish or tool life.

Incorrect Spindle Conditions

Spindle speed must be appropriate for the selected tool, workpiece material, cutter diameter, and operation.

Unsafe Rapid Movement

A G00 movement without sufficient clearance can cause interference with the part or fixture.

Incorrect Z Depth

An incorrect depth command can create undersized features, machine deeper than intended, or potentially interfere with the fixture.

Incorrect Post Processor

A post processor must match the intended CNC machine and controller configuration.

Uncancelled Canned Cycles

A drilling or other canned cycle that remains active may cause later coordinate commands to trigger unintended machining operations.

How Is G-Code Verified Before CNC Machining?

Before machining a new component, CNC programs can be reviewed and verified using several methods.

  • CAM toolpath simulation
  • Collision checking
  • Program review
  • Machine simulation
  • Dry run
  • Single-block execution
  • Controlled first-part machining
  • First article inspection

Program verification becomes particularly important when machining expensive materials, tight-tolerance components, complex fixtures, deep features, or multi-axis geometries.

A successful simulation does not automatically guarantee a conforming component. CNC programming must still work together with correct setup, tooling, machine condition, process control, and inspection.

Why Is G-Code Important for Precision CNC Machining?

G-code provides the machine-readable instructions that connect a digital machining strategy with actual CNC machine movements.

It enables manufacturers to perform programmed machining sequences repeatedly and manufacture complex geometries with much less dependence on continuous manual machine movement.

However, G-code alone does not guarantee precision.

The final quality of a CNC machined component also depends on:

  • CNC machine capability
  • Machine condition
  • Fixture rigidity
  • Cutting-tool selection
  • Cutting parameters
  • Workpiece material
  • CAM strategy
  • Gereedschapsslijtage
  • Thermal conditions
  • Inspectiemethoden
  • Process control

A well-developed CNC program therefore works together with manufacturing engineering rather than replacing it.

How Does Tuofa CNC Germany Handle CNC Programming for Custom Parts?

Customers working with Tuofa CNC Duitsland normally do not need to create their own G-code before requesting custom CNC machining.

Instead, customers should provide the information that defines the required component and its manufacturing requirements, such as:

  • STEP or STP model
  • Engineering drawing
  • Materiaalspecificatie
  • Dimensional tolerances
  • Geometric tolerances
  • Thread requirements
  • Critical machined features
  • Vereisten voor oppervlakteruwheid
  • Surface treatment requirements
  • Required production quantity

Based on this information, the machining process can be developed around the actual part geometry, tolerances, material, and functional requirements.

For example, a CNC machined component may contain a deep pocket, thin wall, precision bore, several threaded holes, and tight positional tolerances. Simply generating G-code from the CAD model is not enough. The manufacturing process must also consider tool accessibility, machining sequence, workholding rigidity, deformation risk, tolerance relationships, and inspection requirements.

For complex CNC milled components, CAM programming can be used to develop suitable roughing and finishing toolpaths before those toolpaths are post-processed for the intended machining equipment.

CNC turning programs can similarly be planned according to required diameters, bores, grooves, threads, surface finish, and tolerance requirements.

This means the customer’s main responsibility is to clearly define what the component must achieve. The manufacturing team determines how the CNC equipment should produce it.

When a design contains features that may increase machining difficulty or cost unnecessarily, a manufacturability review can also identify possible design improvements before production.

Send your CAD model and engineering drawing to Tuofa CNC Germany for CNC machining review and quotation.

Frequently Asked Questions About G-Code

Is G-code the same for every CNC machine?

No. Many basic programming concepts are shared between CNC machines, but specific commands, syntax, cycles, and supported functions can differ according to the machine type and controller.

What is G-code in a CNC machine?

G-code provides machine-readable instructions that tell the CNC controller how to perform programmed movements and machining functions.

What are G codes?

G codes are preparatory commands used within CNC programs. Depending on the controller, they can control functions such as rapid positioning, linear interpolation, circular interpolation, coordinate modes, unit selection, and machining cycles.

Is G-code used for CNC milling?

Yes. CNC milling machines use G-code-based programs to control tool positioning, interpolation, drilling, pocketing, contouring, and many other machining operations.

Is G-code used for CNC turning?

Yes. CNC lathes and turning centers also use G-code programming, although particular command meanings and cycles may differ from CNC milling machines.

What is the G01 CNC code?

G01 commonly commands controlled linear interpolation at a programmed feed rate.

What is G00?

G00 is commonly used for rapid positioning between machining locations.

What does G80 do in CNC?

G80 commonly cancels an active canned machining cycle. The actual function should always be verified for the intended controller.

What does G21 mean in G-code?

G21 commonly selects metric programming units on many CNC controls.

What does G20 mean in G-code?

G20 commonly selects inch programming units on many CNC controls.

Can CNC machines read CAD files directly?

A CAD model defines the required geometry, but conventional CNC machining normally requires CAM programming, toolpath generation, and post processing before machine-compatible instructions can be executed.

Can you generate G-code automatically?

Yes. CAM software can calculate CNC toolpaths and use a suitable post processor to generate machine-compatible G-code. The machining strategy and final program still need to be reviewed and verified.

Do machinists still write G-code manually?

Yes. Manual programming remains useful for simple operations, program modifications, setup adjustments, and troubleshooting. Complex components are more commonly programmed using CAM-generated toolpaths.

Is G-code the same as CNC programming?

Not exactly. G-code is an important part of CNC programming, but complete CNC programming also includes setup planning, workholding, cutting-tool selection, feeds and speeds, offsets, CAM strategies, M codes, post processing, and program verification.

Conclusion

Understanding what is G code starts with a simple concept: G-code converts a CNC machining strategy into instructions that a CNC controller can execute.

Commands such as G00 and G01 control fundamental machine movement, G20 and G21 define programming units, and G80 can cancel a canned machining cycle. Other G codes control coordinate systems, interpolation methods, compensation, and machine-specific machining functions.

However, learning a G code commands list is only the beginning. In production machining, command meanings can depend on the CNC machine and controller, while the quality of the finished part depends on much more than the program itself.

CAD geometry, CAM strategy, post processing, cutting tools, workholding, machining parameters, CNC machine capability, and inspection all work together to convert a digital design into a finished precision component.

For customers working with Tuofa CNC Duitsland, you generally do not need to learn how to write G code or provide a .gcode program. Provide a complete CAD model, engineering drawing, material, tolerances, and other manufacturing requirements so the CNC machining process can be developed around the actual functional requirements of your custom part.

Categories
Latest Articles
CNC Quote Services
Custome parts
made easier, faster
Get a quotation
Please attach your 2D CAD drawings and 3D CAD models in any format including STEP, IGES, DWG, PDF, STL, etc. If you have multiple files, compress them into a ZIP or RAR. Alternatively, send your RFQ by email to andylu@tuofa-machining.com.

Privacy*

As with all our customers, confidentiality remains vital in demonstrating our commitment to customer service. You can feel reassured that we will gladly complete disclosure forms for your applications and your applications will solely be used for quotation purposes.