G-code looks cryptic until you notice that almost every mill program has the same shape: set up the machine, call a tool, start the spindle, move, cut, and finish safely. Once you can see that shape, you can read most programs line by line.

This guide explains that structure, then shows how the free generators in the Shader7 CNC Machinist hub write each kind of program. Generating a program, changing one value and comparing the output is one of the quickest ways to learn what each code does.

A G-code reference: the most common motion, plane and cycle codes on a CNC mill
A G-code reference: the most common motion, plane and cycle codes on a CNC mill.

The shape of a mill program

Here is the start of a face-milling program from the Shader7 Mill / Drill Contour generator, with notes:

G17 G21 G90 G40 G80        (XY plane, mm, absolute, cancel comp and cycles)
#4=200.000 (LENGTH IN X)
#5=100.000 (WIDTH IN Y)
T1 M6                       (tool change to tool 1)
G43 H1 Z55.000              (tool length offset, move to a safe height)
M3 S...                     (spindle on clockwise)
M8                          (coolant on)

Then the cutting moves, and finally:

G00 Z55.000                 (retract)
G28 G91 Z0                  (return Z to home)
G28 X0 Y0
M5                          (spindle stop)
M9                          (coolant off)
M30                         (end of program)

Codes you will meet everywhere

Code Meaning
G00 Rapid move (positioning, never cutting)
G01 Straight-line cutting move at feed F
G02 / G03 Clockwise / counter-clockwise arc
G17 / G18 / G19 XY / XZ / YZ working plane
G21 / G20 Millimetres / inches
G90 / G91 Absolute / incremental coordinates
G40 / G41 / G42 Cancel / left / right cutter compensation
G43 H.. Tool length offset
G54 First work coordinate system
G80 Cancel canned cycle
G81 / G83 / G73 / G84 Drill / deep peck / chip-break peck / rigid tap cycles
M3 / M5 Spindle on clockwise / stop
M6 Tool change
M8 / M9 Coolant on / off
M30 End of program and rewind

What the Shader7 generators write

Each generator in the hub focuses on one job. They all run in your browser, show a preview, and give you code to copy.

Face milling, contours and PCD drilling

The Mill / Drill Contour generator has three tabs:

  • Face Milling: enter the workpiece length, width, total depth, depth of cut, cutter diameter, stepover %, safety distances, plane and origin (corner or centre). The program steps across the part in zigzag passes and uses a small macro loop for depth: #1=#1+#3, then IF[#1 GT #2] GOTO 10 until it reaches the total depth.
  • Simple Contour: choose the plane, workpiece size, cutter diameter, which sides to machine and where the origin is, the final depth and depth of cut, and Climb (G41) or Conventional (G42). The material selection sets the cutting data.
  • PCD Drilling: PCD, first hole angle, angle between holes, maximum angle and drill depth.

Drilling and tapping

The Drill Feed & RPM Calculator writes a canned-cycle program (G81, G82, G83, G73, G86 or G84 rigid tapping) for one or many holes, with RPM and feed based on tool and work material, and lets you pick a Fanuc or Haas style, tool number, work offset and G98/G99 return. It is a good place to learn how canned cycles work, because its animated preview shows each peck and retract.

Bolt circles

The PCD Generator converts a bolt circle into X/Y coordinates and writes a G81 program that visits each hole, then cancels the cycle with G80.

Arcs and circles

The ID / OD Circular Interpolation Generator writes helical G03 programs for bores and bosses using I/J arc centres, in G17, G18 or G19.

Chamfers

The Circular Chamfer and XY Chamfer generators write macro programs with WHILE loops that step a chamfer mill down a bevel.

Turning on Siemens controls

The Siemens Sinumerik helper writes CYCLE95 turning programs for 840D and 828D controls and builds tool offset cards.

How rapid moves, feed moves and arcs combine into a toolpath
How rapid moves, feed moves and arcs combine into a toolpath.

A learning routine that works

  1. Generate a simple program. Start with Face Milling on a small block.
  2. Read it top to bottom. Find the setup line, tool change, spindle start, the first cutting move and the end.
  3. Change one input. Change the stepover from 70% to 50% and generate again. Count how many more passes appear.
  4. Change the plane or origin. See which axis letters change and which coordinates flip sign.
  5. Compare with the preview. Every G01 line in the code should match a straight segment in the drawing.
  6. Run it in a simulator or on your control's graphics before it ever goes near a part.

Safety habits from day one

  • Start every program with a safe line. G17 G21 G90 G40 G80 (or similar) cancels anything left active from a previous program.
  • Know your origin. Every coordinate is relative to the work offset (G54). If G54 is not where the program expects, the toolpath is in the wrong place.
  • Rapid only through air. G00 moves are not controlled for cutting. Make sure the clearance height is above clamps and the vise.
  • Single block and reduced rapid the first time you run any program, including ones from a generator.
  • Check cutter compensation. G41/G42 need the right D register and a lead-in move long enough for the control to apply the offset.

Reading a drilling block line by line

The Drill Feed & RPM Calculator writes a short program like this:

(SHADER7 SPEEDS & FEEDS G-CODE)
(OP: DRILL, TOOL DIA: 8.50 mm, 2 HOLES)
G21 G90 G94 G98 G40 G80 G17 G54 (METRIC WORK PLANE)
T01 M06 (SELECT TOOL)
G00 X0.0 Y0.0 S1049 M03 (RAPID TO HOLE, SPINDLE ON CW)
G43 H01 Z30.0 M08 (TOOL LENGTH OFFSET, COOLANT ON)
G83 Z-25.000 R2.0 Q6.38 F146.86 (DEEP HOLE PECK CYCLE)
X25.0 Y15.0 (HOLE 2)
G80 M09 (CYCLE CANCEL, COOLANT OFF)
G00 Z30.0 M05 (SAFE RETRACT, SPINDLE STOP)
M30 (PROGRAM END)
  • Lines in brackets are comments; the control ignores them.
  • G94 sets feed in mm per minute, and G98 returns the tool to the starting height between holes (G99 would return to the R plane).
  • G00 X0.0 Y0.0 S1049 M03 rapids to the first hole while starting the spindle clockwise at 1,049 RPM.
  • G43 H01 applies the tool length offset stored for tool 1 and moves to the clearance height.
  • G83 drills to Z−25 in pecks of 6.38 mm, retracting to R2.0 to clear chips each time.
  • X25.0 Y15.0 on its own line repeats the same cycle at the next hole, because canned cycles stay active until cancelled.
  • G80 cancels the cycle so later moves do not drill, then the program turns off coolant and the spindle and ends with M30.

Comparing this with the face-milling program above shows the same skeleton: setup, tool, spindle, approach, cut, cancel and retract.

Common beginner mistakes

  • Missing decimal points. On some controls, X10 means 10 mm but on others it means 0.010 mm. Writing X10. is always safe.
  • Forgetting G80. A drilling cycle that is not cancelled will drill at every following position.
  • Leaving G91 active. An incremental mode left on turns every following coordinate into a relative move.
  • Wrong work offset. Running a G54 program when the part is set on G55 puts the toolpath in the wrong place.
  • Rapid into the part. A G00 move to a Z level below the top face is a crash. Check every G00 Z value.

Frequently asked questions

Do I need CAM software to start with G-code?

No. Simple parts and operations such as facing, drilling, bolt circles and circle milling are easy to program by hand or with generators. CAM becomes useful for complex 3D shapes.

Which controls do the Shader7 generators support?

Most write Fanuc-style code, several with Fanuc Custom Macro B variables and loops. The Siemens helper writes Sinumerik CYCLE95 programs, and the 3D CAD Studio can output Fanuc/Haas, Siemens, LinuxCNC-style and macro dialects.

What does the # in some programs mean?

It marks a macro variable. For example, #1=-2.0 stores −2.0 in variable 1, and later lines can use #1 instead of a fixed number. The Macro B guide explains this in detail.

Is the generated code ready to run?

Treat it as a draft. Check the tool numbers, offsets, clearance heights and end code for your machine, and verify it in simulation before cutting.

Do the generators work on a phone?

Yes. They run in any modern browser and do not need an account.

Try the CNC generators

Pick a generator from the CNC Machinist hub, change one value at a time and watch how the program changes. It is the fastest way to learn what each block does.