M04 CNC Code Explained: An Easy Intro for Beginners [Spindle On Counterclockwise]

What does a M04 CNC code do?

The M04 code turns the CNC spindle on in a counterclockwise direction.

On a CNC mill, M04 is used with left hand tools. This is far less often used compared to the M03 (clockwise) command.

The M04 is often programmed together with a spindle speed using the S code such as S2500 M03.

Programming the speed on a previous line is also acceptable. Using the code below will functionally be no different than S2500 M04.



If no speed is given on the same line as the M04 code, the CNC machine will use the last set speed in the machine’s memory.

To ensure the proper speed is set when turning the spindle on with M04, it is good practice to set the speed even if it has not changed since it was last set.

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

M4 vs M04

Some people get confused about whether the 0 is required to include with an M04 code.

To clear this up, there is no need to include the zero in the code. 

The CNC machine will read the code the same. It really is just a matter of preference.

Often you will see the full M04 code used in textbooks or other reference materials. In practice though, many prefer the shortened M4 code in their programs.

If you are working on your own, then go with whichever format you prefer. 

If you work in a bigger shop, make sure to stick to the format that the business has been using.

M03 vs M04

Spindle direction

There are two codes for turning the CNC spindle on.

M03 turns it on in a clockwise direction. M03 is used with right hand tooling.

M04 turns it on in a counterclockwise direction. M04 used with left hand tooling.

If you need to change directions, then it is best to stop the spindle before changing directions.

Which code turns off the spindle?

The code to turn off the CNC spindle is M05.

The same M05 code is used no matter which direction the spindle is currently rotating.

Other CNC codes to know when working with M04

Because the M04 code is used so often, there are a number of codes that are used together with the M03 command. 

Some of the most frequently used are:

  • S – Sets the spindle speed – Most controllers will allow a range of either 1-9,999 or 1-99,999
  • M05 – Spindle stop
  • G96 – Constant surface speed mode – On lathes this mode tells the machine to maintain a constant surface speed so as the part being machined gets smaller, the spindle will turn faster to maintain the same speed at the cutting point
  • G97 – RPM speed mode – This code tells the CNC to run the spindle at a constant number of revolutions per minute

Want to learn more about CNC G Code?

Leave a Comment