G-Code Cheat Sheet: Most Common Codes Explained
A simple G-code cheat sheet covering the most commonly used CNC codes — G00, G01, G02/G03, G28, G90/G91 and more, explained for beginners.
Category: CNC Programming
Introduction
G-code is the language CNC machines understand. While CAM software generates most of it automatically, understanding the basics helps you read programs, troubleshoot issues, and make small manual edits with confidence. Here’s a practical cheat sheet covering the codes you’ll see most often.
Understanding the Basics
G-code is made up of lines called blocks, each containing commands. A typical line looks like this:
G01 X10.0 Y5.0 F150
This tells the machine: move in a straight line (G01) to position X10.0, Y5.0, at a feed rate of 150 (units per minute).
Most Common G-Codes
| Code | Name | What It Does |
|---|---|---|
| G00 | Rapid Positioning | Moves the tool quickly to a position (not cutting) |
| G01 | Linear Interpolation | Moves the tool in a straight line while cutting, at a set feed rate |
| G02 | Circular Interpolation (Clockwise) | Cuts a clockwise arc |
| G03 | Circular Interpolation (Counter-clockwise) | Cuts a counter-clockwise arc |
| G20 | Inch Units | Sets measurement units to inches |
| G21 | Metric Units | Sets measurement units to millimeters |
| G28 | Return to Home | Sends the machine to its home/reference position |
| G40 | Cutter Compensation Off | Cancels tool diameter compensation |
| G54–G59 | Work Coordinate Systems | Selects a specific work offset/origin point |
| G90 | Absolute Positioning | All coordinates are measured from a fixed origin point |
| G91 | Incremental Positioning | All coordinates are measured relative to the current position |
Most Common M-Codes
| Code | Name | What It Does |
|---|---|---|
| M00 | Program Stop | Pauses the program |
| M03 | Spindle On (Clockwise) | Starts the spindle rotating clockwise |
| M04 | Spindle On (Counter-clockwise) | Starts the spindle rotating counter-clockwise |
| M05 | Spindle Stop | Stops spindle rotation |
| M06 | Tool Change | Initiates a tool change |
| M08 | Coolant On | Turns coolant on |
| M09 | Coolant Off | Turns coolant off |
| M30 | Program End | Ends the program and resets to the beginning |
A Simple Example Program
G21 (set units to millimeters)
G90 (absolute positioning)
G54 (select work coordinate system 1)
M03 S1000 (spindle on clockwise, 1000 RPM)
G00 X0 Y0 (rapid move to start position)
G01 Z-5 F100 (feed down into material)
G01 X50 F150 (cut a straight line to X50)
G00 Z10 (retract tool)
M05 (spindle off)
M30 (end program)
Frequently Asked Questions
Do I need to write G-code manually? Rarely. CAM software generates it automatically from your CAD design. Understanding the codes helps you read, troubleshoot, and make small edits — not write full programs from scratch.
What’s the difference between G90 and G91? G90 (absolute) measures every position from a fixed zero point. G91 (incremental) measures each move relative to the tool’s current position. Most beginners should stick with G90 until comfortable.
Why does my program throw an error? Common causes include missing coordinates, incompatible codes on the same line, or referencing a work offset (like G54) that hasn’t been set. See our Troubleshooting Common G-Code Errors guide for details.
What to Read Next
- CNC Machining Glossary (A–Z Terms)
- Best CAD/CAM Software for Beginners
- How to Write Your First G-Code Program
