---
title: "The Most Basic G-Code Program Example, Explained Line by Line"
description: "A complete but minimal G-code program, explained one line at a time, so you can see how the common codes fit together. A teaching example, not a runnable file."
url: https://gcodepractice.com/journal/most-basic-g-code-program-example-ever/
canonical: https://gcodepractice.com/journal/most-basic-g-code-program-example-ever/
author: "Lawrence Arya"
authorUrl: https://www.linkedin.com/in/vibecoding/
published: 2026-06-02
updated: 2026-06-02
category: "Practice"
tags: ["beginner", "example", "g-code", "program"]
lang: en
---

# The Most Basic G-Code Program Example, Explained Line by Line

> **TL;DR** A minimal G-code program sets the units and positioning mode, rapids to a start point, turns the spindle on, feeds a cut, turns the spindle off, retracts, and ends. That is the whole skeleton: G21/G90 setup, G0 rapid, M3 spindle on, G1 feed, M5 off, G0 retract, M30 end. Seeing the common codes work together in one short example makes them click. This is a teaching example, not a file to run on a specific machine.

The fastest way for the codes to click is to see them work together in one short, complete program. Here is about the most basic one there is, walked through line by line. It is a teaching example to show structure, not a file to run on your machine, which would need its own offsets and safety setup.

## The program

```
G21 G90        (millimeters, absolute positioning)
G0 X0 Y0       (rapid to the start point)
M3 S1000       (spindle on, clockwise, 1000 rpm)
G1 Z-1 F100    (feed down to Z-1 at 100 mm/min)
G1 X20 F150    (feed across to X20 at 150 mm/min)
M5             (spindle stop)
G0 Z5          (rapid retract to a safe height)
M30            (end and rewind)
```

## Line by line

| Line | Code | What it does |
| --- | --- | --- |
| 1 | `G21 G90` | Sets millimeters and absolute mode (both modal) |
| 2 | `G0 X0 Y0` | Rapids to the start, not cutting |
| 3 | `M3 S1000` | Starts the spindle clockwise at 1000 rpm |
| 4 | `G1 Z-1 F100` | Feeds down into the work at a controlled rate |
| 5 | `G1 X20 F150` | Feeds a straight cut to X20 |
| 6 | `M5` | Stops the spindle |
| 7 | `G0 Z5` | Rapids up to a safe height |
| 8 | `M30` | Ends the program and rewinds |

Notice how the modal codes carry: `G90` set in line 1 governs every coordinate after it, and `G1` in line 4 is still active in line 5. That carry-forward is the [modal behavior](/journal/modal-vs-non-modal-g-codes/) beginners often miss.

## How to learn from it

Read the program and recall what each line does without the comments, the way you would in [beginner CNC code practice](/journal/beginner-cnc-code-practice/). Every code here is in the [common G-codes](/journal/common-g-codes-for-cnc-beginners/) and [common M-codes](/journal/common-m-codes-for-cnc-beginners/), and the difference between line 2 and line 4 is exactly [G00 vs G01](/journal/g00-vs-g01/). Reading programs this way is also why [G-code for mechanical engineers](/journal/g-code-for-mechanical-engineers-crash-course/) is worth a crash course. A free tool like [G-Code Sprint](/g-code-practice/) drills those codes so the example reads instantly.

## Bottom line

The most basic program is a short skeleton: setup, rapid, spindle on, feed, spindle off, retract, end. Learn to read it line by line and the codes become a language rather than a list. Treat it as a teaching example, not a file to run.

## Sources

- [LinuxCNC G-code reference](https://linuxcnc.org/docs/html/gcode/g-code.html)
- [Wikipedia: G-code](https://en.wikipedia.org/wiki/G-code)
- [CNCCookbook: G-code and M-code cheat sheet](https://www.cnccookbook.com/g-code-m-code-cnc-list-cheat-sheet/)

## Frequently asked questions

### What is the simplest G-code program?
One that sets units and mode, rapids to a start, turns the spindle on, makes one feed move, turns the spindle off, retracts, and ends. That skeleton, `G21`/`G90`, `G0`, `M3`, `G1`, `M5`, `G0`, `M30`, contains the common codes every program is built from.

### Can I run a basic G-code example on my machine?
Not as-is. A teaching example leaves out the work offsets, tool length offsets, and safety setup your specific machine needs. Use it to understand the structure, then follow your machine manual and instructor for a real, safe program.

### What is the best way to go from reading an example to writing one?
Recall what each line does without looking, then try changing one value at a time. A free tool like G-Code Sprint drills the codes so that when you read an example, every line already means something.

*G-Code Sprint is a study and practice tool only. It is not a CNC simulator, machine controller, or safety authority. Always follow your instructor, employer, machine manual, and shop safety procedures.*

---

Source: https://gcodepractice.com/journal/most-basic-g-code-program-example-ever/
Author: Lawrence Arya — https://www.linkedin.com/in/vibecoding/
