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

CodeNameWhat It Does
G00Rapid PositioningMoves the tool quickly to a position (not cutting)
G01Linear InterpolationMoves the tool in a straight line while cutting, at a set feed rate
G02Circular Interpolation (Clockwise)Cuts a clockwise arc
G03Circular Interpolation (Counter-clockwise)Cuts a counter-clockwise arc
G20Inch UnitsSets measurement units to inches
G21Metric UnitsSets measurement units to millimeters
G28Return to HomeSends the machine to its home/reference position
G40Cutter Compensation OffCancels tool diameter compensation
G54–G59Work Coordinate SystemsSelects a specific work offset/origin point
G90Absolute PositioningAll coordinates are measured from a fixed origin point
G91Incremental PositioningAll coordinates are measured relative to the current position

Most Common M-Codes

CodeNameWhat It Does
M00Program StopPauses the program
M03Spindle On (Clockwise)Starts the spindle rotating clockwise
M04Spindle On (Counter-clockwise)Starts the spindle rotating counter-clockwise
M05Spindle StopStops spindle rotation
M06Tool ChangeInitiates a tool change
M08Coolant OnTurns coolant on
M09Coolant OffTurns coolant off
M30Program EndEnds 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

Leave a Reply

Your email address will not be published. Required fields are marked *