Free CNC G-Code Generator & Toolpath Creator | Drilling, Milling & Lathe
Create professional CNC G-code instantly with this free online toolpath creator. Whether you need drilling cycles, pocket milling, slot milling, surface facing, or lathe operations (turning, threading, and grooving), this powerful utility generates complete, ready-to-run programs in seconds.
Supports major controllers including Fanuc, Haas, GRBL, Mach3, LinuxCNC, and Siemens. Features include multiple hole patterns, peck drilling, multi-depth strategies, feeds & speeds calculator, coordinate tables, and visual canvas previews.
Perfect for machinists, hobbyists, and CNC beginners, no expensive CAM software required. Simply enter your parameters, generate, copy, or download your G-code instantly.
CNC G-Code Generator
Free online toolpath creator & CNC programming utility. Generate drilling, bolt circle, pocket milling, lathe, and engraving G-code for Fanuc, Haas, GRBL, Mach3, LinuxCNC, and Siemens controllers.
Drilling G-Code — Parameters
G-Code Output
| # | X | Y | Z Depth |
|---|---|---|---|
| Generate code to populate table | |||
Bolt Circle G-Code — Parameters
Bolt Circle Output
| # | X | Y | Angle ° |
|---|---|---|---|
| Generate to populate | |||
Pocket Milling — Parameters
Pocket G-Code Output
Slot Milling — Parameters
Slot Output
Facing Operation — Parameters
Facing Output
Lathe G-Code — Parameters
Lathe G-Code Output
Feeds & Speeds Calculator
Results & Recommendations
Spindle Speed (RPM)
$$S = \frac{V_c \times 1000}{\pi \times D}$$Where $V_c$ = cutting speed (m/min), $D$ = tool diameter (mm)
Feed Rate
$$F = S \times f_z \times z$$Where $f_z$ = chip load (mm/tooth), $z$ = number of flutes
G-Code & M-Code Cheat Sheet
| Code | Category | Description | Example |
|---|---|---|---|
| G00 | Motion | Rapid positioning — non-cutting move at max machine speed | G00 X100 Y50 Z5 |
| G01 | Motion | Linear interpolation — controlled cutting feed move | G01 X80 Y30 F300 |
| G02 | Arc | Circular interpolation — clockwise arc | G02 X20 Y0 R10 F200 |
| G03 | Arc | Circular interpolation — counter-clockwise arc | G03 I5 J0 F200 |
| G04 | Control | Dwell — pause program for P milliseconds or seconds | G04 P500 |
| G17 | Plane | Select XY plane (default for milling) | G17 |
| G18 | Plane | Select XZ plane | G18 |
| G19 | Plane | Select YZ plane | G19 |
| G20 | Units | Set units to Inches | G20 |
| G21 | Units | Set units to Millimeters | G21 |
| G28 | Control | Return to machine home position | G91 G28 Z0 |
| G40 | Comp | Cancel cutter radius compensation | G40 |
| G41 | Comp | Cutter compensation — left of path | G41 D01 |
| G42 | Comp | Cutter compensation — right of path | G42 D01 |
| G43 | Comp | Tool length compensation positive offset | G43 H01 Z5.0 |
| G49 | Comp | Cancel tool length compensation | G49 |
| G54 | WCS | Work coordinate system #1 (most common) | G54 |
| G55–G59 | WCS | Work coordinate systems #2–#6 | G55 |
| G73 | Cycle | High-speed peck drilling — partial retract chip break | G73 Z-25 R2 Q5 F120 |
| G80 | Cycle | Cancel canned drilling cycle | G80 |
| G81 | Cycle | Standard drilling cycle — plunge and retract | G81 Z-20 R2 F120 |
| G82 | Cycle | Spot drilling with dwell at bottom | G82 Z-5 R2 P500 F120 |
| G83 | Cycle | Peck drilling — full retract each peck | G83 Z-40 R2 Q5 F100 |
| G84 | Cycle | Rigid tapping cycle | G84 Z-20 R2 F1.5 |
| G90 | Mode | Absolute positioning (coordinates from WCS origin) | G90 |
| G91 | Mode | Incremental positioning (coordinates relative to current position) | G91 |
| G98 | Cycle | Canned cycle return to initial Z level | G98 |
| G99 | Cycle | Canned cycle return to R-plane | G99 |
| M-CODES (Miscellaneous Functions) | |||
| M00 | Control | Program stop — requires operator to press cycle start | M00 |
| M01 | Control | Optional stop | M01 |
| M03 | Spindle | Spindle on — clockwise (CW) | M03 S1200 |
| M04 | Spindle | Spindle on — counter-clockwise (CCW) | M04 S800 |
| M05 | Spindle | Spindle stop | M05 |
| M06 | Tool | Tool change | T01 M06 |
| M07 | Coolant | Mist coolant on | M07 |
| M08 | Coolant | Flood coolant on | M08 |
| M09 | Coolant | Coolant off | M09 |
| M30 | Control | End of program + rewind | M30 |
| M98 | Sub | Call subprogram | M98 P0100 L3 |
| M99 | Sub | Return from subprogram | M99 |
CNC Machining Formulas & Calculations
Metric (m/min cutting speed)
$$S = \frac{V_c \times 1000}{\pi \times D}$$$S$ = spindle speed (RPM) | $V_c$ = cutting speed (m/min) | $D$ = tool diameter (mm)
Imperial (SFM cutting speed)
$$S = \frac{\text{SFM} \times 3.82}{D}$$$S$ = spindle speed (RPM) | SFM = surface feet per minute | $D$ = tool diameter (inches)
Feed Rate (mm/min or IPM)
$$F = S \times f_z \times z$$$F$ = feed rate | $S$ = spindle RPM | $f_z$ = chip load per tooth | $z$ = number of flutes
Hole Position on Bolt Circle
$$X_n = X_c + R \cos\!\left(\theta_0 + \frac{360°\,(n-1)}{N}\right)$$ $$Y_n = Y_c + R \sin\!\left(\theta_0 + \frac{360°\,(n-1)}{N}\right)$$$X_c, Y_c$ = circle center | $R$ = bolt circle radius | $\theta_0$ = start angle | $N$ = number of holes | $n$ = hole index
I, J Calculation for G02/G03 (Mill)
$$I = X_{\text{center}} - X_{\text{start}} \qquad J = Y_{\text{center}} - Y_{\text{start}}$$$I$ = X offset from arc start to arc center | $J$ = Y offset from arc start to arc center
For lathe (G02/G03): $I = X_{\text{center}} - X_{\text{start}}$ | $K = Z_{\text{center}} - Z_{\text{start}}$
MRR — Milling
$$\text{MRR} = \text{DOC} \times \text{WOC} \times F$$DOC = axial depth of cut (mm) | WOC = width of cut / stepover (mm) | $F$ = feed rate (mm/min)
Result in mm³/min. Divide by 1000 for cm³/min.
Estimated Cycle Time
$$T = \frac{L_{\text{rapid}}}{V_{\text{rapid}}} + \frac{L_{\text{feed}}}{F} + \sum P_i$$$L_{\text{rapid}}$ = total rapid distance | $V_{\text{rapid}}$ = machine rapid speed | $L_{\text{feed}}$ = total cutting path length | $F$ = average feed rate | $P_i$ = dwell times
Number of Pecks (G83)
$$\text{PeckCount} = \left\lceil \frac{Z_{\text{total}}}{Q} \right\rceil$$$Z_{\text{total}}$ = total drill depth | $Q$ = peck depth increment | $\lceil \cdot \rceil$ = ceiling (round up)
Arc Radius for Thread Milling Entry
$$R_{\text{arc}} = \frac{D_{\text{hole}} - D_{\text{tool}}}{2}$$$D_{\text{hole}}$ = hole diameter | $D_{\text{tool}}$ = thread mill tool diameter
Tapping Feed Rate (Rigid Tap G84)
$$F = \text{RPM} \times \text{Pitch}$$Pitch in mm/rev (metric) or inches/rev (imperial)
Absolute Stepover from Percentage
$$\text{WOC} = D \times \frac{\%}{100}$$$D$ = tool diameter | $\%$ = stepover percentage (typically 40–60% for roughing)
Number of Z Passes
$$\text{Passes} = \left\lceil \frac{|Z_{\text{depth}}|}{\text{StepDown}} \right\rceil$$Manual G-Code Writing is Slow
Users waste time hand-coding G00, G01, drilling cycles, and repetitive coordinates. This tool auto-generates complete programs instantly.
Syntax Errors Cause Crashes
Wrong decimal placement, missing safety lines, or bad modal codes cause tool crashes and scrapped parts. Our generator validates all output.
Beginners Don't Know G-Code
New machinists struggle with arc commands, canned cycles, and coordinate modes. This guided form-based tool removes the learning curve.
CAM Software is Too Expensive
Full CAM packages cost thousands. This free browser-based utility handles common operations without any software installation.
Repetitive Hole Patterns are Tedious
Bolt circles, grid arrays, and linear patterns require many calculations. This tool computes all X/Y positions automatically using the standard formula.
Controller Compatibility Confusion
Fanuc, Haas, GRBL, LinuxCNC all have dialect differences. Post-processor selection tailors output syntax to your exact machine.
Supported Operations & Features
- G81 — Standard plunge drill
- G83 — Deep hole peck drilling
- G73 — High-speed chip-break peck
- G82 — Spot drill with dwell
- G84 — Rigid tapping
- Single hole — manual X/Y
- Linear array — N holes, spacing
- Rectangular grid — rows × columns
- Bolt circle (PCD) — any # of holes
- Clockwise & counter-clockwise
- Rectangular pocket (zig-zag)
- Circular pocket (G02/G03)
- Slot milling (multi-pass)
- Surface facing (raster)
- Multi-level Z step-down
- OD turning (multi-pass)
- Facing operation
- Threading (G76 cycle)
- Grooving
- Roughing + finishing passes
- Fanuc / Haas (standard)
- GRBL (Arduino CNC)
- Mach3 / Mach4
- LinuxCNC (.ngc)
- Siemens Sinumerik
- Feeds & speeds calculator
- RPM from cutting speed
- Feed from chip load
- Cycle time estimation
- MRR (material removal rate)
🔧 SteelSolver Engineering Tools & Guides — featuring 260+ free calculators and 60+ in-depth guides for engineers, fabricators, and metalworkers.
👉 Find the right tool or guide for your project:
📚 Explore All Engineering Hubs on SteelSolver.com
CNC G-Code Generator — Complete User Guide Free online CNC programming tool & toolpath creator for milling, drilling, lathe, plasma, router, and laser machining
This free online CNC G-Code Generator is a browser-based CAM utility and digital toolpath creator that converts your machining parameters into ready-to-run G-code programs — without expensive software, complex CAD/CAM systems, or manual scripting. Whether you are a beginner learning CNC numerical control or a professional machinist needing fast code generation for production runs, this tool covers the full workflow from geometry definition through post-processor output and file download.
The generator supports CNC mills, drill presses, lathes, plasma cutters, routers, and laser engravers, producing G-code compatible with Fanuc, Haas, GRBL, Mach3, LinuxCNC, and Siemens Sinumerik controllers. It handles drilling cycles, bolt circle patterns, pocket milling, slot cutting, facing operations, lathe turning, threading, and grooving — with a built-in feeds & speeds calculator and visual toolpath preview.
CNC G-Code Workflow: From CAD Design to Machine Motion
The diagram below illustrates the complete digital-to-physical manufacturing pipeline — from your part design through the G-code generator and post-processor to the CNC machine controller and final fabrication.
ⓘ The complete digital engineering workflow: CAD geometry → G-Code Generator → Post-Processor → .nc File → CNC Machine production
Key User Pain Points — and How This CNC G-Code Generator Solves Them
Manual G-Code Writing is Slow
Writing hundreds of lines of G00, G01, drilling cycles, and coordinate math by hand wastes shop time and productivity in every job.
Syntax Errors Cause Machine Crashes
Wrong decimal placement, missing G80 cycle cancels, or incorrect modal commands cause tool crashes, broken cutters, and scrapped material.
Beginners Don't Understand G-Code Language
CNC programming syntax, arc interpolation, canned cycles, and coordinate systems have a steep learning curve for new machinists and students.
Full CAM Software is Expensive
Professional CAM systems like Mastercam or Fusion 360 cost hundreds per year. This free browser-based tool handles most common operations instantly.
Repetitive Hole Patterns are Tedious
Bolt circles, linear arrays, and grid patterns require manual coordinate calculation for every hole. The bolt circle module computes all X/Y positions automatically.
Controller Compatibility Confusion
Fanuc, Haas, GRBL, LinuxCNC, and Siemens all use slightly different dialect syntax. The post-processor selector adapts output for each system automatically.
Step-by-Step User Guide — How to Use the CNC G-Code Generator
-
1Select Your Machining Module (Tab)
At the top of the tool, choose the correct operation tab for your job: Drilling, Bolt Circle, Pocket, Slot, Facing, Lathe, Feeds & Speeds, or the G-Code Cheat Sheet. Each module generates a specific toolpath type optimised for that machining operation. Beginners should start with the Drilling tab, which auto-generates a working example on load.
Do not mix up the Drilling tab (which uses canned cycles like G81/G83) with the Pocket tab (which generates zig-zag or circular toolpaths). They serve different cutting operations. -
2Choose Controller and Units
Under Machine & Controller, select your CNC machine's control dialect from the dropdown: Fanuc / Haas (standard industry syntax), GRBL (Arduino-based CNC routers), Mach3 / Mach4, LinuxCNC, or Siemens Sinumerik. Then choose Millimeters (G21) or Inches (G20). This affects all coordinate output, depth values, feed rates, and safe-Z heights throughout the generated program.
Common mistake: Selecting the wrong units. If your machine is metric but you generate inch G-code (G20), the tool will move 25.4× too far and crash. Always confirm your machine's unit setting first. -
3Select Drilling Cycle Type (Drilling Tab)
Choose the appropriate canned cycle for your operation:
G81for standard plunge drilling,G83for deep hole peck drilling (full retract each peck),G73for high-speed chip-break peck (partial retract),G82for spot drilling with a dwell pause, orG84for rigid tapping. Use G83 for any hole deeper than 3× the tool diameter to prevent chip packing and tool breakage.Rule of thumb: Hole depth > 3× drill diameter = always use G83 peck drilling. Forgetting this is the most common reason for drill breakage in deep holes. -
4Select Hole Pattern and Enter Coordinates
Choose Single Hole, Linear Array, or Rectangular Grid. For a single hole, enter the X and Y coordinate. For a linear array, enter start X/Y, spacing between holes, hole count, and axis direction. For a grid, enter origin, number of rows and columns, and X/Y spacing. All coordinates are in the selected unit (mm or inch) relative to your Work Coordinate System (WCS) origin (G54 by default).
For bolt circle / PCD patterns (flanges, pipe flanges), use the dedicated Bolt Circle tab — it automatically calculates all X/Y positions using the polar coordinate formula. -
5Set Z-Axis Depth, Safe Z, and Peck Parameters
Enter three critical Z values: Z Top (surface of the material, typically 0.000), Z Depth (final drill depth — must be a negative number, e.g. −20), and Safe Z (clearance height above the part for rapid moves, e.g. 5). For G83/G73 peck cycles, also enter the Peck Depth Q (how deep each peck goes before retracting) and optional Dwell P in seconds for G82.
Z Depth must be negative (below the surface). A positive Z depth value means you are cutting upward into air, not into the material — a very common beginner mistake. -
6Enter Tool Number, Spindle Speed, and Feed Rate
Enter the Tool Number (T) (1–99), which sets both the tool change command and tool length offset register. Enter Spindle Speed (S) in RPM and Feed Rate (F) in mm/min or IPM. Not sure of the correct values? Switch to the Feeds & Speeds tab first — enter your tool diameter, material, and chip load to get automatic RPM and feed rate recommendations using the built-in calculator formulas.
Feed rate of 0 will cause a syntax error in most controllers. If you do not know the feed rate, use the Feeds & Speeds tab to calculate it before returning to generate your drilling code. -
7Configure Options: WCS, Retract Mode, Coolant, Line Numbers
Select the Work Coordinate System (WCS) — G54 through G59 — matching your fixture offset on the machine. Choose G98 (return to initial Z height between holes) or G99 (return to R-plane only) retract mode. Toggle Flood Coolant (M08), Line Numbers (N-codes), Comments in parentheses, and Tool Length Compensation G43 on or off using the switch toggles.
Use G98 when the fixture or clamps protrude above the part — it ensures the tool retracts fully above them between holes. Use G99 on flat plates for faster cycle times. -
8Click Generate G-Code and Review the Output
Click the orange Generate G-Code button. The tool validates all inputs (checks for positive Z depth, non-zero feeds, safe Z above surface), then generates the complete G-code program in the output panel. Review the Results Summary (hole count, depth, estimated cycle time, line count), examine the Coordinate Table for all X/Y/Z positions, and inspect the Toolpath Preview canvas showing the visual drill pattern.
-
9Copy to Clipboard or Download the .nc File
Click 📋 Copy to send the G-code to your clipboard for pasting directly into your machine controller editor, or click ↓ Download to save a ready-to-load
.ncfile. The filename reflects the operation type (e.g.drilling.nc,bolt_circle.nc,pocket.nc). Most CNC controllers accept .nc, .tap, .txt, or .ngc formats — rename the extension if needed.Always run the program in DRY RUN or AIR CUT mode on your machine first (spindle on, no material) to verify all movements are correct before cutting actual stock. -
10Use the Feeds & Speeds Calculator Tab
Navigate to the Feeds & Speeds tab. Select your material from the pre-loaded library (Aluminum, Mild Steel, Stainless, Brass, Titanium, Plastic, Wood), choose your cutter type (End Mill, Ball Nose, Drill, Face Mill), enter tool diameter and flute count. The calculator applies the standard spindle speed and feed rate formulas automatically. Use the results as starting values in your drilling or milling code — always verify against your toolmaker's specifications.
All Formulas Used — Calculation Reference with Units
Every result produced by this CNC G-Code Generator is computed using the following standard machining formulas. These are the same calculations used in professional CAM software and CNC programming textbooks. All formula variables are defined with their units for clarity and trust.
Spindle Speed (RPM) — S Parameter
The spindle speed formula converts the recommended cutting speed for a material/tool combination into the rotational speed (RPM) the CNC machine spindle must turn at. This value becomes the S word in the G-code (e.g. S1200 M03).
S = Spindle speed (RPM — revolutions per minute)
Vc = Cutting speed (m/min — meters per minute, material-specific)
D = Tool diameter (mm — millimeters)
π = Pi (3.14159...)
SFM = Surface Feet per Minute (imperial cutting speed)
3.82 = Constant = 12 / π (unit conversion factor)
D = Tool diameter (inches)
Worked Example — Spindle Speed
Problem: 10mm carbide end mill cutting Aluminum 6061. Recommended cutting speed = 300 m/min.
Calculation: \( S = \frac{300 \times 1000}{\pi \times 10} = \frac{300{,}000}{31.416} \approx \mathbf{9{,}549 \text{ RPM}} \)
G-code output: S9549 M03
Feed Rate (F Parameter) — mm/min or IPM
The feed rate is the speed at which the cutter moves through the material. It is derived from the spindle RPM, chip load per tooth, and number of cutter flutes. This becomes the F word in all G01, G02, G03, and canned cycle commands.
F = Feed rate (mm/min or IPM — inches per minute)
S = Spindle speed (RPM)
fz = Chip load per tooth (mm/tooth or inch/tooth — tool/material specific)
z = Number of cutting flutes (integer, typically 2–6)
Worked Example — Feed Rate
Problem: 4-flute carbide end mill in Aluminum, S = 9,549 RPM, chip load = 0.04 mm/tooth.
Calculation: \( F = 9549 \times 0.04 \times 4 = \mathbf{1{,}527 \text{ mm/min}} \)
G-code output: G01 X50 Y0 F1527
Bolt Circle / PCD Hole Coordinates
The bolt circle (Pitch Circle Diameter) formula calculates the X and Y coordinates of each equally-spaced hole around a circle. This is the core calculation behind the Bolt Circle G-Code Generator tab and is used to produce the X and Y coordinate words for each drilling position.
Xn, Yn = Coordinates of hole number n (mm or inches)
Xc, Yc = Center point of the bolt circle (mm or inches)
R = Bolt circle radius = PCD / 2 (mm or inches)
θ0 = Start angle in degrees (0° = positive X axis, 3 o'clock position)
N = Total number of holes (integer)
n = Hole index number (1, 2, 3, ..., N)
Worked Example — Bolt Circle (6 holes, PCD 100mm)
Problem: 6 equally-spaced holes on a 100mm PCD, center at X0 Y0, start angle 0°.
\( R = 100/2 = 50\text{mm} \quad\) Angle step \(= 360/6 = 60°\)
Hole 1: \( X = 50\cos(0°) = 50.0000, \quad Y = 50\sin(0°) = 0.0000 \)
Hole 2: \( X = 50\cos(60°) = 25.0000, \quad Y = 50\sin(60°) = 43.3013 \)
Hole 3: \( X = 50\cos(120°) = -25.0000, \quad Y = 50\sin(120°) = 43.3013 \)
...and so on for all 6 holes.
Arc Center Offsets I, J, K — Circular Interpolation
For G02 (clockwise arc) and G03 (counter-clockwise arc) commands, the controller needs to know the arc center position relative to the start point. The generator calculates I and J offsets automatically so you never have to do this complex geometry manually.
I = X distance from arc start point to arc center point (mm or inches)
J = Y distance from arc start point to arc center point (mm or inches)
Xcenter, Ycenter = Absolute coordinates of the arc center
Xstart, Ystart = Absolute coordinates of the arc starting point
For lathe (XZ plane, G18): I = Xcenter − Xstart and K = Zcenter − Zstart
Number of Peck Passes — G83 Deep Hole Drilling
When using the peck drilling cycle (G83), the generator calculates how many individual peck increments are needed to reach the final hole depth, then outputs the Q parameter accordingly.
|Zdepth| = Total drill depth, absolute value (mm or inches)
Q = Peck depth per increment (mm or inches — entered in the Peck Depth field)
⌈ · ⌉ = Ceiling function (round up to nearest whole number)
Material Removal Rate (MRR) — Pocket Tab
The Material Removal Rate measures how efficiently the cutter is removing stock, calculated from the axial depth of cut (step-down), stepover width, and feed rate. The Pocket tab displays this result in cm³/min.
MRR = Material removal rate (cm³/min)
DOC = Axial depth of cut per pass / step-down (mm)
WOC = Width of cut / stepover (mm) = Tool Diameter × (Stepover% / 100)
F = Feed rate (mm/min)
Divide by 1000 to convert mm³/min to cm³/min
Stepover (WOC) and Z-Pass Count — Pocket & Facing
D = Tool diameter (mm)
Stepover% = User-entered stepover percentage (typically 40–60% for roughing, 10–20% for finishing)
|Zdepth| = Total pocket or slot depth (mm, absolute value)
StepDown = Maximum cut depth per Z pass (mm — entered by user)
Estimated Cycle Time Calculation
The generator estimates the drilling program cycle time using the total cutting distance divided by the feed rate, plus rapid move overhead. This is shown in the Results Summary section as Est. Time (sec).
T = Estimated cycle time (seconds)
Nh = Number of holes
|Zdepth| = Hole depth (mm)
F = Feed rate (mm/min)
60 = Converts minutes to seconds
trapid = Estimated rapid move overhead per hole (≈0.5 seconds)
Threading & Tapping Formulas
Ftap = Tapping feed rate (mm/min or IPM)
SRPM = Spindle speed in RPM
Pitch = Thread pitch in mm/rev (metric) or inches/rev (imperial)
Example: M10×1.5 thread at 600 RPM → F = 600 × 1.5 = 900 mm/min
Rarc = Helical interpolation radius used in G02/G03 arc motion (mm)
Dhole = Target hole or thread major diameter (mm)
Dtool = Thread mill tool diameter (mm)
Accuracy Note: All formulas in this generator follow ISO 841 and industry-standard CNC programming mathematics. Spindle speed and feed rate calculations produce theoretically correct starting values based on the cutting speed and chip load you enter. In practice, actual optimal values depend on machine rigidity, tool runout, workholding, coolant, and material batch variation. Treat all calculated values as starting points — always verify with a dry run and adjust based on observed cut quality, tool temperature, and surface finish. The generator validates all inputs before generating code and will flag errors such as zero feed rates, positive Z depth values, and unsafe clearance heights.
Input Parameters Reference — Units, Valid Ranges, and Descriptions
| Parameter | Unit | Typical Range | Description | G-Code Word |
|---|---|---|---|---|
| X Coordinate | mm / inch | Any | Horizontal position of hole or toolpath point relative to WCS origin | X |
| Y Coordinate | mm / inch | Any | Vertical position of hole or toolpath point relative to WCS origin | Y |
| Z Depth | mm / inch | Negative value | Final drill or cutting depth below Z Top surface. Must be negative. | Z |
| Safe Z | mm / inch | 3–10 mm typical | Clearance height above part for rapid (G00) positioning between holes | R / Z |
| Peck Depth Q | mm / inch | 2–8 mm typical | Increment depth per peck in G83/G73 cycles before chip-clearing retract | Q |
| Dwell P | seconds | 0.2–2.0 sec | Pause time at bottom of hole in G82 spot drill or G04 dwell command | P |
| Spindle Speed S | RPM | 100–30,000 RPM | Spindle rotational speed. M03 = CW, M04 = CCW | S |
| Feed Rate F | mm/min / IPM | 20–5,000 mm/min | Cutting feed rate for G01/G02/G03 and canned cycle plunge | F |
| Tool Number T | Integer | 1–99 | Tool number for automatic tool changer (ATC) or manual tool change (M06) | T |
| PCD Diameter | mm | Any positive | Pitch Circle Diameter for bolt circle pattern — diameter of the circle all holes lie on | Calculated to X,Y |
| Start Angle | degrees | 0–360° | Angle of first hole in bolt circle (0° = 3 o'clock / positive X axis) | Calculated to X,Y |
| Step-Down | mm | 0.5–5 mm typical | Maximum depth of cut per Z-level pass in pocket or slot milling | Calculated to Z |
| Stepover % | % | 30–60% roughing | Percentage of tool diameter used as lateral path spacing in pocket operations | Calculated to X,Y |
| Cutting Speed V₃ | m/min | 50–800 m/min | Recommended surface speed for the material/tool combination (from machining data tables) | Used to calculate S |
| Chip Load fᵣ | mm/tooth | 0.01–0.15 mm/tooth | Material thickness removed per tooth per revolution. Determines feed rate. | Used to calculate F |
Controller Compatibility — Post-Processor G-Code Dialects
This CNC G-Code generator supports multiple machine controller dialects through its built-in post-processor selector. Choose the correct controller to ensure generated syntax matches your machine's interpreter requirements for numerical control commands, arc formatting, and canned cycle parameters.
| Controller | Canned Cycle Syntax | Arc Format | Key Differences | File Extension |
|---|---|---|---|---|
| Fanuc / Haas | G83 Z-25 R2 Q5 F120 |
I/J or R | Industry standard. Leading zeros required. O-number program header. | .nc / .tap |
| GRBL | Expanded to G00/G01 moves (no native canned cycles) | I/J incremental | No G81/G83 support — generator expands to individual axis moves automatically | .nc / .gcode |
| Mach3 / Mach4 | G83 Z-25 R2 Q5 F120 |
I/J or R | Similar to Fanuc. Uses % delimiters. Some M-codes differ. | .tap / .nc |
| LinuxCNC | G83 Z-25 R2 Q5 F120 |
I/J or R | RS274 dialect. Uses .ngc extension. Very Fanuc-compatible. | .ngc |
| Siemens 840D | CYCLE83() function calls |
I/J absolute | Entirely different syntax. CYCLE commands instead of G8x. Significant format change. | .mpf |
G-Code & M-Code Quick Reference — Commands Generated by This Tool
The following table covers every G-code and M-code command that this generator produces. Understanding these commands helps you verify the output, edit programs for your specific requirements, and understand the machine motion sequence.
| Code | Category | Function | Key Parameters |
|---|---|---|---|
| G00 | Motion | Rapid positioning — moves at maximum machine speed without cutting. Used for tool positioning between holes. | X Y Z |
| G01 | Motion | Linear interpolation — straight-line cutting motion at a controlled feed rate. Used for slot cutting, lathe turning, and plunge moves. | X Y Z F |
| G02 | Arc | Clockwise circular interpolation. Used for circular pocket perimeters and arc contours. | X Y I J R F |
| G03 | Arc | Counter-clockwise circular interpolation. Used for circular pocket entry moves and inside arc profiles. | X Y I J R F |
| G17 | Plane | Select XY working plane — standard for all milling operations. Required in safety header. | — |
| G20 / G21 | Units | G20 = Inch mode. G21 = Metric (mm) mode. Set in safety header — all subsequent coordinates use this unit. | — |
| G40 | Comp | Cancel cutter radius compensation. Included in safety header to ensure clean start. | — |
| G43 | Comp | Apply tool length compensation (positive direction). Activates H register for tool length offset. | H Z |
| G49 | Comp | Cancel tool length compensation. Included in safety header. | — |
| G54–G59 | WCS | Work Coordinate System selection. G54 is the most common. Defines the part zero (datum) location. | — |
| G73 | Cycle | High-speed peck drilling. Partial chip-break retract (faster than G83). Good for shallow peck depths in aluminium. | Z R Q F |
| G80 | Cycle | Cancel canned cycle. Always output after the last hole in any drilling cycle block. | — |
| G81 | Cycle | Standard drilling cycle. Plunge to depth at feed rate, rapid out. For holes ≤ 3× drill diameter. | Z R F |
| G82 | Cycle | Spot drilling cycle with programmable dwell at bottom. P parameter = dwell time in milliseconds. | Z R P F |
| G83 | Cycle | Peck drilling — full retract to R-plane between each peck for chip evacuation. Best for deep holes. | Z R Q F |
| G84 | Cycle | Rigid tapping cycle. Feed = RPM × Pitch. Spindle reverses automatically at bottom to extract tap. | Z R F |
| G90 / G91 | Mode | G90 = Absolute positioning (all coordinates from WCS origin). G91 = Incremental (relative to current position). | — |
| G98 / G99 | Cycle | G98 = After cycle, retract Z to initial height. G99 = retract only to R-plane. G98 safer for complex fixtures. | — |
| M-CODES — Miscellaneous Machine Functions | |||
| M03 | Spindle | Start spindle clockwise (CW). Always includes S word for speed. | S |
| M04 | Spindle | Start spindle counter-clockwise (CCW). Used for left-hand tools or tapping retract. | S |
| M05 | Spindle | Stop spindle. Output at end of program before machine home return. | — |
| M06 | Tool | Tool change command. Combined with T word: T01 M06 or M06 T01 (controller-specific order). | T |
| M08 / M09 | Coolant | M08 = Flood coolant on. M09 = All coolant off. M07 = Mist coolant. | — |
| M30 | Control | End of program and memory rewind. Always the final line in a CNC program. | — |
Common Mistakes — Microcopy & Input Validation Guide
⚠ Positive Z Depth Value
Z Depth must always be negative for milling and drilling (cutting goes below the surface). Entering Z = +20 instead of Z = −20 will generate code that moves the tool upward into the air. The generator validates this and displays an error before generating code.
⚠ Safe Z Below the Material Surface
Safe Z must be greater than Z Top (the material surface, usually 0). If Safe Z = −2 and the surface is at Z = 0, the rapid move will plunge into the part. Use at least 3–5mm above the highest workpiece feature.
⚠ Wrong Units Selection
If your machine runs in millimeters but you generate code with Inches (G20) selected, all coordinates will be 25.4× too small and all depths too shallow. Verify your controller's active unit mode before generating code.
⚠ Tool Diameter Larger Than Pocket or Slot Width
In the Pocket and Slot tabs, the tool diameter must be smaller than the pocket width/diameter. A 10mm end mill cannot cut a 6mm-wide pocket. The generator does not validate geometry constraints in all cases — check tool-to-feature size manually.
⚠ Forgetting G80 After Drilling Cycle
If G80 (cancel canned cycle) is missing from the program, the machine will attempt to drill at every subsequent X/Y move, causing unintended holes throughout the part. This generator always outputs G80 automatically.
⚠ GRBL Does Not Support Canned Cycles
When GRBL is selected as the controller, the generator automatically expands G81/G83 canned cycles into individual G00/G01 moves. This is correct behaviour — do not attempt to run standard Fanuc-format canned cycle code on a GRBL controller.
Frequently Asked Questions (FAQ) — CNC G-Code Generator
-
What is a CNC G-Code Generator and what does it do?
A CNC G-Code Generator is a software utility — in this case a free browser-based tool — that converts machining parameters (coordinates, tool dimensions, speeds, depths, and operation type) into ready-to-run G-code programs. G-code is the standardised numerical control language that CNC machines — mills, lathes, routers, plasma cutters, laser engravers, and drill presses — use to control motor movements, spindle speed, and coolant.
Instead of manually writing every
G00,G01, andG83command line-by-line (a process that is time-consuming and error-prone), you fill in a form with your job parameters and the generator produces the complete, validated code automatically. This is the same function that professional CAM software (Computer-Aided Manufacturing) performs, but focused on common operations that do not require full 3D CAD/CAM integration. -
Is this G-Code Generator free to use? Does it require any download or installation?
Yes — this is a completely free, browser-based online CNC G-Code Generator. There is no software download, no installation, no account required, and no usage limits. It runs entirely in your web browser using standard HTML, CSS, and JavaScript. You can use it on any desktop computer, laptop, or mobile device — including on the workshop floor directly from a tablet or phone.
-
Which CNC controllers is the generated G-code compatible with?
The generator includes a post-processor selector supporting: Fanuc / Haas (the most common industrial standard), GRBL (used in Arduino-based CNC routers and engravers), Mach3 / Mach4 (common in hobby and small shop CNC mills), LinuxCNC (open-source controller using RS274 dialect), and Siemens Sinumerik 840D (European industrial machines using CYCLE-based programming).
For GRBL machines specifically, the generator expands canned drilling cycles (G81/G83) into individual linear moves since GRBL does not natively support canned cycles. All other controllers use standard G-code syntax with minor dialect differences in header formatting and comment style.
-
What is the difference between G81 and G83 drilling cycles?
G81 — Standard Drilling: The tool plunges to the programmed Z depth in one continuous motion at the specified feed rate, then retracts at rapid speed. Suitable for holes up to approximately 3× the drill diameter deep, where chip evacuation is not a problem.
G83 — Peck Drilling: The tool plunges to a programmable peck depth (Q value), then fully retracts to the R-plane to clear chips from the flutes, then plunges again. This cycle repeats until the final Z depth is reached. Essential for deep holes (greater than 3–5× diameter), through-holes in difficult materials, or any situation where chip packing could break the drill.
G73 — High-Speed Peck: Similar to G83 but only partially retracts (a small break) rather than fully retracting. Faster cycle time but less effective chip clearance. Good for shallow peck depths in aluminium.
-
How does the bolt circle G-Code generator calculate hole positions?
The bolt circle module uses the standard polar-to-Cartesian coordinate conversion formula. Given the circle center coordinates, the Pitch Circle Diameter (PCD), the number of holes, and the start angle, each hole's X and Y position is calculated as:
\( X_n = X_c + R\cos(\theta_0 + (n-1) \times 360°/N) \) and \( Y_n = Y_c + R\sin(\theta_0 + (n-1) \times 360°/N) \)
Where R = PCD/2. This is the same calculation performed manually from engineering drawings. The generator does this for all N holes simultaneously and outputs the complete G-code drilling program with accurate coordinates to 4 decimal places.
-
How do I calculate the correct spindle speed and feed rate for my material?
Use the built-in Feeds & Speeds Calculator tab. Select your material from the library (Aluminum, Steel, Stainless, Brass, Titanium, Plastic, Wood), choose your cutter type, enter the tool diameter and flute count. The calculator pre-loads recommended cutting speeds and chip loads from the material database, then applies the formulas:
\( S = (V_c \times 1000) / (\pi \times D) \) for spindle speed and \( F = S \times f_z \times z \) for feed rate.
The results give you recommended starting RPM and feed rate values. Copy these into your drilling or milling operation parameters. Always start at 70–80% of the calculated value on your first test cut, then increase gradually.
-
What file format does the generator output and how do I load it onto my machine?
The generator produces standard ASCII text G-code that can be saved as .nc, .tap, .txt, or .gcode files. Click the Download button to save the file directly to your computer. To load it onto your CNC machine, use one of these methods:
- USB/Flash Drive: Copy the .nc file to a USB stick and load via the controller's USB port (Haas, Fanuc with USB option).
- Serial/DNC Transfer: Use DNC software to transfer the file via RS-232 serial connection to older controllers.
- Ethernet/Network: Many modern controllers support network file transfer via FTP or proprietary software.
- Direct Paste: For GRBL machines using software like Universal G-Code Sender (UGS), copy the code to clipboard and paste directly into the sender program.
- SD Card: Common for Mach3/GRBL routers — save the file to an SD card.
-
Can I use this tool for plasma cutting, laser engraving, and router operations?
Yes. The core G-code motion commands — G00 rapid positioning, G01 linear cutting, G02/G03 arc interpolation — are the same across CNC mills, routers, plasma tables, and laser engravers. The key differences are: plasma and laser machines do not use Z-axis depth cutting in the same way (they use torch height/focal distance control), and they use different M-codes for torch/laser on/off (typically M03/M05 or custom M-codes).
For plasma and laser operations, generate the drilling or slot milling code that matches your cutting path geometry, then manually edit the Z references and add your machine's specific torch-on/torch-off commands. The generated linear and arc motion code (G00, G01, G02, G03, feed rates, and coordinates) will be directly usable.
-
What is Work Coordinate System (WCS) / G54 and how do I set it up on my machine?
The Work Coordinate System (WCS) defines where X0, Y0, Z0 (part zero / datum) is located on your machine. G54 is the most commonly used work offset register. All coordinates in the generated G-code are relative to this zero point.
To set G54 on your machine: (1) Physically touch-off your reference point (usually a corner or center of the workpiece) with a tool or edge finder. (2) Go to the machine's Work Offsets page. (3) Record the machine coordinates at that position into the G54 X, Y, Z registers. (4) The generator uses G54 in the program header, so all X/Y/Z moves are automatically relative to your set zero point. G55 through G59 are used for multiple fixtures or setups on the same machine table.
-
How accurate is the estimated cycle time shown in the results?
The cycle time estimate is a simplified approximation based on total cutting distance divided by feed rate, plus a small overhead per hole for rapid moves and acceleration/deceleration. It does not account for: tool change time, spindle ramp-up time, machine acceleration/deceleration limits, or air-cut distances between separate features.
For a 6-hole drilling program, the estimate is typically accurate to within ±20–30% of actual machine time. For production planning and quoting, multiply the estimated time by 1.3–1.5 as a safety factor. The estimate improves in accuracy as hole count increases.
Explore More Free CNC Programming & Machining Calculation Tools
This G-Code Generator is part of a complete suite of free online CNC utilities. Use our related tools for bolt circle coordinate calculation, tap drill chart lookup, surface finish conversion, and more.