Useful FANUC Codes

steelexodus@tilde.club:~$: date
2026-08-14

steelexodus@tilde.club:~$: cat /posts/2026/08/14-useful-fanuc-codes.md

FANUC G-Codes and M-Codes I use a lot

Introduction

Below you will find a list of M- and G-Codes I use a lot inside my CNC programs.

M-Codes

M99 - Restart Program

This will reset the program and start running from the top again. Useful for something that needs to keep executing.

NOTE: Make sure your panel supports this, as this is usually reserved for sub-program return.

M19 - Lock Chuck

Milling machines used this to align the spindle for tool changes, but it can also be used on turning machines to lock the chuck in place.

G-Codes

G04 - Dwell

The one machine I work in requires that the tool does not start cutting 500ms after indexing. I use this after each tool change to ensure that the program does not continue before that.

The code excepts the X value to tell it how long to wait. For example, to wait 500ms, use:

G04 X0.5;

To make the machine wait for 1.25 seconds, use:

G04 X1.25;

You get the idea.

G28 - Zero Axis

Before a tool is indexed, I like to return the machine home so there is ample space to rotate the turret. I use it like this:

N0303; <- Block to get to tool quickly
G28 U0. W0.; <- Zero both axis at the same time
...
G28 U0. W0.; <- Ditto
M01;
;

Using G28 U0. W0. will zero both axis at the same time. To zero the Z axis, you can use G28 W0., and for the X-axis you can use G28 U0..

steelexodus@tilde.club:~$: cd ~