G98 CNC Code Explained: An Easy Intro for Beginners [Return to Initial Plane]

What does a G98 code do?

The G98 code is a modal command that tells the cutting tool to move back to the initial plane after finishing a canned cycle operation.

Often, CNC machines will have this command set to “on” by default.

G98 is a very important code because it allows you to avoid clamps, fixtures, and other obstacles that may be present when machining.

The alternative to G98 is G99. 

The G99 code also controls the movement of the machine after finishing a canned cycle.

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

G98 vs G99

visualization of how a cnc machine moves using g98 and g99 codes shows motion of travel for the machine

Both codes are used to perform similar actions.

The difference is that they lift the tool to different heights when finishing a canned cycle process.

G98 lifts the tool back to the initial Z position which the machine was at when starting the canned cycle. This is safer option if you are unsure

The G99 code travels back to the R plane instead. The R plane is closer to the part which can potentially cause problems if you aren’t paying attention.  

Other codes and parameters used with the G98 code

When using the G98 code you should consider all of the following items that can be included as part of the code:

The feed rate will depend on the material that is being cut and the diameter of the drilling tool that you are using.

The retract (R) plane or clearance level refers to the plane height where the tool can move safely from one hole to another. 

The R value should be set so the machine will clear any and all obstacles including clamps, fixtures and the part itself.

X and Y are the location of the hole. Z controls the depth of the hole.

an illustration that shows the X, Y and Z axes on a CNC machine

G98 code format

Using the parameters above, the format for using a G98 code is:

G81 X0 Y0 R0 Z1 F5 G98

G81 is the canned cycle. This can be replaced with any other canned cycle as needed.

The rest of the codes are as listed in the parameters section above. The X, Y and F codes are not required. Often, the X and Y codes will be placed on the previous line.

It is good practice to include the feedrate (F) code.

What to think about when using a G98 code?

When using the G98 command, think about the obstacles that could be in the way of the movement of your cutter.

Using G98 will move your cutter to the initial plane which is the Z height at the start of the canned cycle. This is generally the safest location and should be set at a Z height above all obstacles in the machine.

Common obstacles in the machine are:

  • The workpiece
  • Clamps
  • Fixtures
  • Other tooling

You should also think about the speed of your program. 

For hobbyists, this isn’t as much of a concern. 

For industrial machines, the time it takes to move back to the initial plane instead of the R plane can add up and time is money in the machining industry.

G98 code example

N1 Z5.0 M08;

N2 G82 G99 Z-3.0 R1.0 P500 F50.0;

N3 X10.0;

N4 G98 X20.0;

N5 G99 X10.0;

N6 G80;

The first line (N1) brings the drill down to 5mm above the material surface and turns on the coolant with M08.

Then, the second line (N2) sets the counterbore canned cycle with G82 and tells the machine to return to the R plane where Z = 1.0.

The Z-3.0 is the depth of the counterbore and P500 is the dwell time when the machine reaches the bottom of the hole in milliseconds.

F is feed rate in mm/min.

Line 3 (N3) tells the machine to move the X axis of the machine to the X=10.0 location. Because the canned cycle is a modal code, another counterbore will be drilled to the same parameters as in line 2.

The next line (N4) drills the third hole at X=20mm. G98 tells the control to return to the initial plane. This is Z=5.0, the last Z location before starting the canned cycle. The machine will rapid back to Z=5.0 above the part surface after drilling the previous hole.

The machine drills the final hole 10mm in X from the last one, the G99 code tells the machine to rapid back to the R position instead of the initial Z position.

Lastly, on line 6 (N6) G80 turns the counterboring canned cycle off.

Frequently asked questions about the G98 code

Is G98 a modal command?

Yes, G98 is a modal command. 

Modal codes will stay on until changed to another code in the same code group or until they are canceled. 

It will only be in effect for running canned cycles though. G98 has no effect on straight line movement with either G00/G01 or circular movement with G02/G03.

What does the G98 code do on a lathe?

The G98 codes is completely different when running a CNC lathe.

G98 on a lathe sets the feed rate mode to feed rate per minute.

This means if you use a F100 command and G98 is active, the feed rate will be set to 100 inches per minute.

G99 on a lathe sets the feed rate mode to feed rate per revolution.

Want to learn more about CNC G Code?

Leave a Comment