Beginners Guide to Rapid Traverse for CNCs

Key Points

  • Rapid traverse is full speed movement
  • Rapid travel and rapid traverse are the same thing
  • The G code for rapid traverse is G00 on CNC mills and lathes
  • The rapid speed can be adjusted using the rapid override

What is rapid traverse?

Rapid traverse, sometimes referred to as rapid transverse or rapid travel, is used for moving a machine tool around the workpiece as fast as possible. 

Depending on the type of machine tool, this is accomplished in different ways. See below for more information related to CNC and manual machines.

How fast does the machine move in rapid traverse?

industrial cnc machine
Industrial grade CNC mill

First let’s talk about speed.

Rapid traverse speeds vary based on the machine.  A good quality desktop CNC will usually be capable of speeds around 100 inches per minute (IPM).

Larger, industrial grade CNC can often move at speeds of 1,000 inches per minute or more. 

No matter what type of CNC you are using, you will want to make sure that nothing is in the way when these moves are being made in a CNC machine. 

Crashing a CNC at normal speeds is bad enough, crashing a CNC at rapid speeds could be catastrophic.

Can rapid traverse speed be adjusted?

cnc control board with rapid travel dial identified with arrow
Rapid Override Dial

Most CNC machine controls have an adjustment to dial back the rapid travel speed. This is often referred to as Rapid Override or something similar. This override allows the CNC operator to adjust the rapid speed, usually in the form of a percentage of the full speed.

Some shops need to run full speed. Time is money after all, but many machine shops will dial things back a little for safety.

How does the CNC move during rapid travel?

straight line movement example

Newer CNCs will move in a true straight line fashion, however some older CNCs can process the command in different ways.

Some machines may only move one axis at a time while others will move in other strange ways. The most important thing is to be aware how your specific CNC control will process the rapid travel command and create your program to account for this movement.

Because various machines will process commands in different ways, this means you may not be able to take a program and a setup and run it on a different machine.

What is the G code for rapid traverse?

rapid traverse code example

The G code for rapid movement is G00. 

This applies to both CNC mills and lathes. 

In the example above, G00 is the code for rapid traverse and the X and Y values are the position that the machine is to rapidly move to.

Rapid movement can happen in the Z axis as well.

What should you think about when using rapid travel?

When you are zipping your CNC back and forth think about:

  • Part location – it can be easy to forget about a step in your part and attempt to move over the top of you part at a Z height that is too low
  • Fixturing – similar to your part location, remember that you often have clamps, vises, etc. that will be in your machine and it’s best to avoid them
  • Removing material – don’t cut in rapid mode, it will result in size issues and poor surface finishes at best

Rapid traverse in manual machining

bridgeport milling machine with rapid power feed pointed out
Power feed marked by red arrow

Many manual machines, such as a Bridgeport mill, use a power feed to rapidly move around the workpiece. 

These power feeds are not as fast as a CNCs rapid moves but they are still much quicker than the standard speed which usually involves cranking a handle to position the machine.

Guide to CNC M Codes [List and Quick Reference]

What are M codes used for?

In CNC machining, M codes are used to control machine and miscellaneous functions.

This includes turning off and on features such as the machine spindle as well as coolant functions. They also control how the CNC reads and flows through the program.

M codes are the second most common codes used in CNC programming. 

We’ve laid out what each M code does, but remember that some CNC makers switch things around a little bit.

You can bet that the most common codes such as the ones for starting and stopping your spindle, coolant and program will be the same but some of the others might vary.

For anyone new, be sure to check out our post on the first M codes to learn to make sure you start with the important stuff.

List of M Codes

When the machine gets to this code it will stop everything, including the spindle and coolant until the operator tells the machine to continue on.

Learn more about the M00 code

The machine will check the control panel and if the optional stop switch is on, the machine will stop just like with M00.

Programs often have optional stops placed at the break of sections in the program such as the start of a hole drilling sequence.

Learn more about the M01 code

A leftover from the NC days. Ends the program without rewinding to the start again. 

In many machines now, M02 is no different than M30. How it gets treated depends on the specific CNC control model.

Learn more about the M02 code

Turns the spindle on in the clockwise direction. This is the spindle direction used by most cutting tools.

Learn more about the M03 code

Turns the spindle on in the counterclockwise direction. 

Learn more about the M04 code

Turns on a coolant mist. Some machines treat it as coolant source 1 on.

Learn more about the M07 code

Turns the coolant on to soak the workpiece. Some machines treat it as coolant source 2 on.

Learn more about the M08 code

Turns off all coolant sources.

Learn more about the M09 code

M19 CNC M Code

M19 - Orient Spindle

Gets the tool ready for tool change. Aligns the keyways. 

The M06 code will do this as well but calling it ahead of time can make the tool change process faster.

Stops everything including the spindle, movement, coolant and will go back to the beginning of the program.

Learn more about the M30 code

Frequently Asked Questions

What are M codes used for in a CNC program?

M codes are used for turning miscellaneous functions on and off such as the spindle and coolant.

What is the difference between G and M codes?

M codes turn things on and off while G codes switch modes in the machine such as working in inches or mm.

G codes also prepare the machine for functions such as canned cycles for drilling or boring holes.

What other types of CNC codes are used in CNC programming?

There are many other CNC codes that get used such as:

  • Location based codes such as A, B, C, I, J, K, X, Y & Z
  • Machine related codes such as F, R & S
  • Offset related codes such as D, H & T
  • Program related codes such as G, N, O, P & Q 

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 Compensation Modes

a graphic of a cnc machine with text that says learn g code today compensation modes

Types of compensation

CNC machines have three main types of compensation:

  • Cutter compensation/tool diameter compensation
  • Tool length compensation
  • Work/fixture offsets

These compensation modes allow the machine to accommodate for things such as the location of a part in the machine or the size of a cutting tool.

Compensation allows the machine to adjust how it reads the CNC G code so that the same program can be used in multiple ways.

Using compensation modes allows the CNC to run the same program and get the same results even if the factors we mentioned above (cutting tool, workpiece location) are changed between runs.

The machine will have no problem adjusting for a new cutter as long as we tell the machine the diameter and length of the new cutting tool.

The values that tell the machine how long the tool is or what its diameter is are called offsets.

There are multiple compensation codes and offset codes.

Luckily, the list isn’t long. Let’s go through them one by one.

Want to learn more about CNC G Code?

Cutter compensation/tool diameter compensation

The first type of compensation is compensation that accounts for the size or diameter of the cutting tool. This is often referred to as simply cutter compensation.

There are two types of cutter compensation.

Before we talk about what cutter compensation does when it is on, let’s talk about how to turn it off.

G40 - Cutter compensation cancel

The two cutter compensation modes are both modal commands

This means that they stay on and in effect until they are changed or cancelled.

Selecting G41 or G42 switches between the two modes. If you want to turn off cutter compensation you will need to use the cancel command.

G40 is the off button for cutter compensation

Calling it in your program will cancel any active cutter compensation.  

Because modal commands stay on until changed or turned off, you often see cancel commands used in safety blocks of code found at the beginning of the program or a new section of the code such as when changing tools.

The illustration below shows how the CNC will move when cutter compensation is off.

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

G41 - Cutter compensation left

G41 is the most common cutter compensation. It is used when climb milling.

The G41 code tells the CNC to shift the cutter to the left of the cutting path to account for the size of the cutter.

See the pic below for help understanding what that means in practice.

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

G42 - Cutter compensation right

G42 is used when conventional milling.

The G42 code tells the CNC to shift the cutter to the right of the cutting path to account for the size of the cutter.

G42 is not used nearly as often as the G41 code. 

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

D offsets

illustration of a cnc cutting tool that shows what an D offset is

Diameter (D) offsets are the location where the size (diameter) of the tool is stored in the CNC control.

D01 will be the offset where the size information is stored for tool #01. D02 will be for tool #02 and so on.

D offsets are set with the D code.

Tool length compensation

G43 is the command to turn on tool length compensation. 

Just like G40-G42, G43 is modal which means it will stay on until changed or canceled.

G43 is for positive tool length compensation. You should be aware there is also a negative tool length compensation mode (G44) but it is rarely used and not something that beginners should be worried about.

G43 is used frequently and you can expect to see it used in 99.9% of the CNC programs you will come across.

Just like G40 cancels cutter compensation based on the diameter of the tool, G49 does the same for tool length compensation.

Like many other cancel commands, G49 can be found at the beginning or ending of different sections of code to ensure the machine is in the correct mode as tools are changed and different operations are performed.

H offsets

illustration of a cnc cutting tool that shows what an H offset is

Height (H) offsets are the location where the length of the tool is stored in the CNC control.

This value is the difference in location between the end of the spindle and the end of the cutting tool.

H01 will be the offset where the length of tool #01 is stored. H05 will be for tool #05 and so on.

Height offsets are set with the H code.

Fixture/work offsets

Work offsets are used to tell the machine where it should reference all program values from.

For example, imagine if you wanted to machine four separate parts to be all the same. You could load all four parts into your CNC machine and set a work offset location for each separate part.

Once the work offsets are stored, you could call out the first work offset and then run your program.

Next you could call out the next work offset and run the same program again. This would run the same program in a new location resulting in two of the same part. And rinse and repeat as much as needed.

visual to show cnc work offsets G54-G59 with the zero locations shown

G54 through G59 are the standard work offsets that you can expect to find on just about any CNC machine.

Work offsets identify an X, Y & Z coordinate zero location. Work offsets go by many other names such as program zero, part zero, zero location, etc.

Some machines may be capable of storing many more work offset locations, but it is best to concentrate on the most common codes first. Check your individual machine documentation to learn how to program with more work offsets.

If you are very new to CNC programming with G code then be on the lookout for a G54 code. 

This is the first work offset and as a result is the most common one used. Often shops will only have a need for this single work offset. As shops and machine become more advanced you can expect to see more usage of additional work offsets.

Just like the other offset modes we have talked about; work offsets are also modal commands.

Expect to find them in the safety blocks of code and because they are important enough to be included in the safety block section, you should be very careful about making sure you have identified the correct work offset at all times in the program.

Want to learn more about CNC G Code?

Quick Guide to CNC Subprograms [Tips & Tricks]

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

What is a subprogram in CNC programming?

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

Subprograms can be run (called up) from the main CNC program or from within another subprogram.

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.

Want to learn more about CNC G Code?

What is the difference between a subprogram and the main program?

The commands to end the main program and a subprogram are different.

The main CNC program ends with either M30 (most machines) or M02 (older machines) code. 

No further code will be run after either of these codes.

A subprogram ends with the M99 command

The M99 code returns the machine to the program which called the subprogram. The machine will continue to run code in this program.

How to call a subprogram

There are two ways to run subprograms: M97 and M98.

The difference between M97 and M98 is the program location they move to.

M97 will jump to a new line in the current program.

M98 will run an entirely different program.

Format for using M97

The format for using an M97 code is:

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.

Format for using M98

The format for using an M98 code is:

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.

Subprogram example

Main program

O1234

G21                             (metric mode)

G17 G40 G80           (select XY plane, cancel cutter compensation and canned cycles)

G91 G28 Z0              (home z axis)

M03 S1200               (turn spindle on)

G90 G54 G43 H1     (incremental mode, select work offset, turn on tool length compensation)

G00 X5.0 Y5.0          (rapid to hole #1 location)

Z2.0                            (position tool above part)

M98 P5555               (run subprogram)

G28 Z0                       (home z axis)

M30                            (end program)

Subprogram

O5555

G91                             (set incremental movement mode)

G81 Z-10.0 F200     (drill hole #1)

X5.0                            (drill hole #2)

Y6.0                            (drill hole #3)

X-5.0                           (drill hole #4)

G00 Z20.0                 (rapid to safe location above part)

M99                            (return to main program)

In the example above, the machine will create a pattern of four holes. This pattern could be easily repeated by moving to the start of the pattern in a new location and running the subprogram again.

To do this the location of the repeated pattern would be listed after the subprogram call in the main program and the subprogram call of M98 P5555 would be listed again. The machine would then make the same pattern of holes in the new location.

What are subprograms used for?

Subprograms are used for repeating tasks. 

This can be machining of a part or controlling the machine itself.

Part related subprograms

Most of these subprograms include canned cycles in their lines of code to perform repetitive machining operations such as drilling, pecking, tapping, threading, bearing, and boring.  

They also help to run the same program in different parts of the workpiece, even if they don’t include canned cycles.

This can include rotating or changing the tool, contouring or finishing.

Machine related subprograms

Subprograms can also be used to control the machine.

Changing a tool in the CNC might consist of turning the coolant off, turning the spindle off and moving it to a safe location, setting or canceling a variety of modes, and finally switching the tool.

A subprogram can be created to automate the tasks and make sure it is executed the same way each time. 

This makes the operation less prone to errors or crashes.

This benefit only gets better as the amount of operations performed gets longer.

Benefits of using a subprogram

The greatest benefit of using subprograms is reducing the lines of code which makes the program easier to read and edit.

Subprograms can also reduce the number of errors in the program. Less lines of code means less possible sources of problems.

Drawbacks of using a subprogram

Subprograms are meant to make the program easier to work with for both the programmer and anyone using it. If not done correctly, they can have the opposite effect.

Programmers should remember that part of their job is making sure that the program is easy to use for the operator.

It can also be easy to have the wrong modal commands or offsets chosen when starting or ending a subprogram. Following a good program format that uses safety lines or blocks of code can protect from this happening.

If it is important that a mode or offset is needed in a specific section of your program, it is best to use the necessary code to make sure things are set correctly. Assuming your machine is in the correct mode already is dangerous.

Making subprograms inside your subprograms (nesting) also has the potential to cause confusion. Repeatedly switching between programs can be confusing for both programmers and operators.

For a more in-depth description of subprogram nesting, see additional info on the topic further down in this post.

Differences between subprograms and canned cycles

Subprograms are small blocks of code used to perform repeatable machining operations or functions.

Canned cycles are commands that give the machine instructions for a pattern of movements used to simplify code.

Canned cycles are used for operations that the majority of CNC users will need such as drilling or counterboring a hole. Subprograms can be made custom to the needs of the individual machine user.

In a way, canned cycles are like mini subprograms that can be used easily in your program without needing to create a separate subprogram.

There are often times where canned cycles are used together with subprograms to increase the efficiency of the program even further.

How do modal commands work in subprograms?

Modal commands work the same way as they do in the main program. This means they stay on until changed or turned off.

If a modal command is on when starting the subprogram, it will stay on while running the subprogram. The same is true when switching from the subprogram to the main program.

The safest thing to do is make sure your safety blocks cover the required codes for each section of code.

What is nesting in CNC programming?

So far we have concentrated on running a subprogram from our main program, but did you know you can also run a subprogram from within a subprogram?

This is called nesting.

Nesting can be a powerful tool but can quickly get out of control. 

Most CNC controllers will allow up to four level deep nesting.

This means calling a subprogram in a subprogram in a subprogram in a subprogram in your main program.

Confusing right? That is why in most cases it isn’t a good idea to nest that deep. For most applications, one level deep is enough.

Even two level nesting can be hard to follow. Three and four levels are definitely not advised if you are reading this post.

The bulleted list below shows how subprogram structure works.

bullet point list used to show nesting structure of CNC programs

Tips for numbering your subprograms

Create a system for numbering your programs and subprograms to avoid confusion.

Some choose to set aside blocks of numbers for each type of program. For example, O0001-O4999 for main programs and O5000-O9999 for subprograms.

Others make their subprograms closely follow their main program numbers. If the main program is O1000 then the subprograms will be O1001, O1002 and so on.

Want to learn more about CNC G Code?

First M Codes to Learn [Where to Start for Beginners]

a graphic of a cnc machine with text that says learn g code today first m codes to learn

What is an M code in CNC programming?

M codes are miscellaneous codes. They control various functions of the CNC machine such as turning coolant flow or the spindle on and off.

M codes are the second largest group of codes after G codes.

M codes vary from machine to machine, but we have covered the most common ones below with links for more info on each code.

You can expect that these codes will work the same on most machines:

Want to learn more about CNC G Code?

Common M codes

Stops [M00, M01]

The M00 code is called a program stop.

It stops the spindle and coolant flow. 

The M00 program stop also stops all machine movement and pauses reading the program.

It is typically used when changing the tool manually or there is a need or adding tapping oil to a tap before it touches the workpiece.

The machine will continue reading the program after a program stop once the cycle start button is pushed. It doesn’t automatically restart the spindle or coolant though. Those must be turned back on in the program.

The M01 code is an optional stop. It stops everything that the M00 code does but only if the optional stop button or switch is on.

haas cnc control panel with optional stop button highlighted
Optional stop button on a Haas CNC

If the optional stop switch is off, the machine will ignore the optional stop code and keep running the program.

Program end codes [M02, M30]

While the M00 and M01 codes pause the program, the M02 and M30 codes end it.

M30 is the most common program end code. It ends the program and rewinds the program back to the start.

This means that if you press cycle start after the M30 code, the machine will run the program again.

fanuc cnc control panel with cycle start button highlighted
Cycle start button on a Fanuc control

M02 is a program end without rewind.

This is mostly a legacy feature from when programs were run on tape. In fact, many newer machines will treat a M02 code as if it were an M30 code.

Spindle commands [M03, M04, M05]

Spindle direction

M03 turns the spindle on in a clockwise direction.

M04 turns the spindle on in a counterclockwise direction.

M05 turns the spindle off. The spindle should be turned off first before changing the spindle direction.

Coolant commands [M07, M08, M09, M88, M89]

M08 turns flood coolant on. 

This floods the cutting area with coolant to keep heat from building up which can damage the part or the cutter.

It also helps remove chips from the cutting area which can cause issues as well.

The M09 code turns the coolant off.

Many machines will have other coolant options that can be turned on as well. M07 to turn on mist coolant is a common one and so are M88 to turn thru spindle coolant on and M89 to turn it off.

Tool change [M06]

Most machining centers (mills) have automatic tool changers.

Tools get loaded into the ready to change position with the T code.

When the M06 code is used, the machine swaps the tool currently in the spindle with the tool in the ready position.

an automatic tool changer on a dmg mori cnc machine
An automatic tool changer on a DMG Mori CNC

Subprogram codes [M97, M98, M99]

There are two ways to run subprograms: M97 and M98.

The difference between M97 and M98 is the program location they move to.

The M97 code will jump to a new line in the current program.

The M98 code will run an entirely different program.

The format for using both codes is the same. They both use the P code and the L code.

M97 P1234 L3

For a M97 code, the P number is the line number of the subprogram inside the current program.

For a M98 code, the P number is the program number for the subprogram that will be run.

The L code is the number of times that the subprogram will be repeated.

The M99 code ends both types of subprograms and jumps to the next program line after the M97 or M98 code was used. 

Subprograms are not ended with an M30 code like a normal program is.

M codes vs G codes

M codes control different machine function such as the spindle or coolant.

G codes are another type of code used in CNC programming and they are called preparatory functions. This means they prepare the machine to do something.

Usually this involves moving the machine or controlling how it moves. 

Codes such as G00 [rapid travel] or G81 [drilling canned cycle] make the machine move in a certain way. Codes such as G90 [absolute mode] or G21 [metric mode] control how the machine reads the movement.

Both G and M codes are heavily used in CNC programming. It is important to understand both types of codes. 

For this reason we have a post on the First G Codes to Learn as well. Check it out because understanding the codes in that post and this one will give you a good foundation for understanding CNC programming.

Want to learn more about CNC G Code?

First CNC G Codes to Learn [Where to Start for Beginners]

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

What is a G code?

G code is the programming language used by CNC machines of all types.

This includes everything from mills and lathes to 3D printers and laser engravers.

G code consists of commands made up of letters and numbers that tell the CNC machine what to do. Most letters in the alphabet are used as codes to make the machine do something.

This can be a little confusing because while G code refers to the programming language used by CNC machines, there is also a large group of codes that are frequently used which start with the letter G. This group of codes is often referred to as simply “G codes”.

This post will cover the most common group of codes that start with the letter G, but we also have resources to help with the other letter codes if you need it.

What types of codes are used in CNC programming?

M CNC Code

The two largest groups of codes are G codes and M codes.

G codes are preparatory functions. 

These codes prepare the machine to perform an action by setting various machine modes such as working in inches vs millimeters.

There are dozens of G codes which are used, and they vary somewhat from machine to machine.

The most common G codes are listed below. 

For the most part, the commonly used G codes are consistent across the different machine makes but check your machine manual to be sure.

M codes are miscellaneous functions. 

These are easier to remember as “machine functions” because this group of codes controls different parts of the CNC machine such as turning the spindle or coolant on and off.

The rest of the CNC codes consist of the remaining letters A through Z.

G and M codes are the only ones to worry about that have multiple codes within the same letter. In other words, there is a G01 and a G02 code. This isn’t true for other codes such as F, S, X, Y or Z.

Working with G Codes

G codes set various machine modes including turning them on and off.

Only one G code can be active at a time from each group. 

If you use the G20 code to turn on inch mode then the machine will basically turn off metric (mm) mode. You can’t have both codes active at the same time. 

These are called modal commands.

Some modal commands can be canceled (turned off) without setting another mode. For example, cutter compensation can be set to adjust left with G41 or right with G42. It can also be turned off (canceled) with G40 so there is no cutter compensation.

Inch/metric mode on the other hand can not be turned off. One of the two codes must be active at all times. There is no G code for turning the units the machine is working with off.

The most common G code groups are listed below:

Common G Codes

Movement G Codes

Movement codes are some of the most often used G codes in CNC programming. They are used to move the cutting tool around the machine.

The G codes for movement are:

G00 is used for quickly moving the machine around when not cutting. The machine will move at the max allowed speed. This helps reduce the time it takes to run a program.

G01 through G03 are for cutting movements. They will move at the most recently listed feedrate specified with the F code.

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

Unit Modes

There are two unit modes that can be used when CNC machining.

G20 is used for working with imperial (inch) units and G21 is used for working with metric (mm) units.

You want to pay attention to your unit mode because 1 inch is 25.4 times bigger than 1mm so being in the wrong unit mode could be disastrous!

Positioning Modes

There are two types of positioning that can be used by the CNC.

Absolute positioning with G90 treats every new location that the machine reads as a location relative to a fixed point in the machine.

Incremental positioning using G91 reads every new location as a distance from its current location. Every time the machine moves to a new location in incremental mode, the new location becomes the new zero location.

The main body of most CNC programs is written in absolute positioning mode and smaller sections of the program are often written in incremental positioning mode. 

Incremental positioning is usually used for repetitive features such as drilling a number of holes.

The pictures below show how the locations given to the machine differ between the two positioning modes. The numbers in parentheses ( ) are the coordinates that the CNC is given for each new move.

graph paper example of absolute positioning with multiple points as examples
graph paper example of incremental positioning with multiple points as examples

Compensation Modes and Offsets

Offsets and compensation modes allow the CNC machine to be more flexible. Using them allows you to use the same program with multiple machines as well as different cutting tools.

Offsets and compensation modes also make CNC programs easier to read and understand.

Tool Length Compensation

Tool length compensation is how the CNC machine accounts for the length of the cutting tool.

G43 turns tool length compensation on and G49 turns it off. G44 also turns tool length compensations on, but it is almost never used.

Using tool length compensation allows you to tell the CNC machine how long your cutter is. This lets you use the same program across multiple different tools. Each tool will have its own adjustment, or offset value, stored in the machine’s memory.

Tool length compensation uses H offset values stored in the machine.

H offsets are selected using the H code.

illustration of a cnc cutting tool that shows what an H offset is

Cutter Compensation

Just like tool length compensation adjusts for the length of the cutting tool, cutter compensation adjusts for the diameter of the cutter.

If cutter compensation is off with G40 then the machine will move the center of the cutting tool along the path in the CNC program.

If cutter comp is on with either G41 – left compensation, or G42 right compensation then the machine will adjust the location so that the edge of the cutter follows the path given in the CNC program.

Like tool length compensation, this allows multiple different cutters to be used with the same program. Without cutter compensation, the program would need to be rewritten each time you wanted to use a new tool.

Cutter compensation is in the XY direction and tool length compensation is in the Z direction.

Cutter compensation uses D offset values stored in the CNC controller.

D offsets are selected using the D code.

illustration of a cnc cutting tool that shows what an D offset is

Work Offsets

While tool length and cutter compensation modes adjust for the cutting tool, work offsets adjust for the CNC machine itself in the program.

There are many different sized CNC machines available. Because machines vary in size, the location within the machine for a part can change.

Using a work offset such as G54 allows you to set a zero location for the program. This allows a much simpler and easier to read program. Also, work offsets let you use the same program in different machines.

Without work offsets you would need to write a new program for each CNC machine you want to run it on.

Most CNC machines have multiple work offsets available. G54-G59 are the most common.

Using multiple work offsets can be used to run more than one part at a time. The zero location gets switched and the same program is run again.

Multiple work offsets can even be used in a single program.

visual to show cnc work offsets G54-G59 with the zero locations shown

Canned Cycles

Canned cycles are a single code that allows you to perform common, repetitive machining functions such as tapping or peck drilling.

For example, peck drilling involves drilling into the part, backing up, drilling deeper, backing up again and repeat. 

Using canned cycles allows you to have a simple, easy to read line code that gives the machine instructions for what can be a long process.

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

Using canned cycles can change the length of your program by a large amount. Smaller programs are usually easier to read and programs that are easier to read are usually easier to troubleshoot as well.

Next Steps

That covers the most common G codes, but what about the other letter codes?

Once you’ve mastered the G codes listed above, dive into the list of M codes

There are a lot less M codes that get used and almost all of them are essential to know.

After that, check out the Complete List of CNC Letter Codes. You will likely know some of the common ones such as F for setting feed rates or S for setting spindle speeds through learning about the various G & M codes.

Our complete list of codes rounds them all up and puts them all in one place to make learning easy.

Check out our comprehensive CNC G code training:

Want to learn more about CNC G Code?

Absolute and Incremental CNC Positioning Modes [G90 & G91]

a graphic of a cnc machine with text that says learn g code today cnc positioning modes

What is a CNC positioning mode?

In CNC programming, a positioning mode refers to the way the CNC machine will read and understand every new XYZ location it is given.

For CNC machines, there are two positioning modes available.

The two modes are absolute positioning and incremental positioning.

Absolute mode is set using the G90 code and incremental mode is set using the G91 code.

Want to learn more about CNC G Code?

G90 [Absolute Positioning]

Absolute positioning is the mode that most of your CNC programs will be written in.

The alternative is incremental mode, and it is usually reserved for specific sections of a CNC program such as repetitive features.

The G90 code sets the machine into absolute positioning mode.

When G90 is active all locations will be given relative to a fixed point called the origin.

When we discuss coordinates, we list them in the order XYZ. If you see (1,2,3), then X=1, Y=2, and Z=3. Sometimes this is simplified to only show the X and Y coordinates such as (4,5). In this example, X=4 and Y=5.

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

Now that you understand coordinate locations, let’s talk about the origin again.

The origin is the (0,0,0) location. This means X, Y & Z all equal zero at this one point.

In absolute positioning mode the origin (sometimes called the zero location) is a fixed point. 

This means it doesn’t move.

Using absolute positioning, you will set a location in your CNC machine as the origin and all locations in your CNC program will be given from that origin.

Each new machine location is given in parentheses () below. Notice how all locations are relative to the initial (0,0) location.

graph paper example of absolute positioning with multiple points as examples

Advantages and disadvantages of absolute positioning

Advantages

  • Easier to track the location of your cutting tool throughout the program
  • Changing one location doesn’t affect all of the following locations in the program

Disadvantages

  • Code can be hard to read for repetitive tasks such as drilling a large number of holes

G91 [Incremental Positioning]

While absolute positioning with G90 has a fixed origin or zero location, incremental positioning with G91 has a zero location that changes with each move.

Every time the cutting tool moves to a new location, that location becomes the new zero point.

Compare the picture below to the absolute positioning pic:

graph paper example of incremental positioning with multiple points as examples

The numbers in parentheses () are the coordinates that the machine would be given to move to each new location in the two different positioning modes.

If at any time in the program we gave the machine a (0,0) coordinate in absolute positioning, the machine would return to the origin in the lower left corner.

If we did the same in incremental mode, the machine wouldn’t move. 

In incremental mode the origin changes each move and a (0,0) would tell the machine to move zero units in both directions.

Giving the CNC a (0,0) location in incremental mode would tell it to stay put.

Advantages and disadvantages of incremental positioning

Advantages

  • Easier to read code for repetitive features and patterns
  • Can reuse incremental sections of code easily either in the same program or as a subprogram

Disadvantages

  • Each location affects every location after it so changing one requires changing all others after it

Where you will find G90 and G91 in a CNC program

Setting the correct positioning mode is an important part of any CNC program.

For this reason, the positioning mode is often set in the safety lines of the program.

Safety lines are a line or lines of code that show up at the beginning of the program and at specific locations in the program. They are used to make sure the machine is prepared to run the next section of code.

They get used at the beginning of the program to set all the necessary modes before starting machining.

Safety lines often show up again when a tool is changed or a new machining operation is being performed.

Check out the “sections” of a small CNC program below:

  • Program start
  • Machine exterior profile of piece
  • Drill pattern of holes
  • Add counterbores to holes
  • Program end

At the start of each of these sections you can expect to find safety lines that set the necessary modes needed for the upcoming operation. Doing this allows individual sections of the program to be re-run if needed.

Imagine you ended the program in incremental mode after using the counterboring canned cycle. Then you measure your part and realize the length and width are oversize.

Bummer!

So you decide to adjust your offsets and re-run the exterior profile section of the program.

If you don’t have safety lines that make sure the machine is set to absolute positioning mode, then the machine will remain in incremental mode and interpret the code very differently.

Setting your positioning mode is very important. Even if it doesn’t change often in the program, the codes get used frequently to make sure all the correct modes are set.

Which positioning mode is better?

Neither positioning mode is better, but they do have their own uses.

The body of most CNC programs will be written in absolute positioning mode. 

This is because it is easier to understand and visualize where the cutter is.

In absolute mode you only need to know where the origin and the new location are to understand your position in the machine.

In incremental mode you need to know every move the machine has made to know what position you are at. That can mean a lot of calculations to figure out where you are located.

This might make it seem like absolute positioning mode is the best and should be used for everything, but that is not always the case.

Incremental mode is great for patterns and features that repeat. 

This means incremental mode is often used when working with canned cycles.

Which codes will be affected by your choice of positioning mode?

Any code that uses XYZ movement as part of the code will be affected by your positioning mode.

All movement codes are affected by your choice of positioning mode:

Canned cycles are another set of commonly used codes that will be affected. They vary from machine to machine but generally canned cycles are the G73-G89 codes.

Another important code that is affected by your positioning mode is G28. The G28 zero return command can behave very differently from one mode to the other, so make sure you know how your machine will react before using it.

This isn’t a complete list of codes. 

There are many more that are affected by your choice of positioning mode, but this is a good start for anyone new to CNC machining.

As always, know your machine and check the manual if available to fully understand how it will react to any code you give it.

Frequently asked questions about CNC positioning modes

What happens if you don’t select a positioning mode?

On most CNC machines, there is a default positioning mode.

If you don’t use the G90 or G91 command, the machine will stay in the default mode.

The default mode is most often set to incremental mode for safety reasons.

It is not recommended to rely on the default modes of your machine to make sure you are in the correct positioning mode. 

You should always set the positioning mode you need with either a G90 or G91 code.

Can you use the G90 and G91 codes on the same line/block?

No, it is not possible to use the G90 and G91 commands on the same line.

Both G90 and G91 are modal commands from the same group. This means turning one on turns the other off.

With G90 and G91, only one code can be active at a time.

What could happen if you use the wrong positioning mode?

To put it simply, your machine could crash.

Moving to the (0,0) location in absolute mode with G90 will bring you to the part zero location. This could be any location you chose on your workpiece.

Moving to the (0,0) location in incremental mode with G91 will not move your machine at all.

These are two very different commands being executed based on the positioning mode.

Forgetting to set the correct positioning mode can cause the CNC machine to act in very unexpected ways for the programmer. Unexpected is never good when it comes to CNC machining.

Because being in the correct positioning mode is so important, the positioning mode is often set in the safety lines of the program.

Safety lines are used to make sure the machine is in all of the correct modes before running a section of the CNC program.

Want to learn more about CNC G Code?

Modal G & M Codes for Your CNC [What They Do & How to Use Them]

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

What is a modal command?

Modal commands are a type of CNC code that stay active once turned on until the code is either turned off or switched to another code in the same group.

For example, if left cutter compensation is turned on with G41 it will stay on until either the G42 code switches the machine to right cutter compensation or the G40 command is used to turn off cutter compensation altogether.

Want to learn more about CNC G Code?

Why and how are modal commands used?

Modal commands are useful because they increase productivity. 

Modal commands can save time for the CNC programmer and make the CNC program smaller.

Using modal codes allows you to not have to write the same code repeatedly. This also has the added benefit of making the program easier to read.

By using modal commands you set the machine modes once and then switch them as needed.

A good example of this is your unit mode.

Most programs will be written in either inches or millimeters. It is not common for a program to switch between the two unit types. 

Using modal commands allows you to use the G20 code and set the machine in inch mode at the start of the program and leave it on.

Without the capability to use modal commands, you would need to tell the machine that every new line of code was in inches. 

This would make for a very busy, hard to read program with a bunch of codes repeated throughout.

Modal commands make the programming easier to create and easier to read.

Remember you can only have one modal command from the same group active at a time. 

Also, there are some commands which are one-shot codes. This means they only affect the line they are used on.

The various modal groups are shown below.

Modal command groups

To really drive the point home, remember:

You can only have one modal code active from each group. 

If you use G20 to put the machine in inch mode and then use the G21 command to put the machine in metric mode, they are not both active. The G20 command gets turned off when the G21 command is turned on.

Some of the groups of codes have a cancel command which can be used to turn all codes in the same group off. 

Not every code group has a cancel command though. 

For instance, you will always be in either G20 (inches) or G21 (mm). It is not possible to turn both off. One or the other must be active.

If a code group has a cancel command, it is discussed in the individual group sections below.

Movement [G00, G01, G02, G03]

One of the most frequently used group of codes is movement codes.

CNC machines need to move to cut, drill, and grind parts along with many other functions.

Many times, large portions of your CNC program will be exclusively movement codes as the machine performs its cutting operations.

In the movement group of codes there are four different codes:

You move with G01, G02 and G03 to make cutting movements to make all kinds of shapes and cuts on the part, but what about G00?

G00 is rapid movement and is used to move the machine as quickly as possible when it is not in the process of cutting.

Moving rapidly reduces the total machining time, otherwise known as cycle time. While this might not make a huge difference for making one part in your garage, shaving a minute off each part for an order of 1,000 pieces really adds up.

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

Units [G20, G21]

comparison of units of measurement for cnc programming

We talked about it above but the codes used to set your units are very important.

G20 sets the machine in imperial units (inches) and G21 sets the machine in metric units (mm).

Switching between units is not advised. Set your units and stick with them.

Cutter compensation [G40, G41, G42]

Cutter compensation is a mode that allows the machine to adjust for the size of the cutting tool.

This allows the same program to be used with multiple different cutting tools. Without cutter compensation, you would need to write a new program each time you had a new cutter.

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

The first code in the group is the cutter compensation cancel command, G40. When this code is active, the CNC will move the center of the cutting tool along the tool path listed in the program.

This is useful when you want to drill a hole at a specific location.

The two cutter compensation modes which cause the machine to adjust the tool path are:

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

Both modes adjust the path of the cutting tool so that the edge of the cutter follows the toolpath of the program.

G41 is used when climb milling and G42 is used when conventional milling.

G41 is used far more often than G42.

Both G41 and G42 take into account the D offset value to tell the CNC how much to adjust the tool path. 

The D offset value is listed when turning on cutter compensation. For example, to turn on left cutter compensation with the first D offset the line of code would be:

G41 D1

Tool length compensation [G43, G49]

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

Just like the diameter of the cutter needs to be accounted for, so does the length of the cutting tool.

G43 is the code to turn on tool length compensation. 

This code is used along with an H offset value which is stored in the CNC controller similar to the D offsets used in cutter compensation.

Tool length compensation is used for many of the same reasons cutter compensation with G41 and G42 is used. 

It allows the machine to adjust for the length of the cutting tool and not require a new program to be created each time the tool is changed.

Technically, G43 is for positive tool length compensation and G44 is for negative tool length compensation.

For anyone just learning about modal commands, they should ignore G44 for the time being. 

G44 is not used often and is not something that a beginner can expect to deal with.

Focus on G43 and G49 when first learning CNC programming.

Speaking of G49. G49 is the code to cancel tool length compensation. 

Remember cancel just means turn it off.

You might think that you would need to turn off tool length compensation much like you would with cutter compensation, but this is rarely true.

Instead, the machine will switch between tools by using different H offsets for different length cutters.

When tool length compensation is off using a G49 code, the machine will move the tip of the spindle to each new location instead of the tip of the cutter. 

Because you will almost always have a cutting tool in your spindle, tool length compensation with G43 is almost always on.

Fixture/work offset [G54-G59]

Fixture offsets, sometimes called work offsets are how the machine knows where your part is located in the machine.

They tell the machine the zero location in the three axes (X, Y, & Z). The machine will execute the program based on this zero location.

Using work offsets allows you to easily set up for a different part or even use one program to run multiple parts at once. 

You can tell the machine the location of your first part by using G54, run your program then set the work offset to G55 so the machine knows where the second part is and proceed to run the same program again.

visual to show cnc work offsets G54-G59 with the zero locations shown

Just like your D and H offsets allow flexibility in your CNC programming and setup, work/fixture offsets with G54-G59 do the same.

It should be noted that G54 through G59 are the most common work offsets used and can be found on most machines. 

In addition to these six offsets, most machines (especially new models) will be able to use many more offsets. How they are used varies from machine to machine so check your machine manual.

Positioning mode [G90, G91]

Positioning modes tell the CNC machine how to interpret each new location it is given.

There are two types of positioning modes which can be used:

Absolute positioning with G90 tells the machine that all dimensions are measured from the datum/origin (0,0,0). This is a fixed point in the machine that will not change unless the work offset is changed.

Incremental positioning with G91 tells the machine that each new location becomes the zero location (0,0,0).

The pictures below show the same tool path in both positioning modes. The coordinate location of each new move is listed in parentheses ().

graph paper example of absolute positioning with multiple points as examples
graph paper example of incremental positioning with multiple points as examples

Canned cycles [G80, G81, G82, G83, G84, G85, G86, G87, G88, G89]

Canned cycle are modal commands which are used for programming repetitive CNC operations.

They have the benefit of making your CNC program both shorter and easier to read and understand.

Canned cycles are a big topic on their own so I will only include a brief description of what each code is used for. If you need more information about any of the individual canned cycles, then click the links below:

Plane returns [G98, G99]

Plane returns tell the machine how to act after finishing a canned cycle. 

The two options are:

G98 returns to the point where the canned cycle was started. 

G99 returns to the R plane, which is the point where the controlled feedrate (not rapid) started.

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

The R plane is lower than the initial point. This can allow for shorter machining time because the machine is not travelling as far.

Often a series of holes will be drilled and both G98 and G99 return codes will be used in the process.

The G99 code gets used when the machine is able to stick close to the part and move to the next hole.

The G98 code is used when the machine needs to retract further, for instance if you needed to avoid a clamp or something else in the way of your cutter.

G98 retracts further and takes longer but is generally the safer option.

You should be careful using both G98 and G99 though.

Pay close attention to the initial point (your Z height when starting the canned cycle) and your R plane (set with the R code in your canned cycle callout).

The initial point should be set at a level that is higher than any objects in the machine such as the part itself, clamps, fixtures, etc.

Plane selection [G17, G18, G19]

There are 3 codes that tell the machine which plane to work in:

  • G17 for the XY plane
  • G18 for the XZ plane
  • G19 for the YZ plane

Most programs will be written using the G17 code and work in the XY plane.

Modal M codes

In addition to the modal G codes listed above, there are also modal M codes available for controlling various machine functions.

These modal M codes work in the same way as the G codes. Once they are used, they will stay on until canceled or switched to another code in the same group.

Spindle commands [M03, M04, M05]

Spindle direction

This group of modal commands controls the CNC spindle. They are:

Coolant [M07, M08, M09]

The next group of modal M codes controls the machines use of coolant.

Mist coolant is usually a combination of coolant and compressed air but this can vary from machine to machine and sometimes you may find that it is only compressed air or not even available on your specific machine.

Flood coolant is the normal CNC coolant mode where the machine floods the cutting tool and workpiece with coolant.

M07 modal command turns on the mist coolant and it will be directed to the material cutting.

Other modal commands

There are many other modal commands which can be used for CNC programming. 

They vary by machine and not all machines will have each type of modal code.

The codes laid out here are the most common modal commands and will give anyone trying to learn CNC programming a good start towards learning the ins and outs of modal commands.

Frequently asked questions about modal codes

Modal vs one shot codes

While there are a lot of modal codes, not every CNC code is modal.

There are also one-shot (non-modal) commands as well. These codes only affect the line they are used on.

A couple of the commonly used one-shot codes are:

What happens if I don’t set a modal code?

When the CNC machine starts up it sets the machine to various default modes as set in the setup parameters of the machine.

It is never advised to rely on the startup modes of the machine to create your program. It is always better to call out any needed codes specifically in your program.

If you don’t set a modal command, the machine will remain in the default modes as set in the system parameters.

Want to learn more about CNC G Code?

CNC Offsets Explained [D, H and Work Offsets]

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

What is a CNC offset?

Offsets are the adjustments that the CNC machine will make based on different features of the machine.

There are three types of offsets:

  • Diameter offsets
  • Height offsets
  • Work offsets

Want to learn more about CNC G Code?

Types of CNC offsets

Each of the three offset types has a specific purpose. 

They each allow for flexibility when running your program. This includes allowing you to use the same program even if you need to change cutting tools.

Height (H) offsets

illustration of a cnc cutting tool that shows what an H offset is

The height offset refers to the location difference between the spindle and the cutting tool.

This difference in location is stored in the machines offset library. Height offsets are usually stored in the same number location as the tool.

mach 3 tool offset table
Example offset library

For instance, T01 (tool 1) and H01 (height offset 1) or T05 (tool 5) and H05 (height offset 5).

This makes it easier to match up the necessary offset with the correct tool.

The G43 code is used to turn on tool length compensation using an H offset.

For example, G43 H01 turns on tool length comp with the first H offset.

Once tool length compensation is turned on with the G43 code, it will stay on until it is turned off with the G49 cancel code or switched to a new H offset such as H02 or H05.

Diameter (D) offsets

illustration of a cnc cutting tool that shows what an D offset is

While H offsets adjust for the length of the cutter, D offsets compensate for the diameter of the cutting tool.

D offsets are also stored in the machines offset library. D offsets are usually stored in the same number location as the tool they are used with.

T04 (tool 4) and D04 (diameter offset 4) would usually be matched together.

G41 and G42 are the two cutter compensation modes that are used with D offsets.

They tell the machine to adjust the path of the cutter so that the edge of cutter follows the path given in the CNC program. G41 shifts the cutter left and G42 shifts the cutter right.

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

With cutter compensation off using the G40 code, the machine will move the center of the cutter along the path in the program. 

This can make it difficult to get the correct size, especially when using different or multiple cutters.

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

Telling the machine the size of the cutters with your D offsets allows it to account for them and run the same program with different tools ang get the same size part. 

If you didn’t have cutter compensation, then you would need to create a new version of the program every time you wanted to use a new tool.

Just like tool length compensation with G43, cutter comp with G41 and G42 are modal commands so those adjustments will stay on until switched or turned off with the G40 code.

Work offsets (G54-G59)

Work offsets are basically the stored location of your part in the machine. 

You use them to set the XYZ zero location when working in absolute positioning mode.

There are multiple work offsets available. 

The six most common are G54 through G59. Most machines will also have others available, but the format varies from machine to machine.

visual to show cnc work offsets G54-G59 with the zero locations shown

Fanuc controls are one of the most common controllers. If they allow additional work offsets, the Fanuc format for using them is G54.1 P1, G54.1 P2 and so on. The P number is the additional offset.

In most cases the six offsets of G54 through G59 that are common on all machines will be more than enough.

One benefit of having multiple work offsets is how easy they make it to run multiple parts at once. You can set the work offset for multiple parts and run the same program with a new work offset each time.

This works well when you a fixture that holds multiple parts in your CNC.

Where are offsets stored?

Offsets are stored in the tool offset table or library.

This tool table allows you to describe the different dimensions of the tool that will affect the program.

This includes the tool radius or diameter (D offset) and its length (H offset).

Offset Library
Tool offset library on an Okuma CNC machine

Some machines allow you to store the H and D offsets together in one offset. In this example, tool T01 would use both H01 and D01 as offsets. 

Other machines may require the offsets to be stored individually. 

When the offsets are stored individually, the programmer should maintain a system so that the offset numbers used are consistent. 

In other words, the first H offset would always be stored in the 01 location and the first D offset would always be stored in the 51 location.

Having a system like this will help prevent errors in your program.

Want to learn more about CNC G Code?