Free Browser-Based CAD/CAM for CNC & Laser Cutting — Design Swiftly

All Articles
Tutorials 8 min readApril 10, 2026

G-Code for Beginners: What Every CNC Maker Needs to Know

G-Code is the language your CNC machine speaks. This guide demystifies G0, G1, G2, G3, M3, M5 and shows you how to read, generate, and optimize G-code without memorizing every command.

M
· CNC Specialist & Lead Developer
G-CodeCNCTutorial

G-Code is the universal language spoken by CNC routers, laser engravers, 3D printers, and milling machines. Once you understand its basic structure, you can read, edit, and even write G-code files — and fix problems that automated generators miss.

The Structure of G-Code

Each line of G-code is called a block. It contains one or more words — a letter followed by a number. The most common letters are:

LetterMeaningExample
GMotion / mode commandG0 (rapid move)
MMiscellaneous commandM3 (spindle on)
X Y ZAxis positionsX10.5 Y25.0 Z-3.0
FFeed rate (mm/min)F1200
SSpindle speed (RPM)S18000

The Essential G-Code Commands

G0 — Rapid Move (Air Move)

G0 moves the tool to a position as fast as possible — used for repositioning between cuts, not for cutting. The spindle should be off or raised above the material.

gcode
G0 Z5.0       ; Raise the tool to 5mm above material
G0 X0 Y0      ; Move to origin (rapid)

G1 — Linear Feed Move (Cutting)

G1 moves in a straight line at the specified feed rate. This is the cut command. Always include an F value the first time, or the machine may error.

gcode
G1 Z-3.0 F300    ; Plunge into material 3mm at 300mm/min
G1 X100.0 F1200  ; Cut 100mm along X at 1200mm/min

G2 / G3 — Arc Move

G2 is a clockwise arc; G3 is counter-clockwise. Both require I/J offsets (the arc centre relative to the start point) or an R value (radius).

gcode
G2 X20 Y0 I10 J0 F800   ; CW arc, centre is 10mm right of current position
G3 X0 Y20 R20 F800       ; CCW arc with radius 20mm

M3 / M5 — Spindle On / Off

M3 S18000 turns the spindle on at 18,000 RPM. M5 stops the spindle. Always include a dwell (G4 P2) after M3 to let the spindle reach speed before cutting.

gcode
M3 S18000    ; Spindle on at 18,000 RPM
G4 P2        ; Wait 2 seconds for spindle to reach speed
G0 X10 Y10   ; Rapid to start position
...
M5           ; Spindle off

A Complete G-Code Job Header (GRBL)

Design Swiftly generates this safety header automatically at the start of every G-Code file:

gcode
; Design Swiftly — cnc.jugaaadi.com
G17 G21 G90 G40 G80   ; XY plane, metric, absolute, cancel comp
G28                   ; Return to home position
M3 S18000             ; Spindle on
G4 P2                 ; Spindle ramp-up dwell
; --- Toolpaths start below ---
What those mode codes mean

G17 = XY plane, G21 = millimetres, G90 = absolute coordinates (not incremental), G40 = cancel cutter compensation, G80 = cancel fixed cycles. Including these avoids inheriting previous machine state.

Reading G-Code in Design Swiftly

The built-in G-Code Editor (Simulator tab → Editor view) has syntax highlighting for all GRBL commands. You can edit any line and click Re-simulate to instantly preview the result in 3D. You can also import an existing .gcode or .nc file directly to inspect or re-run it.

Common Mistakes and How to Fix Them

  • No feed rate on G1: GRBL errors with "No feed rate". Fix: add F to the first G1 command.
  • Z never moves: Check that depth is set >0 in the CAM panel. Default is 0mm (score-only).
  • Arc errors: Arcs with radius mismatches cause GRBL to alarm. Use Design Swiftly's auto-generator — it corrects arc precision automatically.
  • Units mismatch: Always confirm G21 (mm) or G20 (inch) at the start of the file.

Try it yourself →

Open Design Swiftly — Free, No Install

No account. No download. Just open and create.

Launch Design Swiftly

More Articles