If you've just bought your first CNC machine or you're trying to move beyond using only automatic toolpath generators, learning G-code feels intimidating. Most manuals throw hundreds of commands at you with no context, and YouTube tutorials jump straight into complex projects. What you actually need is a simple beginner CNC machine g-code reference guide that breaks down the essential commands, explains what each line does, and helps you avoid the mistakes that ruin material and waste time. This article does exactly that no fluff, just the information you need to start writing and understanding G-code with confidence.
What exactly is G-code and how does it work on a CNC machine?
G-code is the programming language that tells a CNC machine what to do. Every movement, every speed change, every tool action it's all controlled by lines of G-code. When you use software like Fusion 360, VCarve, or LightBurn to create a toolpath, that software generates G-code behind the scenes. The machine reads the code line by line and executes each command in order.
Think of it like giving driving directions. Each line says something specific: move here, go this fast, turn the spindle on, cut at this depth. The machine doesn't interpret intent it follows exactly what the code says. That's why understanding the basics matters even if you mostly rely on CAM software. When something goes wrong, or when you want to fine-tune a cut, you need to be able to read and edit the code yourself.
For CNC routers, mills, lathes, and laser cutters, the core G-code language is similar. Some machines add proprietary commands or use slightly different dialects, but the foundation is the same across nearly all of them.
What are the G-code commands every beginner should memorize first?
You don't need to learn hundreds of commands. Start with these core ones and you'll understand the majority of programs you encounter.
Movement commands
- G0 Rapid move. The machine moves as fast as possible to a position. Used for repositioning the tool above the workpiece, not for cutting.
- G1 Linear feed move. The tool moves in a straight line at a controlled speed. This is your main cutting command.
- G2 Clockwise arc move. Used for cutting curves and circles in a clockwise direction.
- G3 Counter-clockwise arc move. Same as G2 but in the opposite direction.
Positioning modes
- G90 Absolute positioning. All coordinates are measured from the machine's zero point (origin). If the code says X10, the tool goes to exactly X10.
- G91 Incremental positioning. Each coordinate is a distance from the tool's current position. If the code says X10, the tool moves 10 units forward from where it already is.
This is one of the most confusing things for beginners. If your machine is set to G91 and you think it's in G90, your cuts will be in completely wrong positions. Always check which mode your program uses.
Machine control commands
- M3 Spindle on (clockwise). Turns the spindle or laser on.
- M5 Spindle off.
- M6 Tool change. Tells the machine to switch to a different tool.
- M8 Coolant on.
- M9 Coolant off.
- M30 End program and reset. The machine stops and returns to its starting state.
Other important commands
- F Feed rate. Sets how fast the tool moves during cutting, usually in mm/min or inches/min.
- S Spindle speed. Sets rotations per minute (RPM).
- T Tool number. Selects which tool the machine should use.
If you're working with a laser cutter rather than a router, many of these same commands apply, but the S value often controls laser power instead of RPM. You can see how specific settings translate for different materials in our laser settings chart for leather cutting.
Can you walk through a real G-code example line by line?
Here's a simple program that cuts a square pocket. Let's break it down:
- G90 Use absolute coordinates
- G21 Set units to millimeters
- G0 X0 Y0 Rapid move to the origin point
- M3 S12000 Turn spindle on at 12,000 RPM
- G0 Z5 Move Z axis up 5mm (safe height)
- G1 Z-2 F200 Plunge into the material 2mm deep at 200 mm/min
- G1 X50 F800 Cut to X50 at 800 mm/min
- G1 Y50 Cut to Y50
- G1 X0 Cut back to X0
- G1 Y0 Cut back to the starting Y position
- G0 Z5 Lift tool up to safe height
- M5 Turn spindle off
- M30 End program
Notice the pattern: the machine starts by setting its mode, turns on the spindle, moves to a safe height, plunges into the material, makes its cuts, lifts back up, and shuts down. Almost every CNC program follows this same basic structure. Once you see the pattern, reading code becomes much easier.
What are the most common mistakes beginners make with G-code?
Confusing G0 and G1
G0 is rapid movement the machine goes full speed. If you accidentally use G0 instead of G1 during a cutting move, the tool will slam through the material at maximum speed. This breaks bits, ruins workpieces, and can damage your machine. Always double-check that cutting moves use G1 with an appropriate feed rate.
Forgetting the feed rate
If you write a G1 command without specifying a feed rate (F value), the machine uses whatever feed rate was last set. On the first move, that might be undefined or zero. Always include an F value with your first G1 move. Getting feed rates right for different materials takes practice our speed and feed chart by material is a good starting reference.
Not using a safe Z height
Before moving the tool horizontally, raise it to a safe height first. If you move X and Y while the tool is still at cutting depth, you'll drag the bit across your workpiece, leaving scratches or breaking the tool.
Mixing up absolute and incremental modes
If your code switches from G90 to G91 (or vice versa) and you don't notice, every coordinate after that point will be interpreted differently. This causes wildly incorrect tool positions. When editing code by hand, always be aware of which mode is active.
Not running a test pass
Never run a new or hand-edited G-code program at full cutting depth on real material. Instead, do a "dry run" with the tool raised well above the workpiece, or use air-cutting mode if your machine supports it. Watch the toolpath and confirm everything looks correct before you commit to cutting.
How do I find the right speeds and feeds for my material?
Speeds and feeds are where many beginners struggle most. The spindle speed (S) and feed rate (F) need to match your material, bit size, and machine rigidity. Too fast and you'll burn or break bits. Too slow and you'll get poor surface finish or rub instead of cut.
Start with manufacturer-recommended values for your specific bit and material combination. From there, adjust based on what you see and hear. A well-tuned cut sounds steady, produces consistent chips (not dust), and leaves a clean surface. If you hear squealing, see smoke, or notice the bit deflecting, slow down the feed or reduce the depth of cut.
Different materials need very different approaches. For example, cutting aluminum requires different parameters than MDF or plywood. If you're also working with laser cutters, remember that the speed and power dynamics are different see our guide on laser cutter code for wood signs for an example of how laser parameters work.
What software do I need to write or edit G-code?
You have several options depending on your budget and workflow:
- Plain text editors Notepad++ or VS Code work fine for viewing and editing G-code files. Use a G-code syntax highlighting plugin to make the code easier to read.
- CAM software Programs like Fusion 360, VCarve, or Estlcam generate G-code from your designs. They also let you edit the generated code before sending it to the machine.
- G-code simulators Software like CAMotics or NCViewer lets you visualize toolpaths before running them on your machine. These catch errors that are invisible in the raw code.
- Machine controller software Programs like GRBL Candle, Mach3, or LinuxCNC send code to your machine and often include built-in editors and visualization.
For beginners, the best workflow is: create your design in CAD, generate toolpaths in CAM, simulate in a visualizer, then send to the machine. You don't need to write G-code from scratch, but you should be able to read and make small edits when needed.
What are the differences between G-code dialects?
Not all machines interpret G-code the same way. Fanuc, Siemens, Haas, GRBL, and Mach3 all use slightly different flavors of G-code. The core commands (G0, G1, G2, G3, M3, M5) are nearly universal, but more advanced features vary.
Common differences include:
- Comment syntax Some machines use parentheses (like this), others use semicolons.
- Program header requirements Some controllers need specific lines at the start of a program.
- Subroutine syntax The way you define and call subroutines (reusable code blocks) varies significantly.
- Additional M-codes Machine-specific functions like automatic tool measurement or probing.
Always check your machine's documentation for its specific G-code dialect. If you download G-code from the internet, verify that it's compatible with your controller before running it.
How can I practice G-code without risking my machine?
Practice is essential, but you don't need to cut material to learn. Here are safe ways to build your skills:
- Use a simulator CAMotics and NCViewer are free and show you exactly where the tool moves. Write code, paste it in, and watch the toolpath.
- Read existing programs Export G-code from your CAM software and read through it line by line. Compare what the code says to what you see in the simulation.
- Make small edits Change a feed rate or depth value in a proven program and simulate the result. This teaches you how each parameter affects the cut.
- Use air-cut mode Run programs with the tool raised above the material. The machine executes the code but doesn't touch anything.
- Start with simple shapes Write a program to cut a square, then a circle, then a simple pocket. Complexity comes later.
When you're ready to move from simulation to real projects, having the right settings for your specific material makes a big difference. Bookmark resources like our speed and feed reference chart so you're not guessing when it counts.
Quick-start checklist for your first G-code program
- Set units (G20 for inches, G21 for millimeters)
- Set positioning mode (G90 for absolute)
- Move to home position (G0 X0 Y0)
- Turn on the spindle (M3 S[rpm])
- Move to safe Z height (G0 Z5 or similar)
- Set your feed rate (F value) before the first cutting move
- Plunge to cutting depth using G1, not G0
- Execute cutting moves at the correct feed rate
- Return to safe Z height before moving horizontally
- Turn off the spindle (M5)
- End the program (M30)
- Simulate or dry-run the program before cutting real material
Tip: Save a template file with your machine's standard preamble (units, positioning mode, safe height) and postamble (spindle off, program end). Every new program starts from that template, so you never forget a critical setup line. Over time, building a small library of proven, tested code snippets for common operations facing, pocketing, drilling will speed up your workflow more than any single command will.
Laser Cutter Code for Creating Wood Signs
Best Laser Settings for Leather Cutting Chart
Optimizing Engraving Parameters for Acrylic Laser Cutters
Cnc Router Bit Speed and Feed Chart by Material for Optimal Cutting
Maker Codes for Electronic Components Discount
Arduino Component Kit Deals with Maker Discount Codes