
G-code (Geometric code) is the fundamental programming language that controls Computer Numerical Control (CNC) machines. Every movement, speed change, tool change, and auxiliary function executed by a CNC mill, lathe, router, or EDM machine is ultimately driven by G-code instructions. Understanding G-code is essential for manufacturing engineers, CNC programmers, and anyone involved in precision machining operations.
What Is G-Code?
G-code is a numerical control programming language standardized under ISO 6983 and RS-274. It uses letter-address codes — “G” commands for geometry (motion), “M” commands for miscellaneous machine functions, and letter prefixes for parameters such as feed rate (F), spindle speed (S), and tool number (T).
A typical G-code block looks like this:
G01 X10.500 Y5.250 F50.0 ; Linear interpolation at 50 ipm feed rate
G-Code Command Categories
G-Codes (Motion and Geometry)
| Command | Function |
|---|---|
| G00 | Rapid positioning (non-cutting move) |
| G01 | Linear interpolation (straight-line cutting) |
| G02 / G03 | Circular interpolation (clockwise / counterclockwise) |
| G17 / G18 / G19 | Plane selection (XY / ZX / YZ) |
| G20 / G21 | Units (inches / millimeters) |
| G40 / G41 / G42 | Cutter compensation (off / left / right) |
| G43 / G49 | Tool length offset (on / off) |
| G54-G59 | Work coordinate systems (WCS) |
| G80-G89 | Canned cycles (drilling, boring, tapping) |
| G90 / G91 | Distance mode (absolute / incremental) |
M-Codes (Machine Auxiliary Functions)
| Command | Function |
|---|---|
| M00 | Program stop (operator intervention required) |
| M03 / M05 | Spindle on (CW) / Spindle stop |
| M06 | Tool change |
| M08 / M09 | Coolant on / Coolant off |
| M30 | Program end and rewind |

From CAD to G-Code: The CAM Workflow
CNC operators rarely write G-code manually for production parts. Instead, the workflow follows:
- CAD Modeling: Engineer creates 3D model with geometric dimensions and tolerances
- CAM Programming: CAM software (Mastercam, Fusion 360, SolidWorks CAM) imports the CAD model and generates toolpaths
- Post-Processing: The CAM post-processor translates generic toolpaths into machine-specific G-code syntax
- Verification: G-code simulation detects collisions, over-travel, and cycle time issues
- Machine Execution: G-code is loaded to the CNC controller and executed
Absolute vs. Incremental Programming
G-code supports two distance modes:
- Absolute (G90): All coordinates are referenced from the program zero (G54 work coordinate system). X10.0 always means “move to X=10.0 in the current WCS.” Safer and more widely used.
- Incremental (G91): Coordinates are relative to the current tool position. X10.0 means “move 10.0 units from where you are.” Used for patterns and repetitive features.
Common G-Code Programming Mistakes
- Missing Tool Length Compensation (G43): Causes Z-depth errors and potential crashes
- Incorrect Work Offset (G54 vs G55): Causes parts to be machined in the wrong location
- Rapid Moves (G00) Too Close to Workpiece: Causes tool breakage or part scrap
- Wrong Units (G20 vs G21): 25.4x scaling error between inches and millimeters
- Missing Cutter Compensation (G41/G42): Results in undersized or oversized features
Похожие статьи
Explore our complete guide to engineering plastics and precision manufacturing. For material-specific guidance, review our technical articles on CNC processes, tooling, and manufacturing optimization.
Часто задаваемые вопросы
What are the main advantages of this manufacturing process?
Precision, repeatability, and material flexibility are the primary advantages. Modern CNC processes achieve tolerances of ±0.001 inches and produce identical parts across production runs. Material selection is virtually unlimited, and design changes require only reprogramming rather than new tooling.
How do I choose between different manufacturing methods?
Consider production volume, tolerances, material properties, and lead time. CNC machining excels at low-to-mid volumes and design flexibility. Injection molding dominates high-volume production. EDM processes address hard materials and complex internal geometries. Water jet cutting provides cold-cutting for sensitive materials.
What quality standards should I require from suppliers?
Require ISO 9001:2015 certification as a baseline. For aerospace, AS9100; for medical, ISO 13485; for automotive, IATF 16949. Request sample inspection reports, CMM capabilities documentation, and material certifications with every production batch.
How can I reduce manufacturing costs without sacrificing quality?
Optimize designs for machinability: increase tolerances where functionally acceptable, use standard tool sizes, minimize setups by designing features accessible from one orientation, and consider whether CNC or molding is more cost-effective at your volume.


