Quick Guide to the G20 CNC G Code [Tips and Tricks]

a graphic of a cnc machine with text that says learn g code today G20 inch mode

Code

G20

Name

Inch mode

Type

Modal - stays on until changed

Description

The machine will interpret all size and location values as in inches

A G20 code will switch the CNC into inch mode. Once the G20 code is used, all sizes and locations in the program will be treated as inch values until the mode is changed.

This type of G code is called a modal command.

Modal commands remain in effect until they are canceled. This holds true even if you restart your program. Until you cancel the command or change it, the G20 code would remain.

This can cause trouble if you aren’t paying attention.

For this reason, most CNC programs will be created with start-up or safety commands. The safety commands make sure that the machine is always in the correct modes.

When to use a G20 code?

A G20 code can be found at any point within the program but the most likely location is at the start of the program or at the start of a new block of code.

For instance, you might switch the CNC into inch mode by using the G20 command immediately before starting a drilling cycle.

The machine may already be in inch mode but placing the G20 command immediately before the drill cycle will ensure the program is in inch mode. All kinds of things can happen when machining and it isn’t uncommon for the machine to crash or some part of a program needs to be re-run.

Placing the safety commands (G20 in this case) at the start of the new block of code makes sure your machine does exactly what was intended.

With this example, the customer won’t be happy if you give them holes that are 1mm instead of 1 inch. If it goes the other way and you make a hole that is 1 inch instead of 1mm just tell them that the extra work is on the house.

What to think about when using a G20 code?

When you use a G20 code you simply need to be aware of what type of units you are working in. Most machine shops will work in either inches or mm.

There are definitely some shops out there that will use mixed units, but in most cases CNC programs will be written in one or the other for every program they make.

Know whether your parts are in inches or mms.

4 G20 code examples and descriptions of what they do

For the examples below, we will assume your machine is in absolute mode (G90). If you are working in incremental mode (G91), the resulting movements will be different. Check out our guides to G90 and G91 G codes to understand the difference between the two movement types.

Example #1

N005 G20 G00 X4.0 Y5.0 Z2.0

N005 is line number 5 of the program.

G20 sets the units as inches

G00 sets the movement mode as rapid travel.

X4.0 Y5.0 Z2.0 is the location the machine will move to. If the Z location of the machine was already at 2.0 inches, then the Z axis will not move. This is the same for each axis.

Example #2

N360 G20

N365 G01 X4.0 Y5.0 Z2.0

N365 is line number 365 of the program.

G20 sets the units as inches

G01 sets the movement mode as straight line (linear interpolation).

X4.0 Y5.0 Z2.0 is the location the machine will move to. If the Z location of the machine was already at 2.0 inches, then the Z axis will not move. This is the same for each axis.

This example is at a different spot in the program (N005 vs N365) but will act the same as the previous example with the exception that this example will not move in a rapid travel manner.

Notice that the G20 code can be called out on the previous line and it will still be in effect on the next line.

Example #3

N025 G20 G00 X1.0

N030 G21 X1.0

N035 X25.4

N025 is line number 25 of the program

G20 sets the units as inches

G00 sets the movement mode as rapid travel

X1.0 moves the machine to a location where X=1.0 inches

Example #4

N030 is line number 30 of the program

G21 sets the units as millimeters

X1.0 moves the machine to a location where X=1.0 mm

N010 G80 G40

N020 G20 G90

This is an example of a safety or startup command. They vary though and you need to know you machine to make sure you use the correct codes. Do not assume that using the code above will be correct for your machine.

N010 is line 10 of the program

G80 cancels all canned cycles

G40 cancels cutter compensation

N020 is line 20 of the program

G20 puts the machine in inch mode

G90 sets the movement mode as absolute

Codes that are similar to G20

All of the codes listed in the table below are modal commands that affect the way the CNC machine interprets size and location values that are entered.

Want to learn more about G Code for your CNC?

Leave a Comment