G84 G-Code: Programming Tapping Cycles in CNC

CNCCookbook’s G-Code Tutorial

Introduction: Tapping on CNC Machines with G84

G84 g code is commonly used to program tapping.  Tapping is a common operation used to thread holes on CNC Machines. For more on the Feeds and Speeds as well as the different kinds of taps and tap holders, see our companion Tapping Feeds and Speeds article. In this article, we’ll be looking at two ways of programming tapping on a CNC:

– Tapping Cycles that can use the Rigid Tapping capabilities of your CNC Machine.

– Long Form (no canned cycle is needed or used) programming when a Tapping Head or Tension-Compression Tap Holder is to be used on machines that do not have Rigid Tapping.

How to Program Rigid Tapping With a G84 Canned Cycle

To use Rigid Tapping, your machine must support the synchronization of feed motion with the spindle speed. This is typically an extra-cost option for CNC Machines and is harder to come by on older machines. The most common GCodes for Rigid Tapping Cycles are:

– G84 G Code: Tapping of right hand threads to be done with M3 spindle rotation.

– G74 G Code: Tapping of left hand threads to be done with M4 spindle rotation.

With some machines and controls, just simply using these cycles is sufficient for Rigid Tapping. On others, you must trigger a Rigid Tapping motion mode using another code. M29 is the common way to do this on Fanuc controls, for example.

Let’s say we want to tap a 1/4-20 thread 0.500″ deep at 0, 0. Here’s the code to do that with G84 G Code:


( Speed and Feedrate )

( Tapping )
G00 X0.0 Y0.0
G01 M29
G84 Z-0.5 R0.2

Let’s go through line by line:

M03 to get the spindle moving in the right direction and M8 to turn coolant on.

Next we set spindle speed to 400 RPM and feedrate to 20. With this particular cycle, it expects feedrate in threads per inch (or mm in metric mode).  Feel free to use our Tapping Feeds and Speeds Calculator.

Next we move down to Save Z and XY. We switch to G01 and we use M29 to turn on Rigid Tapping. Lastly, we run the G84 with Z indicating the bottom of hole coordinate and R indicating the retract coordinate.

If we had more holes to tap we could list their XY coordinates immediately following like this:

G84 Z-0.5 R0.2

X0.0 Y1.0

X0.0 Y2.0


G84 G Code is modal like most canned cycles. When we’re done with it, we use G80 to cancel or simply switch to an alternate motion mode such as G00, G01, another canned cycle, or an arc.

Pretty simple with a canned cycle, right?

That code is straight from G-Wizard Editor’s Conversational CNC Tapping Wizard, which can generate the gcodes for such cycles very easily. Here’s what the Wizard’s popup looks like with the settings for this example:

g84 g code tapping

Answer a few simple questions and G-Wizard Editor’s Conversational CNC will generate your tapping code for you…


How to Program Tapping on Machines that Lack Rigid Tapping

If your machine can’t do Rigid Tapping, you’ll need to use a special tap holder. There are two common types described in our companion article on tapping: a Tapping Head or a Tension-Compression Holder. There are pros and cons for each described in the other article.

The purpose of the special holder is to allow some up/down motion of the tap in case the spindle speed isn’t precisely right for the feedrate. This lets the threading process itself regulate the true feedrate and it works well. A tapping head has some other functions that enable it to tap faster too.

Here’s a quick video of a tension compression tapping head:

Programming these is fairly straightforward. Here is some basic code:


( Speed and Feedrate )

( Tapping )
G00 X0.0 Y0.0
G01 Z-0.5
G00 Z1.0

Same sort of thing but in this case, it is done long-form with no tapping cycle. You could use one of the canned cycles to shorten the code, but it’s so simple to use the long-form, why not?

There are some embellishments to the code that may be helpful depending on the equipment you’re using:

1. A Tapping Head may have a gear ratio that allows it to retract faster. You’ll want to change the feedrate when retracting if yours does.

2. A Dwell at the bottom of the hole may be helpful as the spindle reverses to even out the amount of spring adjustment being used.

3. For a lot of these devices, it can be helpful to drag the feedrate a bit. About 5% should do it. This is due to many of them performing better in tension than compression.

You can see all of those options are available on the G-Wizard Editor Conversational screen above.


Tapping is a very commonly used function. Peter Smid says it is second only to drilling holes. It’s easy to program either by hand or using a tool like G-Wizard Editor’s Conversational CNC. Don’t be afraid to program it on your machines now that you know how.


1. Use GW Editor’s Conversational CNC Tapping Wizards to generate code for the different kinds of tapping so you can see how it should work.

2. Learn the Different Types of Thread Taps that you may be called upon to use on CNC Jobs.

Next Article: Programming Haas CNC Machines: Haas’s unique g-codes and other differences

Recently updated on April 30th, 2024 at 10:54 am