G-Code and M-Code: The Backbone of CNC Programming
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
Code Function Typical use at DELICNC G00 Rapid positioning (non-cutting, max speed) Move to start point before a cut on aluminum profiles G01 Linear interpolation (straight cut at feed rate) Profile milling on curtain wall sections G02 / G03 Circular interpolation (CW / CCW arcs) Corner radii, boss profiles, hole chamfers G17 / G18 / G19 Select XY / ZX / YZ plane Multi-face work on 5-axis profile centers G54–G59 Work coordinate offsets Batch machining multiple parts in one fixture G81 Drilling cycle Hole patterns in EV battery tray brackets G90 / G91 Absolute / incremental positioning Setup consistency across shifts G28 Return to machine reference point Safe 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
Code Function Where you'll see it M03 / M04 Spindle on (CW / CCW) Every cutting cycle on vertical & gantry centers M05 Spindle stop Tool changes, inspection, end of run M06 Automatic tool change Multi-tool aluminum profile machining M08 / M09 Coolant on / off High-speed milling to control heat M00 / M01 Program stop / optional stop Setup checks, first-article inspection M30 Program end + rewind Standard end-of-program on DELICNC controls M98 / M99 Call / return from subprogram Repeatable features, macros
G-Code vs M-Code: Key Differences
Aspect G-Code M-Code Primary role Controls tool motion (lines, arcs, planes) Manages auxiliary tasks (spindle, coolant, flow) Typical commands G00 rapid, G01 linear, G02/G03 arc M03 spindle on, M08 coolant, M30 end Structure Coordinates + parameters (X, Y, Z, F, S) Standalone or simple parameters (T, S) Modal behavior Mostly modal (persists until changed) Mostly non-modal (single execution) Standardization Highly 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:
Line Command Description N10 G90 G54 G17Absolute positioning, work offset, XY plane N20 M03 S1200Start spindle at 1200 RPM N30 G01 X50 Y30 F200Linear cut to (X50, Y30) at 200 mm/min N40 M08Activate coolant N50 G01 X100 Y50Continue linear cut N60 M05Stop spindle N70 M09Deactivate coolant N80 M30End program and rewind
Typical Programming Flow
Setup. G-codes set the coordinate system and work offset. M-codes start the spindle and coolant.
Machining. G-codes run every cut and arc. M-codes handle the pauses, tool changes, and coolant.
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:
. 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.
. 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.
. 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?

