G-CODE FUNDAMENTALS

A Complete Introduction to G-code: From ISO 6983 to AI Generation in One Read

What is G-code? A complete beginner's guide from ISO 6983 to AI-generated G-code — article cover
TL;DR What is G-code? It's the programming language a CNC machine understands, made up of line-by-line "blocks" that step by step direct the tool to move, cut, and change tools, with an address-word format defined by the international standard ISO 6983. The core commands include the four motion modes G00/G01/G02/G03, the F (feed) / S (spindle speed) / T (tool change) / M (miscellaneous function) codes, and the G54 work coordinate system. This article breaks these commands down line by line using a readable G-code example, explains why the same program often can't be run straight on a different machine (controller dialects), and finally covers what AI-generated G-code can and can't do — AI can speed up the draft, but cutting simulation and a senior technician's sign-off are still needed before the job runs.

01What is G-code? The common language of CNC

G-code (also called G code or the NC program) is the programming language a CNC (Computer Numerical Control) machine understands. The simplest way to answer "what is G-code" is: it's a line-by-line list of motions, each line telling the machine which coordinate to move the tool to, whether to travel in a straight line or an arc, how fast to feed, and how fast the spindle turns — the machine's controller reads one line and executes it, then moves on. Milling machines, lathes, and machining centers can share similar commands because the address words of G-code are defined by the international standard ISO 6983[1].

In the framework of manufacturing engineering, G-code sits at the very end of the "design → process planning → machining" chain: CAD draws the part, CAM decides the toolpaths, and finally the output is the G-code the machine actually runs. Classic textbooks stress that the value of numerical control lies in encoding machining motions precisely and repeatably, so complex geometry can be produced stably in volume[2]. In other words, reading G-code is reading exactly what commands the "last mile" of CNC machining is issuing.

02What a piece of G-code looks like: a line-by-line breakdown

Rather than memorizing a command table, it's better to look at a real program. Below is a simplified piece of face-milling G-code (milling the top surface of a plate flat), with the comments on the right explaining what each line does:

%
O1000 (SLIDE PLATE FACE milling program)
G21 G17 G40 G49 G80   metric / XY plane / cancel cutter radius and length comp / cancel canned cycle
G54                   select work coordinate system #1
T1 M06                load tool #1 (face mill D50)
S1200 M03             spindle clockwise at 1200 rpm
G00 X-30. Y0.         rapid positioning to the start point (non-cutting move)
G43 H01 Z50.          enable tool #1 length comp, Z to safe height
G00 Z2.               rapid down to 2 mm above the workpiece
G01 Z0. F150.         linear feed plunge to Z0, feed 150 mm/min
G01 X130. F400.       linear cutting, travel along X across the workpiece surface
G00 Z50.             rapid retract to safe height
M05                   spindle stop
M30                   end program and return to the top
%

Each line is called a "block," made up of an address word plus a value: G is a preparatory function, M is a miscellaneous function, X/Y/Z are coordinates, F is feed, S is spindle speed, and T is the tool number. It is exactly this set of address words and program format that ISO 6983 specifies[1]. Once you grasp the structure of "one motion per line, stacked from letters + numbers," any piece of G-code can be read line by line.

03Motion commands: G00/G01/G02/G03 and G54 coordinates

The most-used and most important G-codes to understand first are the four motion commands:

CommandMotionTypical use
G00Rapid positioning (machine's max speed)Tool travels to the next position without cutting
G01Linear cutting feed (needs F)Removes material along a straight line, the workhorse of most milling
G02Clockwise circular interpolationCutting arcs, filleting (CW)
G03Counterclockwise circular interpolationCutting arcs, filleting (CCW)

Beginners most often confuse G00 and G01: G00 is "getting there" — moving the tool to a point at maximum speed, without guaranteeing the path is a precise straight line, so it can only be used for non-cutting moves that aren't touching the workpiece; G01 is what actually "cuts," removing material along a straight line at the feed rate set by F. G02/G03 replace the straight line with an arc, differing only in clockwise or counterclockwise direction.

All these coordinates need an origin datum, which is the role of the G54 work coordinate system. G54–G59 let the operator map the coordinates in the program to the actual position of the workpiece clamped on the machine — once the G54 zero is set, the program doesn't have to be rewritten just because the workpiece is clamped in a different corner of the table. Note that choosing the wrong coordinate system or setting the zero incorrectly shifts the entire toolpath, one of the common causes of a crash — which is exactly why pre-run simulation verification can't be skipped (further reading: crash prevention and cutting simulation).

04F/S/T/M codes: feed, spindle speed, tool change, and miscellaneous functions

Motion commands decide "where to go"; the F/S/T/M codes decide "how to go and what to cut with":

F and S are not numbers filled in at random. Authoritative texts on cutting mechanics and CNC design point out that feed, spindle speed, and depth of cut must be chosen according to the mechanics and vibration characteristics of the tool–workpiece system; otherwise, at best you get poor accuracy and tool marks, and at worst chatter, tool breakage, or even a crash[3]. In practice, these parameters should be bounded by the shop's standard cutting parameters in the tool crib, not entered on a hunch — which is also why AI generating G-code must treat the shop's parameters as constraints.

05Controller dialects: why you can't just run it on a different machine

Many people assume that since G-code has an international standard, one program should run everywhere. The reality is: ISO 6983 only specifies the basic address words and format, and each controller has developed its own "dialect" for canned cycles, macros, header codes, and parameter calls. Academia has long noted that G-code only describes the tool's low-level motion, retains no design or process information, and — combined with the limited scope of the standard — leads to poor interoperability between controllers and programs that are hard to port directly[4].

Concretely, moving the same program from a FANUC controller to a Mitsubishi or Heidenhain one may run into: different parameter syntax for drilling canned cycles (G81/G83), a different order for tool change and spindle startup, and incompatible subprogram and macro syntax. Add in that every machine has a different tool crib, travel range, and fixtures, and "copying it straight onto the machine" is almost bound to cause trouble. The right approach is: a different machine equals a different set of requirements, so the program must be re-adjusted and re-verified with a fresh 3D cutting simulation. This is exactly the reason the post processor of CAM software such as Mastercam exists, and why AI CAM must factor the controller model into the generation flow.

06From hand-writing to AI-generated G-code

Early programmers hand-wrote G-code line by line; later, CAM software let engineers plan toolpaths graphically and then output the program, sharply lowering the error rate. AI-generated G-code is one more extension of this line: recognizing a customer's 2D drawing as machining features, building a 3D model, and then automatically drafting an executable program according to the shop's tool crib, controller model, and travel/speed limits (further reading: how AI turns a 2D drawing into verifiable G-code). The engineer's role shifts from "operating cell by cell" to "reviewing and correcting."

But automatic generation doesn't mean you can run it blindly. The controller dialects, the mechanical limits of the F/S parameters, and the G54 zero and clamping conditions discussed above are all things AI may not judge sufficiently; tolerances, datums, and special methods further involve assembly intent and shop-floor experience. So the reliable implementation pattern is human-in-the-loop: AI reads the drawing, models, generates code, and cross-checks — accelerating the most time-consuming prep work — while a senior technician completes the cutting simulation and final sign-off before the job runs, confirming length compensation, lead-in/lead-out, and travel safety. This is also the consistent boundary of this site's product — AI accelerates prep, the machinist keeps the final judgment.

In one sentence: G-code is the execution language of CNC, and ISO 6983 gives a common skeleton, but dialects, parameters, and shop-floor conditions make "one program runs everywhere" a myth. AI can make the draft fast and consistent; the last gate still goes back to a human.

07FAQ

What is G-code, and how does it relate to CNC?

G-code is the programming language a CNC machine understands, made up of line-by-line "blocks" that step by step tell the machine which coordinate to move the tool to, and at what feed and spindle speed to cut. Its address-word format is defined by ISO 6983, and it is the common foundational control language for milling machines, lathes, and machining centers.

What is the difference between G00 and G01?

G00 is rapid positioning, moving the tool to a target point at the machine's maximum speed for a non-cutting move; it does not guarantee straight-line cutting accuracy. G01 is a linear cutting feed that must be paired with an F feed rate to remove material along a straight line. G00 is for "getting there," while G01 is what actually "cuts."

Can the same G-code be run straight on a different machine?

Usually not. ISO 6983 only specifies the basic format; different controllers have dialect differences in canned cycles, macros, and header codes, and with different tool cribs, travels, and fixtures, the program must be adjusted and re-verified with a fresh simulation before running on a different machine — it cannot simply be copied over.

Can AI-generated G-code be run straight on the machine?

Not recommended. AI-generated G-code can greatly speed up programming, but controller dialects, cutting parameters, tolerances, and shop-floor methods still need a senior technician's review and a 3D cutting simulation first to confirm there are no gouges, interference, or travel overruns. The right pattern is a human-in-the-loop flow where AI accelerates the draft and a professional does the final sign-off.

Subscribe to the technical blog newsletter

Get notified when new articles and video briefings go live — no inbox spam, one-click unsubscribe. (newsletter in Chinese)

FROM DRAWING TO VERIFIED G-CODE

Take one real drawing and see how far AI-generated G-code goes

From drawing recognition, tool-crib and controller setup to cutting simulation and machinist review, we help define an AI programming rollout that fits your shop.

Contact an implementation consultant Training courses

← Back to the BestAI CAM product overview

08References

  1. ISO 6983-1:2009. Automation systems and integration — Numerical control of machines — Program format and definitions of address words. International Organization for Standardization.
  2. Kalpakjian, S., & Schmid, S. R. (2020). Manufacturing Engineering and Technology (8th ed.). Pearson.
  3. Altintas, Y. (2012). Manufacturing Automation: Metal Cutting Mechanics, Machine Tool Vibrations, and CNC Design (2nd ed.). Cambridge University Press.
  4. Xu, X. W., & Newman, S. T. (2006). Making CNC machine tools more open, interoperable and intelligent — a review of the technologies. Computers in Industry, 57(2), 141–152.