G21 CNC Code Explained: An Easy Intro for Beginners [Metric Mode]

Welcome to our comprehensive guide to using the G21 CNC code. Whether you’re a beginner learning CNC programming or an experienced machinist, understanding the G21 CNC code is extremely important.

In this guide, we’ll break down everything you need to know about this unit mode command, including how, when, and why to use it.

What does a G21 code do?

A G21 code will switch the CNC into metric mode.

Once the G21 code is used, all sizes and locations in the program will be treated as millimeter 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 or changed to another code in the same group.

This holds true even if you restart your program.

Many, but not all modal codes have a cancel command to turn the mode off.

Note: There is no cancel command for unit modes. One of the unit mode codes must be active.

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.

Learn CNC Programming – It’s Easier Than You Think!

Learning G Code doesn’t have to be difficult…

If you know what to focus on.

Join our simple, easy-to-follow course, “G Code Made Easy: CNC Programming for Beginners“. We walk you through all the important codes – with simple explanations and real-world examples.

Want to become a super-skilled CNC programmer? Join now to take the shortcut to becoming a G Code Master today!

Make Learning G Code Easy

G21 [mm mode] vs G20 [inch mode]

It should be pretty obvious from the names but the other unit mode to consider is G20 – Inch mode.

When G20 is the active units code, the machine will read all locations and values as in inches.

comparison of CNC unit mode codes G20 and G21

Neither code can be canceled. The only way to turn on off is to switch to the other.

It is not advised to switch units in your program.

When to use a G21 code?

A G21 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 section of code.

For instance, you might switch the CNC into metric mode by using the G21 command immediately before starting to cut a slot in the part.

The machine may already be in metric mode or it could be in inch mode, but placing the G21 command immediately before the new block of code for the slot operation will make sure you are working in the correct units.

All kinds of things can happen when machining and it isn’t uncommon for the machine to crash or some part of a program to need to be re-run.

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

What to think about when using a G21 code?

When you use a G21 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 millimeters.

CNC codes that are similar to G21

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.

Ready to master CNC programming?

Join our simple, easy-to-follow course, ‘G Code Made Easy: CNC Programming for Beginners’ and take the shortcut to becoming a G Code Master today!

Master G Code Today

Leave a Comment