G-Code Basics: Must Know Functions for CNC Machining! (Part 3))

Machine & Design
2 followers
9 Video Views·Jan 5, 2026
Hello my name's Mark and I am G-Code Tutor. Now I'm here with Practical Machinist to look at the
third in this series of Back to Basic with G-Code. Now this will probably be the last video in this
because after this point we can get more complicated. So I want to start off by looking
at all the different functions available for G-Code. As you can see here we've got program
numbers, block numbers, G-Code, M-Code, coordinates, radial coordinates, center point coordinates,
spindle, feed rate, tools and cycle definitions. So let's have a look at all these and what they
mean. So let's start off by looking at our program number. So the program number can
often be confused with a zero but actually starts with a letter O followed by two zeros and a one
here. Okay so next up we have N, block number. So the block number is what we use to number each
line of code. Well we used to. Now we tend to use them as a search function or as a way to call
upon a part of the program such as a subroutine. So I always start off each sequence with an N
number that matches my tool number. This makes it very easy to search on FANUC. We just type,
we know we're using tool one so we type N1 down arrow on the FANUC controls and it will search
to this section of code. Very good tip there for finding and scanning around your code quickly.
So after our N number there we've got an operator's note in brackets. So in this case it's
what this sequence is about. So it's letting us know it's a rough turn sequence and at the end
of that we've got that semi-colon there which is the end of block sequence which we find after
every line of code. It tells the machine it's time to move on and read the next line. Okay so next on
our list here is G code. Well we all know what G code is. It's why we're here. It's the actual
programming language but it uses G codes and that's where it gets its name from. So not to
be confused some people call it G and M code. M code is also a function in G code but the language
is generally known as G code. Okay so what I've highlighted here is a safety line. I've got videos
that goes into this in more depth with practical machinists but just briefly the G54 there sets the
work shift datum. G53 is the machine datum. Then we control whether an absolute or incremental
metric or imperial. G97 controls the spindle speeds. Two different modes. We've got G80 to
make sure there's no cycles currently active and G40 to make sure there's no cut up compensation
active. So this always sets the machine up into a safe state. So if we start from the beginning
in a sequence it's like starting a program from scratch. Everything's going to run fine and I
always keep my sequences like this. So each sequence can be run individually without needing
to run the whole program each time. Great if you need to rerun a tool. Okay next up is M codes.
So there's less standard M codes than what there is G codes. The two in this example program
it stands out at the moment is coolant on and coolant off with MO8 and MO9. If you've got
flood coolant, mist coolant, different types of coolant you'll have different M codes for these
also. Generally MO8 turns them all on depending on the machine. We can also control our spindle
with M codes too. So these are all auxiliary functions. So we can turn the spindle on and off
and run it forwards and backwards with these M codes. So next up is our coolant. It's our XYZ
UVW. So we all know the XYZ is the positions we move around in the 3D environment. The UVW can
also be used. These are generally incremental moves certainly on lathes but they're auxiliary
axes moves. So they can be used for all sorts of things and it depends on the program and the
machine. But if you want to move in incremental a lot of times we can use U instead of X and that
saves us switching to incremental mode. But again depends on the machine and the style it's made in.
So you can see here there's some examples of my coordinates. Again this is a lathe program so
there's no Y it's just X and Z. And after the G01 we don't need to issue G01 again. It stays active
all the time until we change that G code function. So if we change to G00 for example we'd have to
reinstate the G01. That's a small example of where it would be used. Okay so next up we've got radial
coordinates. What's this? Well when we're coming in to turn a clockwise or anti-clockwise radius
we can use an R value to designate the size of that radius and that's what that is. Okay so we
also have center point coordinates I, J and K. Now these are used for the same sort of thing. What
these do is they designate the center point of that radius so we can do more complex radiuses.
We can do blends, we can do tangential blends that curve into each other and we can be a lot more
creative with the way we create arcs. So that's what I and J is used for. K is on the Z axis and
we tend to use this for more complex curves and radiuses. Okay so next up S spindle speed. So we
control our spindle speed by giving it an S value. It's as simple as that. By defining S1000 here
our spindle is going to start up in a clockwise direction because it's followed there by the MO3.
Now we have feed rate. So feed rate. After a G01 command we have to issue a feed rate so the
machine knows how far to move. It depends if we are working in millimeters per rev of the spindle
such as we tend to do on a lathe or whether it's meters per minute or inches per minute that we
would do on a miller machine. So if we issue a G01 command we have to issue a feed rate. We don't
need to keep issuing that feed rate that will stay active until we change that feed rate. Okay so now
we have tool. So this is our tool designation number T0101. Now again this is more suited to
lathes. On a mill you probably see T1 without the rest of the numbers. So it's still calling tool
one and it gets that information about the tool data elsewhere. On most lathes if we say T01
that's defining the tool. Then the second two digits there is the tool geometry. It's pulling
from the datum table in the machine to get that geometry so it knows how to apply cutter
compensation etc. So that's why we have two lots of numbers here. Now they don't always have to be
the same. We could have tool one with offset 25 and that will pull that data from the table using
the 25 position not the one position. But it's best to keep them both the same unless you're
using the same tool with two different offsets. And finally we've got cycle definitions I, K,
P, Q, R etc. So these change depending on the situation. Like U always doesn't mean the same
thing. It's not always an auxiliary axis. If you're using it in a roughened cycle for example
it means something totally different. And it also changes meanings twice in one line as it does here.
So there is no definite value for U, R, P, Q and W. They can change if we are using cycles and the
cycle reads them in a certain way. So be aware of that. Don't always assume R is the radius because
if it's used in a sequence or if it's used in a cycle it may not be. So if you want to know more
about g-code programming pop over to my website at gcodetutor.com where I have a range of paid
and free courses to teach you how to program g-code, computer aid design, machine shop maths.
In fact there's 12 courses there that cover all sorts of machine shop skills. So pop over
and have a look. And don't forget to follow me on instagram at gcodetutor.
