🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Manufacturing & Marine › CNC Machining › G-Code Programming for CNC Mills and Lathes › Lesson 2
MFG-CNC14-04 · Lesson 2 · 14 clock hours · theory

G-Code Word-Address Format and Program Structure

Objective. Students write syntactically correct G-code blocks using proper word-address format, define every field in a program header and footer, and explain the difference between modal and non-modal codes.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by a licensed engineer or certified journey-level tradesperson or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

What Is Word-Address Format?

Every line of G-code you write follows a convention called word-address format. A word is a single letter (the address) paired with a number (the value). For example, `X1.500` is one word: address `X`, value `1.500`. A complete line of G-code is called a block. A block is a sequence of words that the control reads and executes as one command.

The general structure of a block looks like this:

```

N0010 G01 X1.500 Y-0.750 Z-0.100 F15.0

```

The control reads left to right within the block, but on Haas controls the order of word types is largely fixed by convention: N, G, axis words, feed/speed, M. Always follow the format your control expects.

Address Letters and Their Meanings

Each letter of the alphabet has a defined role in CNC. The most common ones you will use every day:

| Address | Meaning |

|---------|---------|

| O | Program number |

| N | Block sequence number |

| G | Preparatory function |

| M | Miscellaneous function |

| X, Y, Z | Axis moves (mill); X, Z (lathe) |

| A, B, C | Rotary axis moves |

| I, J, K | Arc center offsets |

| R | Arc radius or canned-cycle retract |

| F | Feed rate |

| S | Spindle speed |

| T | Tool number |

| H | Tool length offset number |

| D | Cutter diameter offset number |

| P, Q | Canned-cycle parameters |

| L | Subprogram repeat count |

Memorise these. NIMS and Haas assessments both test address recognition.

Program Structure: Header and Footer

Every CNC program has a defined beginning and end.

Header (mill example):

```

O0100 (PROGRAM NUMBER)

% (start-of-tape character — Haas convention)

G20 (inch mode)

G17 G40 G49 G80 G90 (safety block)

T1 M06 (tool call: tool 1, execute tool change)

G43 H1 (tool length compensation on, using offset 1)

S2500 M03 (spindle 2500 RPM, clockwise)

M08 (coolant on)

```

Safety block explained: `G17` selects the XY plane. `G40` cancels cutter compensation. `G49` cancels tool length offset. `G80` cancels any active canned cycle. `G90` selects absolute positioning. Writing all five on one line at the start of every program is an industry habit that prevents the machine from inheriting a dangerous mode left over from a previous program.

Footer:

```

M09 (coolant off)

G28 G91 Z0. (return Z to machine home, incremental)

G28 G91 X0. Y0. (return X and Y to machine home)

G90 (back to absolute)

M30 (program end and rewind)

%

```

`M30` ends the program and rewinds the pointer to the top. Never leave it out — a program without `M30` will continue reading whatever memory follows, which can cause unexpected motion.

Lathe header differences: Use `G18` (XZ plane), omit `G17`. Replace `H` with `T` format (on most lathes, `T0101` means tool 1, offset 1). Spindle direction for turning is typically `M03` (forward). Feed is often in inches per revolution (`G99`) rather than inches per minute.

Modal vs. Non-Modal Codes

This distinction appears on every major credentialing exam.

Modal codes stay active until cancelled or replaced. Once you write `G01`, every subsequent block commands linear interpolation until you write a different motion code such as `G00` or `G02`. Modal codes belong to modal groups. Only one code from a group can be active at a time. For example, `G90` (absolute) and `G91` (incremental) are in the same modal group — you cannot have both on simultaneously.

Non-modal codes are active for one block only. `G04` (dwell) is a common example: it pauses motion for the time or number of revolutions you specify, then the control acts as if `G04` was never written.

Knowing the modal group of a code helps you avoid conflicts. Haas publishes a complete modal-group table in their operator's manual — keep a copy at your machine.

Safety Note

Before running any program you have written:

1. Dry run — use the machine's single-block mode and feed-hold to step through the program with the spindle off and the part clear.

2. Verify tool offsets — an incorrect `H` or `D` value can drive the cutter into the part or fixture.

3. Check rapid moves — `G00` moves at full machine speed; confirm the path is clear.

4. Lockout/tagout (LOTO) applies whenever you are inside the machine envelope performing setup. Program editing at the control pendant does not require LOTO, but tool changes and workholding adjustments do.

5. Wear safety glasses any time the machine is powered.

Key terms10

WordA single address letter paired with a numerical value, forming the smallest unit of G-code (e.g., X1.500).
BlockOne complete line of G-code that the control reads and executes as a single command; made up of one or more words.
AddressThe letter prefix of a word that identifies the type of data that follows (e.g., G, M, X, F, S).
Modal codeA G- or M-code that remains active until another code in the same modal group replaces or cancels it.
Non-modal codeA G- or M-code that is active for only the block in which it is written, then has no further effect.
Modal groupA set of G-codes that control the same machine function; only one code from the group may be active at a time.
Safety blockA block written at the program start — typically G17 G40 G49 G80 G90 on a mill — that cancels potentially dangerous inherited modes.
O-numberThe program identification number assigned to a CNC program, written as the O-address followed by up to four or five digits depending on the control.
M30The miscellaneous code that signals program end and rewinds the control's program pointer to the beginning of the program.
G28A non-modal code that commands the machine to return the specified axes to the machine home (reference) position, passing through an intermediate point if commanded.
In class: Dissect three sample programs line-by-line on a printed worksheet, underlining each word, identifying the address letter, numerical value, and function for every block. · Build a reference card listing at least 20 G-codes and 10 M-codes with their modal group, function, and an example block; cards are peer-reviewed for accuracy. · Write a program skeleton—O-number, safety header, tool call, spindle on, coolant on, rapid to home, program end—for both a mill and a lathe context without using a computer, then verify against the Haas G-code list.
Materials: Haas Mill and Lathe G-code/M-code reference lists; sample programs (3 mill, 3 lathe); printed block-dissection worksheets; Smid CNC Programming Handbook Chapters 2–3
Check: Block-dissection worksheet graded by instructor; students must correctly parse ≥90% of 30 targeted blocks with correct address, value, and function identified.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

NIMS Machining L1 — CNC fundamentals
1. In the word `F18.0`, the address is _____ and the value is _____.
NIMS Machining L1 — G-code theory
2. Which of the following best defines a modal G-code?
Haas Certification — program structure and safety
3. A machinist forgets to include a safety block at the start of a new program. What is the most likely risk?
Haas Certification — G-code reference
4. On a Haas mill, which code cancels an active canned cycle?
NIMS Machining L1 — address letters
5. Which address letter is used to call a specific tool on a Haas mill?
NIMS Machining L1-2 — modal groups
6. G90 and G91 cannot both be active at the same time because they are:
Haas Certification — program structure
7. A student writes the program footer without M30. What is the most likely consequence when the program is run?
NIMS Machining L1 — CNC safety practices
8. Before running a newly written program on a CNC mill for the first time, the safest immediate action is to:
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.