# CNC Program Header and Safe Start Block Generator

> Source: https://netray.co/tools/cnc-program-header-and-safe-start-block-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Create a consistent program header with revision comments, a safe start line and a tool change sequence for a mill.

## Category

developer

## Industry

Machining

## Audience

- CNC programmer
- Machinist
- Manufacturing engineer

## Tool

**Kind:** template

**Output:** code

**Language:** text

**Fields:**

#### Program number

**Key:** prog

**Type:** text

**Default:** 4821

#### Part number

**Key:** part

**Type:** text

**Default:** BRKT-48213-A

#### Drawing revision

**Key:** rev

**Type:** text

**Default:** C

#### Operation

**Key:** op

**Type:** text

**Default:** OP10 FACE AND POCKET

#### Programmer initials

**Key:** programmer

**Type:** text

**Default:** AJ

#### Date

**Key:** date

**Type:** date

**Default:** 2026-10-20

#### Work offset

**Key:** wcs

**Type:** select

**Options:**

- G54
- G55
- G56
- G57
- G58
- G59

**Default:** G54

#### First tool number

**Key:** tool

**Type:** text

**Default:** 1

#### Tool description

**Key:** tooldesc

**Type:** text

**Default:** 50 MM FACE MILL

#### Spindle speed (RPM)

**Key:** rpm

**Type:** text

**Default:** 1800

#### Safe Z clearance

**Key:** safez

**Type:** text

**Default:** 100.0

#### Coolant code

**Key:** coolant

**Type:** select

**Options:**

- M8
- M7
- M88
- none

**Default:** M8

**Blocks:**

#### Program header and first tool

**Body:** %
O{{prog}} ({{part}} REV {{rev}})
({{op}})
(PROGRAMMER {{programmer}}, {{date}})
(T{{tool}} {{tooldesc}})
(WORK OFFSET {{wcs}})
G90 G17 G40 G49 G80 G94 G21 (SAFE START LINE)
G91 G28 Z0 (RETURN Z TO HOME)
G90
T{{tool}} M6
{{wcs}} G0 X0.0 Y0.0 S{{rpm}} M3
G43 H{{tool}} Z{{safez}}
{{coolant}}
(MACHINING BLOCKS GO HERE)
G91 G28 Z0
M9
M5
G28 X0 Y0
M30
%

**Notes:** This is a generic Fanuc style starting point for a milling center. Metric units (G21) are assumed, so change to G20 for inch programs. Verify the coolant codes, return to home commands and tool change macro on your machine. Review every program in single block before first cut.

## Content

**Intro:** Consistent program headers make NC programs easier to find, review and trust. A good safe start line cancels everything left over from the previous program, so the first move does what the programmer intended. This generator builds that header in a few seconds.

**Sections:**

#### How to use the generator

**Body:** Fill in the program number, part number, drawing revision, operation and the first tool. The code block updates immediately. Copy the result into your CAM post, editor or machine, or export it to include in a setup package. Adjust the home return and tool change blocks to match your machine builder's recommendations.

#### What the safe start line does

**Body:** G90 selects absolute mode, G17 selects the XY plane, G40 cancels cutter compensation, G49 cancels tool length compensation, G80 cancels any canned cycle and G94 sets feed per minute. G21 selects metric units. Together they put the control in a known state regardless of what the last program or MDI command left active.

**Bullets:**

- G90 absolute positioning
- G40 and G49 cancel compensation
- G80 cancels canned cycles
- G94 feed per minute, G21 metric

#### Why the header comments matter

**Body:** Part number and drawing revision in the first comment let an operator verify they loaded the right program for the job on the traveler. Many shops also record the programmer and date so a change can be traced. Keep comments short and uppercase, since some controls limit comment length or character sets.

#### Common mistakes

**Body:** Leaving out G49 before a tool change on a machine with a leftover offset, starting without a Z home return, and putting a work offset call after the first rapid. Another mistake is changing the revision in the drawing but not in the program header, which defeats the point of the comment.

**Cta:** If drawing revisions, NC programs and traveler data live in different systems, we can discuss linking them so the right program is always tied to the right revision.

**Faq:**

#### What is a safe start line in G-code?

**Answer:** It is a block at the top of a program that cancels modal states such as cutter compensation, tool length compensation and canned cycles, and sets absolute mode and units. It prevents leftover settings from affecting the first moves.

#### Do I need G28 before a tool change?

**Answer:** It depends on the machine. Many mills require Z at its home position before M6, and some do this inside the tool change macro. Follow the machine builder's recommended tool change sequence for your model.

#### Should the header use G20 or G21?

**Answer:** Use G21 for metric and G20 for inch programs. Some shops avoid mixing by setting units in the post processor and a comment in the header, so operators never wonder which system the program uses.

#### Can I add more tools to this template?

**Answer:** Copy the generated tool call, spindle start and G43 lines for each additional tool and change the numbers. Many CAM systems do this automatically; the template is mainly for hand written programs and standard headers.

## Search terms

cnc program header template, g-code safe start line, cnc safe start block, g-code program template, fanuc program start block, cnc program format standard, haas program header, cnc tool change template

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
