CNC Machining

G and M Codes in CNC: Motion, Machine Functions and Program State

Read common CNC G and M codes in context. Understand modal states, coordinates, offsets, program review and machine-specific compatibility.

G and M codes communicate machining instructions to a CNC control. Understanding them means reading a block in the context of the program state, selected coordinate system, tools and physical setup. Recognizing a familiar command is useful, but it does not establish where the cutter will move on a particular machine.

This guide explains common code families and how to review their meaning. The examples illustrate concepts; command support, option behavior and the approved operating procedure belong to the documentation for the actual machine and controller.

G codes, M codes and the other program words

G codes commonly select motion modes, coordinate interpretation and machining functions. M codes commonly control auxiliary machine functions or program behavior. Those categories are useful starting points, not a universal guarantee that every machine assigns a number in the same way.

A program also contains words that identify positions, speeds, feeds, tools or offsets. The letter and value must be read together with the active mode. An X value can be an absolute position or an incremental change, and an F value depends on the active feed interpretation.

Program elementTypical roleReview question
G wordSelect a motion or preparation function.Which modes and groups does this control support?
M wordRequest an auxiliary or program function.What does this machine do when the command is executed?
X, Y, Z or rotary-axis wordsDescribe commanded axes or positions.Which origin, units and coordinate interpretation apply?
F and S wordsDescribe feed and spindle-related values.How are the values interpreted in the active mode?
Tool and offset wordsRefer to tools or stored corrections.Do the references match the loaded tool and setup record?

A short G code list for reading programs

The following names are common in milling documentation. They are an orientation aid rather than a machine-independent programming specification. A turning control, a special machine or a different option set can have important differences.

Common commandCommon milling meaningWhat must also be known
G00Rapid positioning.The full rapid path and fixture clearance.
G01Linear feed motion.Active feed interpretation and commanded destination.
G02 / G03Circular interpolation directions.Plane, arc definition and controller convention.
G17 / G18 / G19Plane selection.The operation and supported interpolation behavior.
G20 / G21Inch or metric units.Consistency of program values, offsets and setup.
G90 / G91Absolute or incremental positioning.The position from which each coordinate is interpreted.
G54A work coordinate system selection on many controls.The work offset actually stored on the machine.

A CNC G code list can explain names, but cannot describe the machine’s current physical condition. Keep the applicable control reference, machine configuration and setup information together when reviewing an output file.

How M codes fit the operation sequence

Common milling examples include M03 for a spindle direction command, M05 for spindle stop, M06 for a tool change and M08 or M09 for coolant control. The exact supported functions and their implementation must be checked on the equipment in use.

The sequence matters. A tool-change request belongs to a machine with a particular tool-changing arrangement and defined clearance behavior. An auxiliary command can depend on installed equipment or machine-builder logic. Do not transfer a list of functions between machines merely because their motion commands look similar.

Program stops, optional stops, subprogram calls and end commands are also controller-dependent parts of the workflow. The review must include how the program enters, pauses, resumes and finishes, not just the lines that remove material.

A modal instruction remains active until another relevant instruction replaces or cancels it under the control’s rules. A non-modal instruction applies according to its defined scope. Knowing the distinction helps explain why a block can be incomplete when read by itself.

For example, after a linear-motion mode has been selected, a later block containing only axis values may continue that motion mode. A reader who sees only the later coordinates has not yet established how the control will interpret them. Review the preceding state as well as the visible words in the current block.

A program restart requires particular care because the required prior state may differ from the state left active on the machine. Follow the machine’s approved restart procedure. Selecting an arbitrary line is not equivalent to recreating the intended units, tool, offsets, spindle state and position.

Separate programmed coordinates from the physical setup

In absolute positioning, a commanded coordinate refers to a position in the active coordinate system. In incremental positioning, it represents a change relative to the defined current reference. A repeated X word can therefore produce different motion when the interpretation changes.

Work offsets connect a programmed origin to the location of the workpiece. Tool offsets account for measured tool information according to the control and machining method. An error in either can affect the physical result even if the nominal part geometry and toolpath are correct.

For a bracket drawing that locates holes from a finished edge, the setup must explain how the physical locating surfaces relate to that drawing datum. A code review cannot replace that transfer plan. Inspection of the first part then checks whether the planned references produced the specified geometry.

Example: investigate a shifted hole pattern

Consider a program that produces the right hole spacing, but the whole pattern appears displaced relative to the required edge. This observation suggests a different investigation from a case in which individual holes have the wrong spacing.

First establish the released drawing, program revision and intended datum scheme. Compare the active work offset and physical part location with the setup record. Then review how the program selected its coordinate system and how the origin was transferred between operations. Do not immediately edit every hole coordinate to compensate for an unexplained setup discrepancy.

If the location issue is corrected, inspect the part using the same functional datum basis as the drawing. Keep the corrected setup information with the program so that the next batch does not repeat an undocumented adjustment. This is an illustrative reasoning example, not a report of a specific production job.

A practical NC program review sequence

  1. Confirm the part, drawing revision, program and machine configuration.
  2. Identify the stock, locating surfaces, work origin, fixtures and tool assemblies.
  3. Read the initial units, coordinate interpretation and required active modes.
  4. Follow tool changes and transitions, including non-cutting approaches and retracts.
  5. Check how the output refers to tools, offsets and auxiliary functions.
  6. Use verification appropriate to the posted program and modeled setup.
  7. Apply the approved machine-specific prove-out procedure and inspect the first article.

A useful review record identifies what was checked and which revisions were used. It should allow another qualified person to understand the intended setup without relying on an operator’s memory of a previous run.

Common questions about CNC programming codes

Are G codes and M codes universal?

Many functions share familiar conventions, but supported commands and machine behavior differ. Check the control and machine documentation for the actual configuration, especially special cycles and auxiliary equipment.

Does CAM eliminate the need to understand the output?

No. CAM and a suitable post can automate much of the program creation, but the output still depends on the selected machine, post settings and manufacturing setup. Review the generated instructions and use the required verification process.

Can I reuse a program on another machine?

Only after checking compatibility and adapting the complete manufacturing setup where required. A different machine, control, tool library or fixture arrangement can change the necessary output and validation.

Do customers need to supply G code when ordering parts?

Usually the manufacturing supplier needs the released design, material, quantity and acceptance requirements. Discuss program ownership and reuse separately where they are part of the contract. Sending an NC file without setup information does not fully define the part.

Reference sources and next steps

For a custom component, prepare the model, drawing and inspection requirements for a CNC machining review.

Get More Information

Send us your project requirements. Our engineers will get back to you.

BoValley Project Inquiry / 项目询盘

Accepted files: PDF or ZIP, up to 10 MB per file, maximum 3 files. Put STEP, IGES, STL or DXF CAD files in a ZIP archive before uploading.

Uploading drawings or CAD files is optional. Read how we handle design files. If you need to discuss confidentiality first, send your project requirements without attaching files.

Ready to Start Your Next Manufacturing Project?

Share your CAD files and project requirements. An engineer will review the details and follow up with pricing and any manufacturability questions.