O CNC Code Explained: An Easy Intro for Beginners [Program Number]

Welcome to the exciting world of CNC programming!

If you’re curious about the O CNC code and want to learn how to use it, you’ve come to the right place.

In this easy-to-follow guide, we’ll teach you everything you need to know. Don’t worry if you’re new to this, because the O code is super easy to learn.

So, let’s jump in to discover the O CNC code together!

What does the O code do?

The O code lists the CNC program number. 

It is found on the first line of a CNC program.

Example program numbers

Code BlockProgram Number

What range of numbers can you use with the O code?

Most controllers allow the use of program numbers O0001 through O9999.

Some newer machines allow a larger range of program numbers, but they would rarely be used or needed.

O code program example

Code BlockCode Description
O0001(Program number: O0001)
G90 G80(Absolute positioning mode, cancel canned cycles)
G54 G0 X0 Y0 (Select coordinate system G54, rapid move to X0 Y0)
M3 S1000(Start spindle clockwise at 1000 RPM)
G43 H1 Z0.1(Tool length compensation active, move Z to 0.1)
G1 Z-0.5 F100(Linear move to Z-0.5 at a feed rate of 100)
X1 Y1(Linear move to X1 Y1)
X0 Y0(Linear move back to X0 Y0)
G0 Z1(Rapid move to Z1, retracting the tool)
M30(End of program and rewind)

Learn CNC Programming – It’s Easier Than You Think!

Learning G Code doesn’t have to be difficult…

If you know what to focus on.

Join our simple, easy-to-follow course, “G Code Made Easy: CNC Programming for Beginners“. We walk you through all the important codes – with simple explanations and real-world examples.

Want to become a super-skilled CNC programmer? Join now to take the shortcut to becoming a G Code Master today!

Make Learning G Code Easy

Using the O code when running subprograms with M97 and M98

Subprograms are reusable pieces of code that are often used for repetitive tasks such as drilling holes or changing a tool.

There are two codes used to call subprograms; M97 & M98.

When using M98, the P code is used to choose the subprogram to be run.

For example, M98 P5678 will tell the CNC to run subprogram O5678.

M98 Code Flow

M98 calls a separate program.

The M97 code calls a subprogram by line number in the current program.

Important: M97 and M98 call subprograms differently. M97 jumps to another line in the current program. M98 moves to a completely separate program.

An example of this is M97 P500 will tell the machine to jump to line number 500 in the current program. The N code notes the line number.

illustration that shows the flow of a cnc program when using the m97 command to call a subprogram

Want to learn more about CNC G Code?

Leave a Comment