G-Wizard Calculator:
Fast, Easy, Reliable Feeds and Speeds


Join 100,000+ CNC'ers!  Get our latest blog posts delivered straight to your email inbox once a week for free. Plus, we’ll give you access to some great CNC reference materials including:

  • Our Big List of over 200 CNC Tips and Techniques
  • Our Free GCode Programming Basics Course
  • And more!


GCode is Complicated
G-Wizard Makes it Easy

9 Easy G-Codes Every Machinist Must Learn

Feb 11, 2013   //   by Bob Warfield   //   Beginner, Blog, GCode  //  9 Comments

CNC Control Panel

For those of you who are manual machinists and still wondering what CNC can do for you, there are 9 basic g-codes you must learn today.  If you know them, and they are easy, they will turn the CNC Machine into the equivalent of a manual machine with power feeds and DRO’s on every axis.  They do this because you can use them as simple immediate commands without having to write a g-code program.  You just type in one of these 9 gems and the machine will perform that action immediately through the magic of what’s called “MDI” or “Manual Data Input.”  MDI is like the command line prompt from DOS for CNC and it is handy as can be for quick and dirty operations.

Each of these 9 g-codes is super easy to understand so let’s go through them, one at a time:

Move in a Straight Line:  G01

G01 is the very first g-code you should learn as it is the one you’ll use the most.  It causes the machine to move in a straight line based on the coordinates you enter afterward.  For example, let’s say you’ve got a piece of material in the milling vise, and the top left corner is at 0, 0, 0.  You want to move the cutter tip to that location, but a little above the work as you’re not ready to cut yet.  You could use this MDI command:

G01 X0 Y0 Z0.5

You can see how that would move to X = 0, Y=0, and Z=0.  Congratulations, you’ve just learned your first g-code and it was pretty obvious.  Some things to take note of:

–  G-Code ignores spaces.  You could’ve also typed (and you will often see in programs) this:  G01 X0Y0Z0.5

–  The Z-axis is positive in the “up” direction.  As you can imagine, it’s extremely important to get used to which way the spindle will move, up or down, based on your commands.  If it moves the opposite of what you’d expect and you’re at all close to anything, you may crash into it.

–  The g-code dialect will determine whether you need that leading zero or could write “G1” and whether you need a decimal point no matter what like “X0. Y0. Z0.5”.  If things act odd, be sure to check on that for your machine.

For an understanding of how to establish the part corner being at 0,0,0, consult your machine’s manual, but I will tell you in advance it’s just like using a DRO.  You position the tip of the cutter somewhere and press buttons that set the “DRO’s” to be zeroed.  Easy, but just a little different on each machine.

The experienced reading this will wonder why I didn’t start with G00 instead of G01.  After all, most g-code programs start with G00.  This is a bit of extra credit, but an important bonus point.  G00 is a rapids move in a straight line.  It has the same syntax as G01, so that last move would be:

G00 X0 Y0 Z0.5

The difference is that G01 moves at feed rate and G00 moves at rapids, which is the fastest your machine can use.  When I am operating a CNC manually in MDI mode, I prefer not to use G00.  It’s just too fast and G01 is safer.  Plenty of time to hit that red button if you type in the wrong thing.

You can move pretty fast too in feed rate, so let’s make our next g-code the “F” word (hey, what did you think that meant?).

Feedrate: F

“F” word, eh?  No, not that F-word, silly!

In g-code we refer to words and addresses.  The word is the letter and the address is the number that follows.  “G01” is word “G” and address “01”.  Hence, we call it the “F-word” because it uses the letter “F”.  This is the g-code needed to set your feedrate.  For example, on a machine using Imperial units, “F100” tells the machine to move at 100 inches per minute.  When I am just moving the tip around in air, I generally will use “F100” as the rate I move.  I consider that to be my “rapids” speed for MDI work.  It’s slow enough you have plenty of time to react and fast enough so you don’t grow too old waiting.

You specify the F-Word before the move. So, to plunge down from our last move at a feedrate of 5 inches per minute to a depth of 1/2″ after our last MDI command we’d enter something like this at the MDI prompt:



Some things to note:

–  We didn’t have to specify G01 again, although we could have.  CNC is modal, meaning it remembers a lot of things you do.  In particular, the motion is modal.  If we had just run a G00 and no other motion commands since, any coordinates we enter result in G00 moves.  In this case, we depended on the prior G01 mode to still be in effect.  This is another reason I dislike using G00 for MDI work.  I’m just the kind of guy who’d do a G00, get distracted, think I was in G01, and enter a move.  DOH!  Broke another tool, darn it!

–  Not only does g-code not care about spaces, it doesn’t care about any white space.  I could’ve put the F-Word on the same line:

F5 Z-0.5

Okay, you’re cooking with fire now.  You can move the tool and control how fast it moves.  Hopefully you like my use of a big F-word instead of G00, and I also hope you have a good tool like G-Wizard CNC Calculator to help you determine the right F-Word to use.  In other words, the correct Feeds and Speeds.

Spindle Speed: S

Speaking of Speeds, it’s time to set the spindle rpm.  For that, we’ll use the S-Word and follow it up with rpms.  “S1000” gives 1000 rpm on the spindle.  Except it doesn’t.  You type that in and the spindle just sits there. All S is doing is telling the spindle that when it starts spinning, it will do so at 1000 rpm.  Kind of like “F” not causing any motion, just telling the CNC that when the motion happens, that’s how fast it should move.  To actually start the spindle spinning you will need:

Clockwise Spindle:  M03

As soon as you enter the “M03”, the spindle will start to rotate clockwise at its programmed speed.  Now you really are in business.  You can move the tool tip at feed speeds and you can turn on the spindle.  Pretty easy so far, right?  And we’ve got most of it down.  Just one thing, you probably don’t want to be cutting without some coolant, right?

Coolant:  M07/M08/M09

Good idea, let’s don’t cut without coolant unless we really understand dry machining, and even then, we probably want an air blast.

There are definitions for what M07 and M08 are supposed to do, but I am not going to tell you what they are.  People can hook up the machines to do all sorts of things.  For example, M07 could turn on an air blast or mist and M08 could turn on full flood coolant.  Suffice to say M07 and M08 turn on two different kinds of coolant.  Give each one a try to see what it does.  M09 turns off the coolant, which is another good one to know.

That ought to do it.  You should be ready to cut.  But wait, there’s one thing missing.  How about selecting a tool?

Tool Changing:  T+M06

You could certainly manually insert a tool in the spindle taper.  That’s not hard and you need to know how to do that.  But if your machine has a tool changer, there’s a bunch of them sitting there and probably several would be convenient to access.  With just two more g-codes, you’ll know how.

Tool Changing is a two step process on a mill (and on some lathes, but most lathes don’t use the M06).  First, you select the tool with a T-Word followed by the tool number.  Then you perform the tool change with M06.  You can put them on two lines or write them together:

T12 M06

Select tool in slot #12 and swap it into the spindle.

One more for extra credit:  Peck Drilling

With those 9 g-codes, you can do a lot.  You can run circles around your manual machinist friend, for example.  Let me give you one more, just because it is often convenient to drill holes using MDI g-code, and when you drill a hole deeper than one diameter, you really ought to peck drill.  G- Code includes what are called “Canned Cycles.”  Canned cycles do all sorts of miraculous things in one command instead of requiring you to write a bunch of g-code.  Imagine how painful peck drilling would be if you were programming each in and out cycle all the way down the hole with G01.  You could do it, but it wouldn’t be much fun.  Canned cycles are available for all sorts of functions, but right now let’s learn how to do a simple G83 deep hole peck drilling cycle.  I picked that one because it is fairly universal.  There are faster cycles for special cases and slower cycles for other special cases, but this one will work for a lot of holes.

A typical G83 looks like this:


XY: Coordinates of the hole

Z: Hole bottom

R: Retract position in Z. Motions from initial Z to R are performed at rapids speeds. From R to hole bottom is done at feed speed.

P: Dwell time at bottom of hole.

Q: Depth to increase on each peck.

F: Cutting feedrate

L: Number of repeats

I’ve left out the addresses associated with X, Y, Z, R, P, Q, F, and L.  Once the drill reaches the bottom of hole and has finished dwelling, retraction is at rapids speeds.

Now here is a real example:

G01 X0 Y0 Z0.5

G83 X0Y0Z-1.0 R0.1 P0.1 Q0.1 F2

We’ll ignore L for the time being.  Repeats are probably not something you will use much for MDI.  I stuck the G01 in so we would have a frame of reference.

So, the tool tip moves to X0Y0 and is 1/2″ above 0, which I usually program to be 1/2″ above my workpiece.  We’re going to peck every 0.1″ on the way down.  What that means is the drill will retract every 0.1″ of additional depth drilled.  And, we’re going to dwell a tenth of a second at the bottom of the hole.  This just cleans up the bottom and makes sure there’s no chips left down there.

That’s it!

You’re now armed with 10 basic g-codes you can use at the MDI prompt of your machine to do all sorts of things.  Go ahead and practice them a bit with G-Wizard G-Code Editor and Simulator.  Then try it at your machine.  It’s very convenient to drill a quick hole or to face off the top of some material without having to go fire up your CAD/CAM software each time.


Like what you read on CNCCookbook?

Join 100,000+ CNC'ers!  Get our latest blog posts delivered straight to your email inbox once a week for free. Plus, we’ll give you access to some great CNC reference materials including:

  • Our Big List of over 200 CNC Tips and Techniques
  • Our Free GCode Programming Basics Course
  • And more!

Just enter your name and email address below:

Full Name
Email *
100% Privacy: We will never Spam you!

9 Easy G-Codes Every Machinist Must Learn
3.7 (73.33%) 3 votes


  • Hey Bob, nice basic list. And you taught me a new thing. I use G83 a lot, but didn’t know that it could have a dwell. Thanks for that.

    I’d suggest just one more code — M05 to turn the spindle back off. 🙂


  • Debug means What / how you do it ?

  • Great info. Would love more ways to start learning G code before actually having the machine.

  • Good list bob, but i’d add a little note on the peck drilling. You only want to peck with HSS drills, carbide drills don’t like to peck. wouldnt want someone to waste a pricey drill!

    • David, it seems to be less a matter that carbide drills don’t like to peck as that they may not need to peck. Different manufacturers say different things about the practice. Sandvik, about their solid carbide Corodrill Delta C says you can go ahead and peck if you need to, but it probably won’t be needed unless you’re more than 8 diameters deep. OSG, for their Exo Carb Max-Mini says you MUST use an appropriate peck cycle when needed.

      I have seen similar recommendations from others. Given how much faster carbide drills runs, they can evacuate the chips more vigorously. Best thing is to check with the drill manufacturer to be sure before attempting to peck drill a carbide drill.

  • […] fact, I am fond of saying that by mastering just a few g-codes and MDI, any manual machinist can run a CNC and it will function jus….  People who think manual is faster for certain things have to consider that used like that, a CNC […]

  • Dear Bob, Thank you for the very basic about G-codes. It helped me a lot.
    But I have one question. Can I write a G-codes like “M6T2” for tool changing?
    actually I use that code for my tool changer for almost two years. what is the difference between “M6T2” and “T2M06”? are those same syntax??
    please let me know. I’m really curious about it. Thank you!

    • Sure, those are fine. The leading zero (M06 vs M6) is a function of your controller’s g-code dialect. Some may require it, most will not. Also, the order (T2M6 or M6T2) may not matter as long as they are both on the same line.

  • Thanx for your help

Leave a comment


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 © 2016, CNCCookbook, Inc.