G40 is the G-code for canceling cutter compensation. If you’ve been using G41 or G42 to offset your tool, G40 is how you turn that off.
G40 is a simple code to use, but there are two rules to know about using it that can prevent a serious machine crash. Make sure you know both.
Key Takeaways
- G40 cancels cutter compensation (G41 left, G42 right)
- When G40 is active, the tool center follows the programmed path exactly
- Always cancel cutter comp while the tool is clear of the part
- Always include a move on the same line as G40 — never cancel without one
- G40 is often found in safety lines at the start of a program or operation
| G40 – At A Glance | |
|---|---|
| Function | Cancel cutter compensation |
| Type | Modal (Group 7) |
| Cancels | G41, G42 |
| Cancelled by | G41, G42 |
| Used on | Milling machines, machining centers |
What Does G40 Do?
G40 turns off cutter compensation. When it’s active, the CNC controller stops offsetting the tool based on the D offset value — the center of the cutter follows the tool path exactly as programmed.
In the animation below, the arrows represent the programmed tool path. With G40 active, the cutter center tracks those lines directly.

Compare that to G41 (cutter comp left) and G42 (cutter comp right), where the controller shifts the cutter sideways by the tool radius so the edge of the tool follows the path — not the center.


What Is Cutter Compensation?
Cutter compensation is a CNC feature that lets you program a tool path based on the finished part geometry — and then let the controller handle the offset math for you.
Instead of calculating the tool center path yourself, you set a D offset value equal to the tool radius. The controller shifts the tool left (G41) or right (G42) by that amount so the cutting edge follows your programmed profile.

This is useful when you want to run the same program with tools of slightly different diameters, or when you need to make a fine finishing pass by adjusting the D offset without rewriting the program.
Two Rules for Canceling Cutter Compensation
This is where most problems happen. Follow both rules every time you use G40.
Rule 1: Cancel off the part
Cancel cutter compensation only when the tool is clear of the part by more than half the cutter diameter. If you cancel while the cutter is still engaged, the controller removes the offset instantly — and the tool snaps back to the programmed center path. That can mean an unexpected move into the part.
A safe method: raise the tool in Z above the part before canceling comp. Once the tool is clear, program G40 with a move.
Rule 2: Always make a move with G40
Don’t program G40 on a line by itself with no axis movement. Some machines react unpredictably when cutter comp is canceled without a motion block — the controller expects to use that move to ramp out of the compensation. Without it, behavior can vary by machine.
Always pair G40 with an X, Y, or Z move.
Example — Cancel cutter comp safely:
G40 G00 Z1.0 (Cancel cutter comp and rapid up to safe Z)
COMMON MISTAKE – Canceling While In Contact With The Part
When the offset is removed mid-cut, the tool center jumps to the programmed path — which can put the cutter in an unexpected position and damage the part or cause a crash.
Always exit the part before calling G40.
G40 in a Program
Here’s a short example showing G41 turning on, running a contour, and then G40 canceling it cleanly:
G90 G54 G00 X-1.0 Y0.0 (Rapid to approach position, off the part)
G43 H01 Z0.1 (Tool length comp)
G41 D01 G01 X0.0 Y0.0 F20.0 (Turn on cutter comp left, lead-in move)
X4.0 (Cut along profile)
Y4.0
X0.0
Y0.0 (Return to start of profile)
G40 G00 X-1.0 Y0.0 (Cancel cutter comp with a move off the part)
G00 Z1.0 (Retract)
Notice that G41 is turned on during a lead-in move that approaches the part from off the material — and G40 is canceled with a move that exits the part before the tool is retracted.
Where G40 Shows Up in Programs
G40 appears most often in two places:
Safety lines at the top of the program or operation
Safety lines are a set of modal codes that put the machine into a known state before cutting begins. G40 is included to make sure cutter comp is off before the program runs — even if it was accidentally left on from a previous operation.
A typical safety line might look like this:
G90 G40 G49 G80 G17
This one line cancels cutter comp (G40), tool length comp (G49), any active canned cycle (G80), sets absolute mode (G90), and selects the XY plane (G17).
After a contouring operation
Any time you use G41 or G42 to run a profile, you’ll end the operation with G40.
Other Cancel Commands
G40 is one of several cancel codes in CNC. Here are the most common:
Code | Description |
G40 | Cancel cutter compensation |
G49 | Cancel tool length compensation |
G50 | Cancel scaling |
G67 | Cancel custom macro call |
G69 | Cancel rotation |
G80 | Cancel canned cycles |
faqs
What happens if I forget to program G40?
If cutter comp is left on from a previous operation, the next tool may run with an unintended offset active. This is why G40 is included in safety lines — it acts as a reset to guarantee comp is off before the program starts cutting.
Can G40 be used on a lathe?
Cutter compensation (G41/G42) is primarily a milling function for offsetting an end mill or similar tool. Some CNC lathes do support a form of cutter comp for turning, but G40 usage varies by control. On most Fanuc-based lathes, G40 cancels nose radius compensation.
Does G40 need to be on its own line?
No — and it shouldn’t be. G40 should always be combined with an axis move on the same block. Programming G40 alone without a motion block can cause unpredictable behavior on some controls.
What’s the difference between G40, G41, and G42?
G40 cancels cutter compensation. G41 activates it to the left of the tool path (as seen from the direction of travel). G42 activates it to the right. You use G41 or G42 to turn comp on, and G40 to turn it off.