G-Code Cheat Sheet + MDI: Your CNC Secret Weapon

Do you want to be a better CNC'er in 37 Seconds?

Get Better Tool Life, Surface Finish, and Material Removal Rates Fast.

It's that easy. You can install and get results now.


G-Code Cheat Sheet + MDI: Your CNC Secret Weapon

CNCCookbook’s G-Code Tutorial

G-Code Cheat Sheet?  Now You’re Talking!

I’m going to let you in on a little secret: with just 9 g-codes and something called “MDI”, you can use a CNC to do everything a manual machinist could do.  If you’re a manual machinist looking to become productive fast on a CNC, this is your secret weapon and shortcut.  If you’re a beginner starting out with CNC, this is a way to quickly do some simple things before having to learn all the rest of it.

Have I got your attention?  Cool!

CNC Can Be Quick and Dirty Too!

Many manual machinists are under the impression that CNC is only good for manufacturing multiple identical parts, and that one offs are a lot faster to do on manual machines. They have visions of spending hours making CAD drawings of even the simplest parts and then feeding those CAD drawings through a CAM program to finally produce G-Code, at which point they are finally ready to make some chips.

It just ain’t so!

Good CNC machinists can do most anything a manual machinist can do and then some. This article is all about how.

Lathe Gal

You can do anything on your CNC that the manual machinist can and often faster once you know how…

DRO’s and Power Feeds

The first trick is to forget about G-Code, CAD, and CAM. Think of that fancy CNC machine as nothing more than a manual machine that has DRO’s (digital read outs) and Power Feeds on all of the axes.

For beginners:

  • Power Feeds:  The machine can move under motorized control.  Easy, right?
  • DRO:  DRO is short for “Digital Read Out”.  It’s just an indicator telling you the exact coordinates the machine is at every step of the way.

Most manual machinists would see a machine like that as a tremendous improvement over handwheels and no DRO’s, and wouldn’t hesitate to use such a machine.

Once you get used to the idea of using your CNC in that capacity, you’ll be surprised at how easy it is.

Fanuc Panel

A typical Fanuc panel you might use…

But how does it work? The CNC certainly doesn’t look like a manual machine with DRO’s and Power Feeds. There’s way more knobs and buttons and no handwheels!

How to Access MDI

The trick is something called “MDI”.

The Manual Data Input Mode (MDI) is one of the modes your CNC machine can operate in. The idea is to enter g-codes on a line which are executed immediately by the machine–you don’t have to write an entire g-code program when a line or two will suffice. MDI offers a lot of power while requiring very little learning. You can even use MDI commands to machine your part. With MDI, CNC can be quick and dirty just like manual machining.

MDI is accessed via the MDI key on your CNC machine’s control panel:

Press the MDI key on your CNC control panel to go to MDI mode.

Press the MDI key on your CNC control panel to go to MDI mode…

With MDI, you input short commands that tell the machine what to do.  We’ll get to our g-code cheat sheet for you shortly, but let me finish setting the stage first.

Power Feeds for your CNC

What about those Power Feeds?

There are two approaches. First of all, CNC’s have the ability to jog. Jogging is where you’re spinning a simulated electronic handwheel, or holding down a button or joystick to make the axis move. You generally select an axis, select a speed or multiplier (x1, x5, x100 or whatever), and then operate the control to move the axis. It’s pretty easy. Here is a typical pendant with an electronic handwheel (called an “MPG” or “Manual Pulse Generator”) for jogging:


A pendant for jogging a CNC. Select axis and speed then spin the wheel…

But, there is a better approach if you’re actually trying to do some machining as opposed to touching off a setup.

Your CNC has the abilty not just to go where jogging tells it too.  It can go immediately at any speed you want to a command coordinate.  You tell it to do so using MDI and one or more g-codes from our g-code cheat sheet.  More on how shortly.

Digital Read Outs (DRO’s)

Check out this Mach3 Standard Mill home screen:

Mach3 Standard Mill

Mach3 Standard Mill Screen Set…

You can see the XYZ DRO’s on the lower right. Just to the left of them is the MDI type-in field. When not running a program, you can type G-Code commands into the MDI field for immediate execution. Look up in your operator’s manual how to go about accessing MDI for your controller.

Get familiar with where the DRO’s are located on your CNC machine.

Using MDI to Move the Axes With G01 and F G-Codes

To use MDI to move the Axes of your machine, you need to know a couple of G-Codes.

G00 G-Code: Rapid Motion in a Straight Line

G00 (some machines will accept G0 too) tells the machine to expect rapids motion. It is a mode, as we discussed earlier. Most CNC’s come up with G00 active by default, meaning if you enter coordinates, they’ll cause rapid moves. “Rapids” are when your machine moves absolutely as fast as it can to the place you’ve commanded it to move.

Tip:  Beginners, I want you to ignore G00 and rapids when you MDI for the time being if you’re just starting out.

You don’t really need the machine to move at its fastest possible speed as a beginner–it just makes it easier for the machine to get away from you.

Instead, I’d like you to remember to perform a G01 command at the beginning of any session. That tells the CNC to switch from rapids to linear interpolation. It amounts to the same thing but you have a fine ability to control the speed the machine moves at using the “Feedrate” command, which is just an F. So for example, you might start up the machine and first thing you do is type in something like “G01 F20” in the MDI. What that will do is limit your machine’s speed to 20 units/minute. If you’re in inches, its 20 IPM. For metric it’ll be mm/minute.

Now the axis motions will be a lot less scary and easier to manage. If you know the feedrate you want to do your cutting at, use the “F” word to establish that feedrate. If you don’t, try something like G-Wizard Calculator to determine a good feedrate.

Practice moving the axes around with MDI. If you’re not already in G01 mode, enter “G01” to the MDI. Enter your feedrate using the “F” word–F20 for 20 IPM, for example. To make a move, simply enter the appropriate axis coordinates on the line. The machine will move using what’s called “linear interpolation”. This means multiple axes move at rates so that they all get to the end coordinates you’ve specified at the same time. If you don’t need an axis to move from its current coordinate, just don’t specify it.

For example, suppose you want to make a cut in the X axis. You’ve issued the “G01” and “F” words (G-Code calls those letters “Words”) and you’re ready for the coordinates. Let’s say your cutter is all lined up for a face milling pass, and is sitting at the correct Y and Z coordinates. You’ve got a workpiece 5″ long in X, the X coordinate on the console says 7.125 and the cutter is spinning about 1/2″ off the edge. What do you do?

Well, you want to move the 5″ and leave 1/2″ on either side. Let’s allow even a little more than that to be sure the cutter clears the workpiece–after all, we’re just eyeballing quick and dirty. So, type “X1.0” and the machine will feed the spindle right to left moving across the workpiece in the X direction.

Pretty easy, huh?

Firing Up Spindle and Coolant with S, M03, and M07 or M08 M-Codes

Consider that a hypothetical case. Had we been doing it for real, we would’ve needed to fire up the spindle and the coolant. So let’s take time to learn a couple more codes.

While the whole language is commonly referred to as “G-Code”, and we have certainly used G-Codes G00, G01, and F thus far, we’re going to need some “M-Codes” to control the spindle and coolant. Think of M-Codes as “Miscellaneous” codes.

Fanuc refers to M-Codes as “Auxilliary” functions.  Most sources say the “M” in m-code is for “Machine” functions.

Before we can start your spindle going, let’s first select a speed with the “S” word (S for Speed, it’s easy to remember most of these codes). Let’s go for 4000 rpm by entering S4000 in the MDI.

The spindle won’t actually start to rotate until we ask it to because it doesn’t know whether to go clockwise or counterclockwise. Enter “M03” for clockwise rotation and your spindle should spin up to 4000 rpm in the clockwise direction. Coolant is switched on using M08 for flood and M07 for mist or just air, depending on how the machine is set up.

You can stop the spindle by typing “M05”, and you can shut off all coolant with “M09”.

M13 and M14: Start Spindle and Coolant

On some machines, typically lathes, you may find M13 and M14. These m-codes start the spindle and the coolant at the same time. M13 starts the spindle running clockwise and M14 runs counterclockwise. Stop the spindle with M05 and coolant with M09.

Now you’ve got the gist of using MDI and with a little practice, you’re ready to make some chips and do some useful work on a CNC Machine.  Pretty easy, huh?

There are many more g- and m-codes you can use with MDI, but those are all the ones you need to do everything a manual mill with power feeds and DRO’s can do.

A Few More G-Codes to Fill Out Your G-Code Cheat Sheet

Want to fill out your g-code cheat sheet?  Even download a nicely formatted pdf that you can print and tape on the machine?

No worries, mate, we’ve got you covered.  Check out “9 Easy G-Codes Every Machinist Must Learn” and we’ll lay all that on you.

Using G-Wizard Editor’s Wizards to Help Keep Track of the Codes

OK, now I’m going to give you something even better than a g-code cheat sheet.

You’re probably starting to wonder how you’re going to memorize all these codes. After all G00 and G01 don’t exactly mean anything by themselves–they’re pretty arbitrary. Don’t worry, there aren’t all that many g-codes you’ll be using on a regular basis, certainly not on MDI. You’ll pick them up quickly with practice, and for the rest, there are quick reference tables and other tools.

What if you had a smart assistant right near your elbow at all times?  This assistant knows all about g-code and can either help you find and use the g-code you need, or tell you what a particular g-code does.

We call that handy tool G-Wizard Editor, and one of it’s best features is its G-Code Wizards. They remember all this for you so you don’t have to remember the exact codes when you’re writing a program. For example, the Toolbar groups different G-Code functions you can select for entry:

GWE Wizards

The buttons to the right of “Insert” trigger the various code insertion Wizards…

If you select “M-Code” (or type “Ctrl+M” for M-Code on the keyboard), you’ll get the Wizard for entering M-Codes:

M-Code Wizard

Each code is called out with a description of what it does…

Each code is called out in the list with a description of what it does. Just select the code you want (or type its number, the Wizards are designed so you need not use a mouse) and click “Insert” (or press Enter) and it goes into your program.

Don’t see it on the list? You can close and pop up a different Wizard or switch directly to G-Codes using the radio button at the top of the panel. The G-Code Wizard is a little fancier than the M-Code Wizard:

G-Code Wizard

G-Codes are grouped in categories…

The G-Codes are grouped into categories by the buttons at the top to help you narrow your search. So far we have only considered G-Codes from the Motion category, G00 and G01, but there are many more and we’ll be going through all of them.

Another thing to note: the Wizards only show you codes that are enabled by the Post for your control so you can’t inadvertantly enter a code that won’t be recognized and will cause an alarm (CNC jargon for an error). There are a lot more handy capabilities in the Wizards that we’ll be covering during the rest of this course.

G-Code Cheat Sheet

Here is a little quick references of the commands we’ve discussed in this article that are useful for MDI. You can print it out to keep near the machine until you memorize them. These codes and the ability to use MDI on your machine and read the console DRO display is all that’s needed to run your CNC like a manual mill with DRO’s and Power Feeds.

I really do recommend the slightly fancier g-code cheat sheet from 9 Easy G-Codes Every Machinist Must Learn.  It’s more complete and more nicely formatted, but this is even shorter and more concise if you prefer.

MDI G-Code Quick Reference
G00 Rapid motion mode. Remember: We’re going to use G01 instead, so type G01 in to cancel G00 as soon as you bring up MDI!
G01 F<ipm> Linear Interpolation mode. Motion in a straight line at the feedrate established by “F”. You can change feedrate without issuing a G01 each time.
XYZ Move to the specified coordinates in a straight line.
ABC Move the rotational axis to the specified angle.
S<rpm> M03 Set spindle to rpm and start it turning clockwise. You can change spindle rpm without issuing an M03 each time.
M05 Stop spindle
M08 Flood coolant on
M07 Mist or Air coolant on
M09 All coolant off

Final Word: Watch Out Below!

MDI is almost too easy, in fact. I broke more tools when I was learning CNC by fat fingering MDI than running programs. If you get confused, it’s very easy to start the cutter moving at high speed in totally the wrong direction. If you’re lucky, it’ll strike the edge of the workpiece moving too quickly and just snap off the cutter clean. If you’re not so lucky, you can run it into the vise or worse, your table.

Here are some tips to try to cut down on the incidence of accidents with MDI:

– Always think carefully about what’s about to happen before hitting the Enter key to initiate the MDI command.

– The bigger the tool, the worse the mishap if it crashes. Start out with small cheap endmills and leave the big expensive facemills and indexable tooling until you’re sure you have the hang of it.

– Beware dropped digits and signs. This is an easy way to go somewhere you didn’t expect.

– Use your FRO (Feedrate Override) to slow everything down until you’re sure. In fact, crank it way down before you start the command and inch it up as things look to be going okay.

– Remember, avoid G00 and stick to G01 with a slow feedrate. First because you’ll move more slowly and second because you won’t get confused about whether the machine is in G00 or G01 when you’re first starting out.

– Use your pendant and jog. It’s easier to let up if things start to get pear shaped on you. Save MDI for feeding cuts.

– Entering the workpiece or moving close to the workpiece requires the most vigilance. Once you’re in the neighborhood, small moves at feedrates are less likely to be a problem.

– Before you issue an MDI, make sure you know where the big red E-Stop button is. Visualize pressing it a couple of times. Don’t hesitate to reach for it if you don’t understand what’s going on.

– A lot of CNC controllers have a distance to go DRO readout. Use it to make a quick check as the cutter starts getting close to cutting–if distance to go is wildly greater than the amount you expect the cutter to have to move to finish your command, you have a problem.

– Don’t allow distractions while you’re running the machine. Give it your full attention, and don’t walk away. When a pilot is landing a plane, he uses his full concentration–all conversation in the cockpit not specific to landing the plane is stopped.


1. Take out your manual and figure out how to jog your CNC machine and how to issue MDI commands.

2. Use GWE as a G-Code simulator. Start with an empty file and issue your faux-MDI commands by just typing them into the text pane. Watch what happens. Get good at predicting what will happen. Learn to make the cutter go where you want it to go.

3. Once you’ve mastered getting G01 to go where you want it to in GWE, get comfortable practicing MDI commands on the machine without turning on the spindle. Start out with the spindle high above anything it might touch, and don’t issue any “Z” axis moves until you’ve got the hang of X and Y.

4. Load a piece of scrap material and a cutter and try some practice passes under MDI control.

5. Learn to use touch offs and an edge finder to precisely locate the tool just as you would with your manual machine. If you don’t know how to do this, stay tuned as we’re covering it next.

Next Article: Conversational CNC

G-Code Cheat Sheet + MDI: Your CNC Secret Weapon
5 (100%) 1 vote


Do you want to be a better CNC'er in 37 Seconds?

Get Better Tool Life, Surface Finish, and Material Removal Rates Fast.

It's that easy. You can install and get results in a matter of minutes.


Start Now, It's Free!



  GW Calculator

  GW Editor



  Deals and Steals

CNC Blog








     Feeds and Speeds

     G-Code Tutorial

     CNC Machining & Manufacturing

     DIY CNC Cookbook

     CNC Dictionary

CNC Projects


     Machinist's Search


     Online Groups


     Reference Data


     CNC Dictionary


     Tool Brands


     Hall of Fame

     Organization: Soon!





     Our History

     Privacy Policy

All material © 2017, CNCCookbook, Inc.

Pin It on Pinterest

Share This