PAGES

Page Default Description.

BLOG

G-Code and M-Code: The Backbone of CNC Programming

G-code and M-code are the two languages every CNC program is written in. They turn a designer's drawing into the precise, repeatable cuts that modern manufacturing runs on. If you run a CNC machining center for EV battery trays, or you program a 5-axis gantry machining center for aerospace parts, these codes are doing the work. DELICNC has built vertical, gantry, and profile machining centers since 2008, and all of them follow the same programming logic. Learn the two codes and you can get a lot more out of the machine on your floor.

What Are G-Code and M-Code in CNC Programming?

A CNC machine does not read a drawing. It reads a list of instructions. A program is a plain text file split into numbered lines, and most lines mix two things:

  • G-code (preparatory code) tells the machine how to move: which line or arc, at what feed rate, from which coordinate.

  • M-code (miscellaneous code) covers everything around the cut, like starting the spindle, turning on coolant, or stopping the program.

Put them together and you have CNC programming. G-code shapes the part. M-code runs the machine. You cannot really do one without the other.

G-Code: Guiding Tool Motion

G-code drives the toolpath, which is the actual shape of the cut. It sets position with coordinates (X, Y, Z, plus rotary A/B/C) and parameters like feed rate (F) and spindle speed (S). On a CNC vertical machining center or a gantry machining center, G-code is what turns a 3D model into real parts.

One thing that trips up beginners is modal behavior. A command like G90 (absolute positioning) stays in effect until you switch it with G91 (incremental). Set it once and the machine keeps using it, line after line, instead of you typing it every time.

Common G-Code Commands

CodeFunctionTypical use at DELICNC
G00Rapid positioning (non-cutting, max speed)Move to start point before a cut on aluminum profiles
G01Linear interpolation (straight cut at feed rate)Profile milling on curtain wall sections
G02 / G03Circular interpolation (CW / CCW arcs)Corner radii, boss profiles, hole chamfers
G17 / G18 / G19Select XY / ZX / YZ planeMulti-face work on 5-axis profile centers
G54–G59Work coordinate offsetsBatch machining multiple parts in one fixture
G81Drilling cycleHole patterns in EV battery tray brackets
G90 / G91Absolute / incremental positioningSetup consistency across shifts
G28Return to machine reference pointSafe retract before tool change

Why G-Code Matters for Aluminum and Curtain Wall Machining

Aluminum and thin-wall curtain wall sections do not forgive mistakes. Push the feed too hard or pick the wrong arc move and you get burrs, warping, or chatter. G-code for surface machining lets the operator control exactly how the tool enters, cuts through, and pulls away from the material. On a 5-axis profile machining center, the compound-angle cuts and multi-face drilling that curtain wall mullions need are built entirely from G-code. Write the program clean and your surface finish and cycle time both improve.

M-Code: Managing Machine Auxiliary Functions

M-code handles the jobs that are not about movement. It starts and stops the spindle, runs coolant, opens the door, triggers a tool change, and ends the run. In a busy CNC machine shop, getting M-code right is the difference between a clean shift and a crashed spindle.

Most M-codes run once and stop. M00, for example, parks the program until someone hits resume. A few are modal, like M03 (spindle on, clockwise), which stays on until M05 turns it off.

Common M-Code Commands

CodeFunctionWhere you'll see it
M03 / M04Spindle on (CW / CCW)Every cutting cycle on vertical & gantry centers
M05Spindle stopTool changes, inspection, end of run
M06Automatic tool changeMulti-tool aluminum profile machining
M08 / M09Coolant on / offHigh-speed milling to control heat
M00 / M01Program stop / optional stopSetup checks, first-article inspection
M30Program end + rewindStandard end-of-program on DELICNC controls
M98 / M99Call / return from subprogramRepeatable features, macros

G-Code vs M-Code: Key Differences

AspectG-CodeM-Code
Primary roleControls tool motion (lines, arcs, planes)Manages auxiliary tasks (spindle, coolant, flow)
Typical commandsG00 rapid, G01 linear, G02/G03 arcM03 spindle on, M08 coolant, M30 end
StructureCoordinates + parameters (X, Y, Z, F, S)Standalone or simple parameters (T, S)
Modal behaviorMostly modal (persists until changed)Mostly non-modal (single execution)
StandardizationHighly standardized (ISO 6983-based)Varies by control brand, verify in the manual

Here is the simplest way to put it: G-code picks where the tool goes. M-code picks what the machine does while it is getting there.

How G-Code and M-Code Work Together

A real program stacks both codes on the same lines. Here is a short example on a gantry machining center cutting an aluminum bracket:

LineCommandDescription
N10G90 G54 G17Absolute positioning, work offset, XY plane
N20M03 S1200Start spindle at 1200 RPM
N30G01 X50 Y30 F200Linear cut to (X50, Y30) at 200 mm/min
N40M08Activate coolant
N50G01 X100 Y50Continue linear cut
N60M05Stop spindle
N70M09Deactivate coolant
N80M30End program and rewind

Typical Programming Flow

  1. Setup. G-codes set the coordinate system and work offset. M-codes start the spindle and coolant.

  2. Machining. G-codes run every cut and arc. M-codes handle the pauses, tool changes, and coolant.

  3. Shutdown. G-codes send the tool back to a safe point (G28). M-codes stop the spindle, kill the coolant, and end the program (M30).

G-Code and M-Code Across DELICNC Machining Centers

DELICNC machines run on standard controls from FANUC, Siemens, and Mitsubishi. That means everything above applies to every machine we build:

  • CNC Vertical Machining Center. The 4-axis models handle precision milling for automotive and 5G parts, where tight G-code tolerance and reliable M-code tool changes keep cycle times down.

  • 5-Axis CNC Gantry Machining Center. Big parts like rail-transit aluminum extrusions use G17 to G19 plane selection and compound G-code moves, timed with M08 coolant to manage heat.

  • 5-Axis Profile Machining Center. Built for curtain wall CNC fabrication: compound-angle cutting, multi-face drilling, and mullion milling all run on structured G-code, with M06 swapping tools between drilling and milling.

  • Double Head Sawing Machines. Even the sawing cells use M-code for clamp, feed, and cut sequencing alongside positioning G-code.

Buying tip: when you compare machines, ask what is in the control's G-code cycle library (G81 drilling, G83 peck drilling) and whether it supports M98 subprograms. A deeper library means less hand-coding and a faster start on production parts.

Common CNC Programming Pitfalls

  • Sequence errors. Always call M03 (spindle on) before G01 (cutting). Cutting with a stopped spindle ruins the tool and the part.

  • Missing reference return. Send the axis home with G28 before an M06 tool change, or you risk a crash on gantry and profile centers.

  • Brand-specific M-codes. Coolant, door, and tool-change codes differ by control. Check the manual before the first run.

  • Over-stuffed programs. Long, repetitive code is a pain to debug. Use M98 subprograms for repeated features so the main program stays readable.

  • No dry run. Test new programs in single-block mode before you cut into aluminum.

FAQs

What is the difference between G-code and M-code?

G-code controls tool motion, position, feed, and cutting geometry. M-code controls the machine's auxiliary functions: spindle, coolant, and program flow. G-code shapes the part. M-code runs the machine around the cut.

Is G-code the same on every CNC machine?

The core set (G00, G01, G02/G03, G90, G54, and so on) follows the ISO 6983 standard and stays fairly consistent. Some advanced cycles and M-codes still differ between control brands such as FANUC, Siemens, and Mitsubishi, so check the manual.

Can G-code and M-code be on the same line?

Yes. A line such as M03 S1200 next to a G01 move is normal. Just keep the order logical: spindle and coolant should be running before the cutting move starts.

How does CNC programming affect aluminum profile machining?

Aluminum is soft but it burrs and warps under heat. Well-structured G-code (controlled feed, sensible arc strategy, correct plane selection) plus steady M-code coolant control gives cleaner edges and tighter tolerances. That matters for curtain wall and EV battery tray parts.

Which DELICNC machine is best for curtain wall fabrication?

The 5-axis profile machining center is built for curtain wall systems, with compound-angle cutting and multi-face drilling. For larger panelized components, the 5-axis gantry machining center is the better fit.

Conclusion

G-code and M-code sit at the center of CNC programming. G-code shapes the workpiece with precise, repeatable motion. M-code keeps the machine safe and running. If you are cutting aluminum profiles, machining EV battery trays, or building curtain wall systems on a DELICNC vertical, gantry, or profile machining center, knowing both codes pays off fast.

Want better programs behind better hardware? Contact DELICNC to talk through the right CNC machining center for your work, or request a quote and our engineering team will match the machine, control, and process to your parts.