G-Code Comments: How to Add Them (By Machine Brand)

G-code comments are notes inside your CNC program that the controller ignores. They help operators, setup people, and your future self understand what the program is doing — without changing how the machine runs.

Key Takeaways

  • Comments are ignored by the CNC controller — they’re notes for humans, not the machine
  • The two most common comment characters are parentheses () and the semicolon ;
  • Fanuc, Haas, Hurco, Mitsubishi, and Yasnac use parentheses; Heidenhain and Siemens use a semicolon
  • Place comments at the start of program sections and after key moves — not on every line
  • Avoid placing comments in the middle of a line if you want maximum machine compatibility

How G-Code Comments Work

A comment is a section of your program that the controller reads but skips over. It doesn’t move any axes, change the spindle speed, or trigger any machine action. Its only job is to communicate information to whoever is reading the code.

Different machine brands use different characters to mark a comment. Knowing which one your machine uses is important — use the wrong character and some controllers will throw an alarm.

Comment Characters by Manufacturer

Machine Control ManufacturerG-Code Comment Character
FanucParentheses ()
HaasParentheses ()
HeidenhainSemicolon ;
HurcoParentheses ()
MitsubishiParentheses ()
Sinumerik (Siemens)Semicolon ;
YasnacParentheses ()

When in doubt, check your machine’s programming manual. There are dozens of control manufacturers out there, and some older or less common controls use different conventions.

How Parentheses Work

When you use parentheses, the controller ignores everything between the opening and closing parenthesis:

G00 X1.0 Y1.0 (RAPID TO FIRST HOLE POSITION)
G43 H01 Z1.0  (TOOL LENGTH COMP - 1/2 INCH DRILL)

Only the text inside the () is treated as a comment. The rest of the line runs normally.

COMMON MISTAKE – Putting a semicolon inside parentheses on a Fanuc/Haas machine.

Why it matters: On these controls, the semicolon inside the parens is just part of the comment text — it won’t comment out the rest of the line. Only what’s inside the parentheses is ignored.

How the Semicolon Works

On Heidenhain and Siemens controls, a semicolon tells the controller to ignore everything after it on that same line:

G00 X1.0 Y1.0 ; RAPID TO FIRST HOLE POSITION
G43 H01 Z1.0  ; TOOL LENGTH COMP - 1/2 INCH DRILL

Everything to the right of the ; on that line is ignored. A semicolon on a Fanuc machine behaves differently — it marks the end of a block, not a comment.

COMMON MISTAKE – Using a semicolon as a comment on a Fanuc control.

On Fanuc, the semicolon is an end-of-block character (like a carriage return). Using it as a comment delimiter can confuse the controller or cause errors depending on the version.

What to Include in a G-Code Comment

Keep comments short and useful. A comment that fills three lines of text is harder to read than no comment at all.

Good things to include:

  • Tool number and description (T01 = 1/2″ DRILL)
  • Operation being performed (ROUGH FACE, FINISH BORE, DRILL HOLES)
  • Offset numbers being used (H01, D01)
  • Instructions for the operator (INSPECT PART BEFORE CONTINUING, FLIP PART HERE)
  • Program revision or date at the top of the file

Here’s a realistic example of a well-commented program header:

%
O1001 (PART: 12345-A HOUSING - REV 2)
(DATE: 2024-09-01  PROGRAMMER: B. FOWLER)
(MATERIAL: 6061 ALUMINUM)
(MACHINE: HAAS VF-2)
(-----TOOL LIST-----)
(T01 - 3/4 INCH FLAT ENDMILL)
(T02 - 1/2 INCH DRILL)
(T03 - 1/2-13 TAP)

This kind of header is worth the extra lines. Anyone who opens the program — including you, six months from now — can understand it at a glance.

Where to Put Comments in Your CNC Program

There are a few spots where comments consistently add value.

At the top of the program — Include a header block with the part name, revision, programmer name, date, machine, and tool list. CAM software often generates this automatically.

At the start of each section — When you switch from one operation to another (roughing to finishing, drilling to tapping), a comment line helps the operator track where they are:

(-----BEGIN DRILLING CYCLE-----)
G99 G83 Z-1.25 Q0.25 R0.1 F12.0

At the end of key lines — A brief note after a critical move or setting is enough:

G92 S3000 (SPINDLE SPEED LIMIT)
G50 S3000 (MAX RPM - LATHE)

Avoid Putting Comments in the Middle of a Line

Some Fanuc-based controls allow inline parentheses comments mid-line, but not all do. Stick to end-of-line comments for the best cross-machine compatibility.

When to Use Comments (And When to Skip Them)

Use comments where they genuinely help someone understand the program. You don’t need to comment every single line.

A good rule: comment at transitions and at the top of each tool or operation. That’s usually enough. If someone reads your header and your section comments, they should be able to follow the program without needing a note on every G00.

On older machines or machines with limited memory, excessive comments can increase program size. It’s rarely a problem today, but worth keeping in mind if you’re running a very old control.

FAQs

Do g-code comments slow down the machine?

No. The controller reads and ignores them — they don’t affect machine motion, feed rate, or cycle time in any meaningful way.

Can I put a comment anywhere in the program?

Generally, yes — but the safest approach is at the end of a line or on its own line. Putting comments in the middle of active code can cause errors on some controllers.

What happens if I use the wrong comment character for my machine?

On many controls, using the wrong character will just be ignored or cause a syntax error. On some machines, an unrecognized character in the wrong place can stop the program or trigger an alarm. Always verify the correct character for your specific control.

Do all CNC machines support comments?

Most modern CNC controls do. Very old or simplified controls may not support them, or may only support one format. When in doubt, check the programming manual for your specific machine.

Leave a Comment