โ† Open Viewer
GCodex โ€บ STL to G-Code

How to Convert STL to G-Code: Complete Slicing Guide

The definitive guide to turning a 3D model (STL) into printable G-Code โ€” covering slicer software, settings, CAM workflows, and verification. Updated May 2026.

Quick Answer: To convert STL to G-Code for 3D printing, import the STL into a slicer (Cura, PrusaSlicer, or Bambu Studio), configure layer height, infill, and temperature settings, then click Slice. The slicer outputs a .gcode file. For CNC machining, use CAM software (Fusion 360, Mastercam) instead.

What is an STL File?

STL (Standard Triangle Language, or stereolithography) is the most universal 3D model format. It describes the surface geometry of a 3D object as a mesh of triangles. STL files contain no color, material, or unit information โ€” just the geometric shell of the object. They are the standard export format from virtually every CAD program (SolidWorks, Fusion 360, Blender, Tinkercad, FreeCAD) for use in manufacturing.

What is G-Code?

G-Code (RS-274) is the machine control language that tells a 3D printer or CNC machine exactly where to move, how fast, and what to do at each point. A G-Code file for a 3D print contains thousands to millions of lines describing every layer, every travel move, every temperature change, and every extrusion amount. G-Code is generated from the STL by software โ€” you never write it manually for a full print.

Method 1: STL to G-Code for 3D Printing (Slicer Software)

For FDM 3D printing, slicer software converts STL to G-Code. The slicer slices the model into horizontal layers and generates the toolpath for each layer.

Step 1 โ€” Export a clean STL

In your CAD software, export as STL. Ensure the mesh is watertight โ€” no holes, no non-manifold edges, no inverted normals. Use the STL repair tool in Meshmixer, Netfabb, or PrusaSlicer's built-in fixer if needed. A bad mesh produces artifacts in slicing.

Step 2 โ€” Choose your slicer

SlicerBest ForCost
Ultimaker CuraUniversal, beginner-friendly, huge plugin libraryFree
PrusaSlicerAdvanced features, multi-material, Prusa printersFree
Bambu StudioBambu Lab printers, fast workflowFree
IdeaMakerRaise3D printers, industrial workflowsFree
Simplify3DAdvanced manual control, complex multi-extruder$199

Step 3 โ€” Configure critical settings

  • Layer height: 0.1mm (fine detail), 0.2mm (standard), 0.3mm (fast draft)
  • Infill percentage: 15% (display models), 30โ€“40% (functional parts), 80โ€“100% (maximum strength)
  • Print temperature: PLA 200โ€“220ยฐC, PETG 230โ€“250ยฐC, ABS 240โ€“260ยฐC
  • Bed temperature: PLA 60ยฐC, PETG 80ยฐC, ABS 100โ€“110ยฐC
  • Supports: Enable for overhangs greater than 45ยฐ
  • Print speed: 40โ€“60 mm/s for quality, 80โ€“120 mm/s for speed

Step 4 โ€” Slice and export G-Code

Click the Slice button. The slicer calculates all toolpaths. Review the layer preview in the slicer. Export the .gcode file to SD card, USB, or send via OctoPrint to your printer.

Step 5 โ€” Verify your G-Code

Before printing, drop the .gcode file into GCodex to inspect the full 3D toolpath. Check layer count, support structure paths, and any unexpected travel moves. This step takes 2 minutes and can save a failed 12-hour print.

Verify your G-Code in the browser โ€” free, instant, no upload.

Open GCodex Viewer โ†’

Method 2: STL to G-Code for CNC Machining (CAM Software)

For CNC machining, you use CAM (Computer-Aided Manufacturing) software instead of a slicer. CAM software defines cutting toolpaths for subtractive manufacturing โ€” removing material from a solid block.

  • Fusion 360 CAM โ€” Free for personal use. Excellent for milling, turning, and multi-axis work.
  • Mastercam โ€” Industry standard, most powerful, expensive.
  • HSMWorks โ€” Integrated into SolidWorks.
  • FreeCAD Path workbench โ€” Free, open-source, basic 2.5D milling.

In CAM, you import the STL (or preferably a STEP file for better feature recognition), define your cutting tools, stock material size, feeds and speeds, and toolpath strategy. The CAM software generates G-Code post-processed for your specific machine controller (Fanuc, Haas, Siemens, GRBL).

Common STL to G-Code Problems and Fixes

  • Slicer shows no model after import: Model may be in wrong units (mm vs inches) โ€” check and rescale. Or mesh has errors โ€” run Repair in PrusaSlicer.
  • G-Code prints in wrong location: Work coordinate system issue โ€” verify G54 offset or re-home the printer.
  • Print looks correct in slicer but fails on printer: Verify G-Code in GCodex โ€” the slicer preview and actual G-Code can differ if post-processing scripts modify the file.
  • Excessive stringing between parts: Increase retraction distance and speed in slicer settings.

Frequently Asked Questions

What software converts STL to G-Code?
Slicer software converts STL to G-Code for 3D printing. The most popular free options are Ultimaker Cura, PrusaSlicer, and Bambu Studio. For CNC machining, use CAM software like Fusion 360 CAM (free tier available), Mastercam, or HSMWorks.
Is converting STL to G-Code free?
Yes โ€” Cura, PrusaSlicer, and Bambu Studio are completely free for STL to G-Code slicing. For CNC CAM, Fusion 360 offers a free personal license. GCodex is also free for verifying and visualizing the generated G-Code.
How long does slicing take?
Typically 5โ€“60 seconds for most models. Complex high-polygon models with dense infill can take 2โ€“5 minutes. The resulting G-Code file may contain 100,000 to several million lines for large prints.
Can I view G-Code before printing?
Yes โ€” drop your .gcode file into GCodex at gcodex.tech for instant 3D toolpath visualization, layer inspection, and travel move analysis. No account or upload needed โ€” processes entirely in your browser.