Quick Guide to the G86 CNC Code [Boring with Rapid Retract]

a graphic of a cnc machine with text that says learn g code today g86 boring cycle with rapid retract

What does a G86 code do?

The G86 command activates a boring canned cycle.

The steps the machine will take are:

  1. Rapid traverse to the R plane
  2. The machine will start boring/reaming from the R plane to the bottom of the hole (Z) at the listed feedrate (F)
  3. At the bottom of the hole, the spindle will stop and then the machine will rapid move back out of the hole.

This cycle will feed into the hole at a set feedrate but move at max speed coming back out.

The G86 canned cycle is very similar to G85 command except G85 will make the machine feed back out of the hole instead of rapid retract.

Want to learn more about CNC G Code?

What is boring?

Boring uses a single point cutting tool to create holes very accurately. This includes size, location and roundness requirements.

Boring involves creating a hole either by drilling it or some other means and then making it larger through the boring operation. Often this will require taking multiple passes to “sneak up” on the correct size requirements.

Parameters used with the G86 code

There are many different parameters used in a G86 code. They are similar to those used in other canned cycles. See the list below to understand all the different parts of the code.

The retracting value (R) or clearance level refers to the plane perpendicular to the Z-axis 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.

Format for using a G86 code

G86 X2.0 Y3.0 R1.0 Z-5.0 F25.0

It would be easy to assume that the Z location is the location of the start of the hole. In reality, it is the Z location for the bottom of the boring/reaming movement.

Keep in mind that the X and Y coordinates of the hole are not usually in the same line as the G86 command.

In most programs you will see them in this format:

X2.0 Y3.0

G98 G86 R1.0 Z-5.0 F25.0

The program first identifies the coordinates of the hole and then starts the boring/reaming process.

How to cancel a G86 code

The G80 code is used to cancel the G86 boring canned cycle. G80 is the code used to cancel all canned cycles.

If the G80 code is not used, the machine will attempt to bore a hole at each new location given in the program.

G85 vs G86

G85 and G86 are both boring canned cycles. They both move into the part at the set feedrate.

G85 feeds back out at that same feedrate. G86 stops the spindle and rapid retracts back out of the hole.

This means that G85 usually provides a better surface finish for the hole being machined, but takes more machining time.

R planes

The G86 code is most commonly used with the G98 code. Retract planes are important because they control how your machine will act when moving between locations when using canned cycles such as G86.

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

Retract planes should be chosen so that the machine avoids any and all obstacles such as clamps, fixtures and the workpiece itself. More info about the type of retract planes that can be used is shown below.

Want to learn more about CNC G Code?

Quick Guide to the G80 CNC Code [Canned Cycle Cancel]

a graphic of a cnc machine with text that says learn g code today g80 canned cycle cancel

What does the G80 CNC code do?

G80 is the code used to cancel all active canned cycles.

Canned cycles are sometimes referred to as fixed cycles and they are used for a variety of common machining tasks such as drilling or threading holes.

Want to learn more about CNC G Code?

What are canned cycles?

Canned cycles (also called fixed cycles) are G-codes that allow the machine to perform a pattern or series of movements automatically.

These commands simplify repetitive and common tasks, such as drilling holes, threading or boring.

So instead of programming every movement and function individually, a canned cycle controls a set of motions using a much smaller piece of code.

Peck drilling is a great example of how canned cycles make code easier to read and understand.

To create the code to execute the peck drilling motion shown in the picture above would require many lines of code. This would involve moving the cutter up and down repeatedly to “peck” its way down to the bottom of the hole.

With canned cycles this can be condensed to a single line of code that contains all of the necessary information.

List of canned cycles

When to use the G80 code?

The G80 code is used to turn off canned cycles.

Once you have drilled all the holes you need or threaded all the holes required, the G80 code can be used to stop drilling or threading.

If the G80 code is not used, once the machine is given a new location it will attempt to run the active canned cycle again at the new location.

The G80 code is also often used as part of a program’s safety lines to make sure that the machine is set to the correct mode.

If you needed to go back and only run a small portion of your program, it would be important to know that a canned cycle wasn’t accidentally left active by whatever code you ran last.

What other codes cancel canned cycles?

It isn’t good practice to not use the G80 command but there are other codes that turn off active canned cycles.

G00, G01, G02 and G03 all belong to the movement group of codes and will turn off any active canned cycles.

Remember it is not good practice to turn off your canned cycles using movement codes. Always make it clear that canned cycles have been turned off by using the G80 cancel command once finished running your canned cycles.

Want to learn more about CNC G Code?

Quick Guide to CNC Coolant Codes [M07, M08 & M09]

a graphic of a cnc machine with text that says learn g code today coolant codes

Which codes control coolant use on a CNC machine?

There are three main CNC M codes which control coolant use. 

M07, M08 and M09.

M08 and M09 are the most common codes used. In addition, many machines have special coolant functions available such as through spindle coolant.

Special coolant codes tend to vary from machine to machine so make sure to check your individual machine for specialty coolant function.

Want to learn more about CNC G Code?

M07 [mist coolant]

The M07 code is a modal command which turns on mist coolant.

Mist coolant is compressed air and coolant (usually oil). It can be more efficient than flood coolant and in some situations be better at clearing chips than flood coolant, but it is used far less often than flood coolant with the M08 command.

M08 [flood coolant]

cnc machine table with coolant lines and spindle shown
Flood coolant on a workpiece

M08 turns on the coolant for the main spindle.

In general, you will find this coolant aimed directly at the cutting edge of the tool.

Flooding the area with coolant has multiple benefits. The coolant reduces the heat build up from the cutting action, lubricates the cutter and helps to clear chips from the cutting area.

These three benefits of using flood coolant all work to reduce any heat that is caused by the cutting action which helps extend the life of your cutting tool.

M09 [coolant off]

The M09 code is used to turn off both types of coolant flow.

You never want to turn off coolant while the cutter is still cutting. On the opposite end of things, you should never turn coolant on if the cutter is already cutting.

Always start and stop coolant flow when the cutter is not actively engaged with the part.

What is coolant used for in CNC machining?

Coolant for CNC machines is used to keep the workpiece and cutting tool at a lower temperature during the cutting process.

Both the cutter and the part tend to get hotter because of the friction created cutting.

Coolant is also used to clear chips from the cutting area. If chips are not cleared from the cutting area then you can end up recutting chips. Built up chips can also lead to built up heat which can damage your cutter or part.

Recutting chips also has a tendency to create poor surface finishes.

Types of coolant that can be used

The main types of coolant used on CNC machines are:

  • Air: This type of coolant reduces heat and clears the chips, but it does not lubricate the workpiece. This type of coolant is used more often with sensitive materials.
  • Mist: With mist coolant, the pressure of the coolant is kept low and less coolant is used. This can be beneficial if your CNC doesn’t have a coolant capture system. Mist coolant lubricates the cutter and clears chips.
  • Flood: This is also a low-pressure form of coolant. Flood coolant lubricates, removes chips and reduces heat buildup.
  • High pressure: High pressure coolant is similar to flood coolant. The only difference is that it hits the workpiece at greater than 1000psi. The higher pressure and higher quantity of coolant helps cool the cutter better and remove more chips.
  • Through spindle: Through spindle coolant delivers the coolant directly where it is needed. It is better at clearing chips in many cases because the coolant from the spindle pushes the chips out of a hole or pocket.

What is CNC coolant made of?

Coolants are categorized into four groups depending on the material that they are made of:

  • Synthetic fluids: They are made of lubricants and rust inhibitors usually dissolved in water. It is basically soluble oil mixed with water to create coolant.
  • Semi-synthetic fluids: These coolants are a mix between synthetic polymer and oil.
  • Soluble oils: They contain a mix of 40 percent or more of oil and the rest is water.
  • Straight oils: These ones are derived from petroleum, they are not diluted with water.

List of common CNC coolant brands

There are many different brands of CNC coolant available. Some of the most commonly used ones are:

  • Castrol
  • Chem Arrow
  • ChemTool
  • Fuchs
  • Hangsterfers
  • Master Fluid Solutions
  • Quaker Houghton
  • Qualichem
  • Tower Coolant
  • Yushiro

Frequently asked questions

Does every CNC machine have coolant capabilities?

Yes and no.

You can expect that industrial level CNC machines will have coolant capabilities.

Home or hobbyist level machines such as CNC routers often do not have coolant capabilities, but they can usually be added on if needed.

cnc wood router
CNC router without coolant capability

Which code turns CNC coolant off?

The M-code to turn coolant off is M09.

However, there are other stopping commands that also turn off coolant such as:

Want to learn more about CNC G Code?

Quick Guide to CNC Safety Lines [Common Codes]

a graphic of a cnc machine with text that says learn g code today safety lines

What are CNC program safety lines?

Safety lines, sometimes called a safety block, are a section of code within a CNC program which are used to protect the machine, the workpiece, and the operator.

Safety lines are used to make sure the machine is in the proper mode/state which means that the machine will understand all the commands we give it correctly.

If you need the machine to work in inches (or mm in some parts of the world), it is important to frequently set the machine to work in those units. This is especially true if you will be switching between units when machining.

While many won’t switch between imperial and metric units, it is common to switch between absolute and incremental positioning modes.

The safety lines used will vary by machine however there are many which are common between the majority of machines.

Want to learn more about CNC G Code?

Types of codes found in a safety line

Safety lines can contain G codes for coordinate systems, measurement units, tool compensation, and cancelation functions. Each one of these commands is necessary to move the tool safely. 

Modal commands and cancel commands are two of the most common codes used in CNC safety lines.

Below are the most common safety codes found in CNC programs:

Positioning mode – G90/G91

The first code normally found in a safety line will be the machine’s positioning mode.

There are two positioning modes available to use. Absolute and incremental positioning.

Absolute positioning uses the G90 command. 

Absolute positioning mode tells the machine to interpret all locations it is given as measured from a fixed zero location (origin).

graph paper example of absolute positioning with multiple points as examples

Incremental positioning uses the G91 command.

Incremental positioning modes tells the machine that the zero location is wherever it currently is. Once the CNC makes a move in incremental mode, the new location becomes the zero location.

graph paper example of incremental positioning with multiple points as examples

Units mode – G20/G21

Selecting the system of units you will be working in is important. This is why the units mode is found in the safety lines of the program.

Imperial units are set with G20 (inches) and metric units are set with G21 (mm).

You don’t want to move 4 inches when you meant to 4 millimeters.

Setting the units mode is critical to running your CNC.

comparison of units of measurement for cnc programming

Plane selection – G17/G18/G19

Selecting the plane you will be working with is necessary. Not because you will often switch between planes, but because it’s possible.

Most people will never use anything other than the standard XY plane with G17, but setting it will make sure that it is set correctly.

The alternatives to G17 are G18 for the ZX plane and G19 for the YZ plane.

Canned cycle cancel – G80

G80 is the g code used to cancel any active canned cycle.

Canned cycles are used to perform repetitive machining. This includes drilling, reaming, boring, counterboring and other operations.

Canned cycles are modal which means they are on until they are switched or turned off. In the case of a drilling canned cycle, once it is turned on every new location the machine reads will be a spot where it drills a hole.

Obviously, you need to stop drilling holes eventually. Using G80 cancels the drilling canned cycle or another other canned cycles that might be active.

Cutter compensation cancel – G40

Cutter compensation is when the CNC machine control changes how it reads the program. With cutter compensation on, the machine will shift a set distance based on the size of the cutting tool when running the program.

illustration that shows how a CNC will act when using cutter compensation left with the G41 code

Cutter compensation is turned on with either G41 or G42. G41 shifts the tool left and G42 shifts it right.

illustration that shows how a CNC will act when using cutter compensation right with the G42 code

The G40 code turns cutter compensation off.

illustration that shows how a CNC will act when there is no cutter compensation mode active

Tool length compensation cancel – G49

an illustration of a cnc machine that shows how a g43 code offsets the program

Cutter compensation is accounts for the diameter of the cutting tool.

Tool length compensation accounts for the length of the cutter from the CNC spindle.

G49 is the code used to cancel tool length compensation.

Both compensation modes adjust for the size of your cutter. This allows you to run the same program with different tools.

Other safety codes

Codes will vary by machine. Check your instruction manual for the specific codes you need to use in the safety lines.

The codes listed here are certainly a good start.

Safety lines for starting up your CNC

Setting the initial modes for your machine is an important part of every CNC program. If the modes are not set then the machine will stay in it’s initialized state.

Modes such as the unit system (mm/inch) can be set in the machine parameters. If no code is specifically given in the program then the machine will remain in the initialized state.

This is not a good programming practice because there is plenty of opportunity for errors to occur. Use safety lines to make absolutely sure your CNC is in the correct mode.

Here is an example of a safety line to use at the beginning of a program:

O1000

(Start of safety code)

G20 G17 G40 (G20 inch, XY plane, cancel cutter compensation)

G49 G64 G80 (cancel tool length compensation, normal cutting mode, cancel canned cycles)

G90 G94 G98 (absolute mode, feed per minute, initial plane for canned cycles)

(end of safety code)

Frequently asked questions about CNC safety lines

Can you put all of your safety codes on the same line?

The number of codes that can fit in the same line depends on the CNC machine.

Many machines have limitations for how many M-codes you can put on one line. G codes are generally only limited to one code from each group.

For example, G00, G01, G02 and G03 are all in the same group (movement). Only one of the codes from this group should be used on any particular line.

Want to learn more about CNC G Code?

Quick Guide to the T CNC Code [Tool Selection]

a graphic of a cnc machine with text that says learn g code today t tool selection

What does the T CNC code do?

On most CNC machines, the T code tells the machine the tool to place in the tool changer to prepare it for a tool change.

The M06 command will then perform the tool change.

On some CNC machines, the T code will actually switch to the tool called out.

The T command is a very important CNC code because most programs will use multiple tools during the execution of a program. It is not uncommon for dozens of tool changes to be performed in the process of running a more complex program.

Want to learn more about CNC G Code?

When does the T code get used?

The T code is used at the start of a program to make sure the correct tool is loaded before any machining is performed.

After this initial setup, the T code is used every time the machine switches to a new tool.

If tool #1 is currently in the CNC spindle, calling tool #2 with the T02 command will ready it in the tool changer. Using the M06 command will swap tools.

Readying the tool before the switch saves precious machining time, something that is more important for high volume production machining.

Even though the tool is already loaded in the tool changer, it is advised to still call the T02 command in this instance to make sure that the correct tool is loaded.

The code would look like this:

T02

<machining code here>

T02 M06

Again, this format is used to ensure that the correct tool is placed in the CNC spindle during the tool change.

Without using the T02 command right before the M06 tool change command, it is possible that another is loaded in the tool change position and will be swapped in.

Imagine if you needed to re-run a portion of the code and started your program after the initial T02 code. If you didn’t repeat the T02 code right before the tool change then the machine would use the last tool number from its memory.

There is a good chance that it isn’t swapping the correct tool which can mean a machine crash.

How to change tools

CNC cutting tools are changed using the M06 command. On some machines (usually older CNCs), the T code will cause the machine to perform a tool change.

Check your machine manual to know how your machine will react.

If your machine is equipped with an automatic tool changer, then it is likely that you will be using the M06 command to change tools.

an automatic tool changer on a dmg mori cnc machine

How is the T code used differently on mills vs lathes

As stated above, most CNC milling programs need the use of more than one tool to complete the machining of a workpiece.

Therefore, the usage of T code for tool changes is essential.

On lathes, the T change is less common because the same cutter can perform many turning operations.

However, operations such as parting-off, threading, and drilling require specific tools. The number of tools allowed on a CNC lathe depends on the number of cutters that fit in the machine’s turret.

Where should you document your tools?

Information about your tools should be stored in two locations, on your machine setup sheet and in your tool offset library.

The setup sheet is used to communicate to the machine operator what tools are expected to be loaded in the machine while running the program.

The tool offset library, sometimes called the tool offset table stores information related to the size of your cutting tools. This includes both the diameter (D offset) and tool length or height (H offset).

The D offset and H offset values allow the machine to compensate for the size of the cutting tool and accurately machine the part.

Frequently asked questions about the T code

What does T0X.0X mean?

You may see some codes that have two numbers separated by a dot along the T code (e.g. T01.01).

This formatting exists because some controllers such as Fanuc allow different offsets to be assigned to the same tool.

Depending on the type of operation performed by the tool, you may need to change its offset values. T01.01 is tool #1, offset 1. T01.02 would be tool #1, offset 2.

Want to learn more about CNC G Code?

Quick Guide to the M06 CNC Code [Tool Change]

a graphic of a cnc machine with text that says learn g code today m06 tool change

What does a M06 code do?

The M06 code tells the CNC to perform a tool change.

The machine will swap the tool that is in the ready position of the automatic tool changer into the spindle.

Want to learn more about CNC G Code?

Preparing the CNC for a tool change

You should be aware of some of the characteristics of your cutting tool. The size, as in diameter and length need to be taken into account.

A cutter with a very large diameter may need to be placed near empty spots in your tool changer so it doesn’t smash into other tools.

Length isn’t usually as big of an issue but still keep it in mind to make sure you have enough clearance with the machine and with your part.

Another big thing to consider is the weight of the cutter. Check your machine manual because the capabilities of various machines differ. Just remember that the total weight of everything you are putting in the spindle or automatic tool changer is what counts, not just the cutter.

an automatic tool changer on a dmg mori cnc machine

Executing a tool change

Certain conditions need to be met for a safe tool change.

Machine movement needs to be stopped and the machine should be in the tool change position. Often this position is the same as the home position.

The spindle should be stopped and the tool to be swapped in should be in the ready position.

Performing a tool change without an automatic tool changer

If your machine doesn’t have an automatic tool changer, then the operator (probably you) will need to change the tools manually.

The best way to do this is to put a program stop in your program using the M00 code. You should include comments in your program at the program stop to tell the operator what they are expected to do.

What other CNC codes are used with the M06 command?

The main code used with the M06 command is the T code. The T code selects the tool that will be swapped in.

The line of code performing the tool change will usually be something like:

T02 M06

In this example tool #2 is readied for the tool change and then the M06 tells the CNC to swap the tool into the spindle.

M6 vs M06

Some people get confused about whether the 0 is required to include with an M06 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 M06 code used in textbooks or other reference materials. In practice though, many prefer the shortened M6 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.

Frequently asked questions about the M06 code

Do you use the M06 code if you want to switch to an empty spindle?

Yes, just call up a tool holder location without a tool in it. When the M06 command is used the machine will swap in the empty spot. Leaving no tool in the spindle.

Do you need to use the M06 command if you don’t have an automatic tool changer?

No, if you don’t have an automatic tool changer, the M06 code isn’t needed. Without an automatic tool changer all tool changes will need to be done manually.

Want to learn more about CNC G Code?

Quick Guide to the G99 CNC Code [Return to R Plane]

a graphic of a cnc machine with text that says learn g code today g99 canned cycle return to r plane

What does the G99 code do?

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

G99 is a very important code because it allows you to shorten the time needed to move your cutter around when machining.

The alternative to G99 is G98. G98 also controls the movement of the machine after finishing a canned cycle.

Want to learn more about CNC G Code?

G99 vs G98

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.

The G98 code 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.

G99 travels back to the R plane instead. The R plane is closer to the part which can potentially cause problems if there are obstacles close to the part such as fixtures or clamps.

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

Parameters used with a G99 code

When using the G99 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.

G99 code format

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

G81 X0 Y0 R0 Z1 F5 G99

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 G99

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

Using G99 will move your cutter to the R plane specified with the R code. The R plane will usually be set close to the top of the part to make the moves shorter which takes less time. This is great for reducing cycle time but not great for avoiding obstacles.

Common obstacles in the machine are:

  • The workpiece
  • Clamps
  • Fixtures
  • Other tooling

Reducing the cycle time is great for industrial CNC machines, but for hobbyists this isn’t as much of a concern. Unless you are trying to maximize the output of your machine, G98 is a safer option.

G99 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 G99 code

Is G99 modal?

Yes, G99 is a modal command. This means it will stay on until canceled. It will only be in effect for running canned cycles though. G99 has no effect on straight line movement with either G00/G01 or circular movement with G02/G03.

What does the G99 code do on a lathe?

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

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

This means if you use a F5 command and G99 is active, the feed rate will be set to 5 inches per revolution.

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

Want to learn more about CNC G Code?

Quick Guide to the R CNC Code [Multi Use Code]

a graphic of a cnc machine with text that says learn g code today r radius size and retract plane

What does the R CNC code do?

There are two main functions for the R code when CNC programming.

When combined with the G02 or G03 circular interpolation commands, the R code specifies the size of the radius to be machined.

When combined with canned cycles such as G73 through G89, the R code specifies the location of the R plane or clearance height to be used.

Want to learn more about CNC G Code?

Radius size with G02 or G03

There are two types of circular movement (interpolation) that can be used when CNC machining.

They are G02 for clockwise movement and G03 for counterclockwise movement.

a comparison of the type of movement created with G00, G01, G02 and G03 cnc g codes

The format for using both codes is:

G02 (or G03) X10 Y15 R5 F30

The X and Y locations are the end point of the circular movement. The R value is the radius size of the circle and F is the feedrate.

Circular movement can also be performed using IJK codes instead of XY locations and an R value.

Both methods are common, so be on the lookout for either type.

R plane with canned cycles

The R plane is a specific height that the CNC will reference when performing a canned cycle.

First it is the height that the machine will rapid travel to and begin the machining part of the canned cycle.

It is also the height that the machine will return to if the G99 [return to R plane] command is active.

If the G99 [return to initial plane] command is active then the machine will return to the start of the canned cycle instead.

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

The G98 and G99 codes are used to switch between the two types of clearance modes available when running canned cycles.

G98 moves the cutter further up and away because in most instances the canned cycle is started at a higher Z height location further away from the part. This increases the time that it takes the machine to run the program.

The G99 command is used to keep the machine closer to the part being machined. It should only be used when you are sure that there are no obstacles in the way such as the part itself, clamps or fixtures.

Format for using the R code with canned cycles

G81 X0 Y0 R5 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.

Want to learn more about CNC G Code?

Quick Guide to the Q CNC Code [Peck Depth]

a graphic of a cnc machine with text that says learn g code today q peck depth

What does the Q CNC code do?

The Q code is used to specify the depth of each peck when peck drilling with either the G73 or G83 code.

The “peck” is how much farther down the machine will drill on each pass.

When peck drilling, the machine drills down, backs up, drills further down, backs up, drills even further down and repeats until the cycle has been completed.

Want to learn more about CNC G Code?

Difference between peck and standard drilling

illustration that shows the difference between peck drilling and standard drilling in a CNC machine

The main difference between peck and standard drilling is that the peck drilling process removes the material in multiple steps, while standard drilling is a one-step process.

Both commands are intended to make holes, but the peck drilling cycle allows more control over how the hole is drilled.

Peck drilling is the first option for CNC programmers when making blind holes. The pecking process helps break chips as well as remove them and any other debris from the hole during the drilling process.

Trouble removing chips from the hole when drilling can cause size and/or surface finish issues.

Standard drilling is far more common when dealing with simple through (thru) holes.

Types of peck drilling

There are two peck drilling cycles, G73 and G83.

They are both canned cycles with one key difference. Using the G83 code will retract completely out of the hole after each peck to the retract plane. Using the G73 code will only retract to the start of each peck.

an illustration that shows the difference between the G73 and G83 CNC codes

The G73 canned cycle is a peck drilling cycle but with a shorter retract intended for relatively shallow holes. Meanwhile, the G83 command is peck drilling with a full retract intended for deep holes.

Both commands are meant to help break and clear chips. G83 does a better job of this by fully retracting out of the hole but with the added expense of a longer cycle time.

On the other hand, G73 is designed to break up stringy chips, while G83 is intended to pull chips up and out of deep holes.

Other codes used with the Q code

The Q code is used in peck drilling canned cycles G73 and G83. You can also expect to find the following codes used in those canned cycles:

Format for using the Q code

The format for using a Q code is shown below:

G98 G83 R1.0 Z-5.0 Q1.0 F25.0

This example shows a peck depth (Q) of 1.0.

This means that the machine will drill the hole in 1.0 unit steps. This would be 1 inch or 1mm depending on which unit mode you currently have active.

Want to learn more about CNC G Code?

Quick Guide to the P CNC Code [Multi Use Code]

a graphic of a cnc machine with text that says learn g code today p subprogram number, fixture offset & dwell time

What does the P CNC code do?

The P code is used for multiple uses in CNC programming.

Those uses depend on which other codes the P code is combined with.

The four uses of the P code are selecting a subprogram, setting a dwell time, selecting an offset number, and setting a scale factor.

Want to learn more about CNC G Code?

Subprogram number when choosing a subprogram with M97 or M98

Subprograms are a separate CNC program selected to run from within another program.

They are used to perform repetitive machining operations or sequences such as drilling, counterboring and countersinking a hole.

CNC machines run the lines of code in a program in order. Using subprograms allows the programmer to jump around to different sections of the current program or to run a different program and come back to the current program.

When used with either the M97 code or the M98 code, the P code tells the machine where to go run the subprogram. This will either be a specific line in the current program (M97) or an entirely different program (M98).

The P code when using M97 [subprogram call by line]

illustration that shows the flow of a cnc program when using the m97 command to call a subprogram

M97 P1234 L5

This line of code will tell the machine to move to line N1234 of the current program. The L code tells the CNC machine to run the subprogram five times. The L code can be left out if the subprogram will only be run once.

Line 1234 will be after the program end command (M30). Once the machine reaches the M99 command it will return to the line after the example shown above.

The P code when using M98 [subprogram call by program number]

M98 Code Flow

M98 P5678 L2

This line of code will tell the machine to go run program number 5678 two times. The L code tells the CNC machine to run the subprogram twice. The L code can be left out if the subprogram will only be run once.

Program 5678 will perform any necessary machining functions and then end with an M99 command instead of M30. The M99 command will make the machine return to the line after the example shown above.

On the other hand, both commands (M98 and M97) use parameters K (or L) as the number of repetitions of a given subprogram. The use of the letter K or L depends on the CNC model. Always check the machine’s manual for further details.

Dwell time with G04

A G04 code makes the cutting tool stop moving for specified amount of time. Following that amount of time, the machine will proceed to the next line of code.

There are some variations between machines when using G04.

Not all machines will use the P code. Some CNCs use either F, U or X instead of P.

Also, some machines will read the value after the P code as seconds and some will read it as milliseconds.

1 second = 1,000 milliseconds.

So P300 could mean 300 seconds (5 minutes) or 0.3 seconds depending on how your CNC reads the code. Makes sure to verify how you machine will read the P code when using the G04 command.

Dwell time with G82 and G89

G82 [drill cycle with dwell] and G89 [boring cycle with dwell] are both canned cycles with dwells.

G82 and G89 both use the P code to specify how long to stop and wait at the bottom of the hole. Usually this time is in milliseconds. Machines vary though so make sure your machine isn’t reading the P code as full seconds.

Fixture offset number with G10

Using the P code with G10 tells the machine which fixture offset to change.

Below is a list of the values used with the P code and which fixture offset they correspond to:

Code

Fixture Offset

G10 P1

G54

G10 P2

G55

G10 P3

G56

G10 P4

G57

G10 P5

G58

G10 P6

G59

Scale factor with G51

CNC programs can be scaled up or down using the G51 command.

The P code is used to set the scaling factor when used with G51.

This means that a P2 code will tell the machine to make everything in the program 2x larger.

On the opposite end, a P0.5 code will tell the machine to make everything half the normal size.

Conclusion

The P code can be used in many different ways when CNC programming.

Using the P code to select a subprogram is pretty much universal across the different CNC machine manufacturers.

The other uses of the P code are less standard. At times the CNC will read the code different such as seconds vs. milliseconds or it will require a different code altogether such as in the case of dwell times with G04.

Make sure you check your individual machine to understand the requirements of your individual CNC.

Want to learn more about CNC G Code?