An Introduction To CNC Machine Control

We recently gave you some tips on purchasing your first milling machine, but what we didn’t touch on was CNC (Computer Numerical Control) systems for milling machines (or other machines, like lathes). That’s because CNC is a complex topic, and it’s deserving of its own article. So, today we dive into what CNC is, how it works, and ultimately if it’s right for you as a hobbyist.

A Brief History of CNC

As a Hackaday reader, you’re no doubt a tech savvy individual who is already at least somewhat familiar with the concept of CNC. It is, after all, just the automation of machining at its core. As you might expect, the history of CNC systems pretty closely mirrors the development of computers, and the two are directly linked. The first fully automated control systems began to appear in the 1950s with NC (Numerical Control). These used punch tapes (or similar instruction storage techniques) to direct machines — mostly milling machines, routers, and lathes.

Power feed for these machines had already been around for sometime. These used (and still use) electric motors or mechanical links to feed a particular axis on the machine at a consistent rate. The benefits were two-fold: it was a lot less labor for the machinist, and the smooth and consistent feed improved surface finishes and tool life.

By the ’50s, high-end machines had more advanced power feed controls that could be set for different speeds. Numerical control essentially just automated that existing technology. Operators could tell the machine when and where to move each axis, thereby removing the most time-consuming part of machining (the precise turning of handles).

A magnetic tape controlled vertical profiler from 1962 (courtesy of
A magnetic tape controlled vertical profiler from 1962 (courtesy of

This technology progressed pretty predictably from there: digital computers gave rise to CNC, removing the need for antiquated punch tapes. CAD (Computer-Aided Design) came along and made the design process digital, giving operators the ability to design a part and program the machine all on a computer. Computers got exponentially smaller, more powerful, and cheaper. The machine’s electronics improved, allowing for more precise control and better feedback. And, recently, the open source movement in particular has made CNC controlled machines readily available for the hobbyist.

The Benefits of CNC

The most obvious benefit of CNC, particularly in manufacturing, is automation. If a manufacturer needs to make thousands of identical parts, the CAD and CAM (Computer-Aided Manufacturing) process only needs to be done once. Then, a single operator can simultaneously run a handful of machines, simply loading and unloading parts and pushing “start.” This efficiency has led to the ability to mass produce complex machined parts (something that was done manually for the first half of the 20th century) with impressively high accuracy.

Another key benefit of CNC is precision and repeatability. Precision has always been an important part of machining, but maintaining tight tolerances when manually operating a machine isn’t simple. It requires the machinist to have good math skills, to know the machine, and to have a strong attention to detail. If the machinist turns a handle a few degrees too far, a part might need to be scrapped because it fails to meet the tolerances required by the engineer.

quote-cnc-capable-of-movements-humans-cannotCNC machines, on the other hand, are very good at math. They know exactly where they’re supposed to be positioned, and can repeat their programming perfectly over and over again. Once a part program has been perfected by the CNC programmer, a manufacturer can rest assured that the parts are all going to come out identical to each other. As long as the machine is running properly and the tool is good, a single part program can be run indefinitely with perfect results.

Another benefit that is often overlooked, but extremely important in our modern world, is that CNC machines are capable of movements that humans cannot reproduce. Take a simple circular pocket as an example. It’s so trivial these days that we don’t even think about it — a CNC milling machine can cut it in many different ways using any tool that has a diameter smaller than the diameter of the pocket. But, in order to manually machine the same pocket, a machinist would either need a bore with the exact same diameter as the pocket, or a rotary table to rotate the part. And, the latter would require the rotary table’s axis to be exactly aligned with the axis of the circular pocket.

That’s because a circle requires two axes to be moved simultaneously and at varying speeds in relation to each other. A machinist simply cannot do that manually, at least not while maintaining any kind of realistic tolerances. Think of it like trying to draw a perfect circle on an Etch A Sketch, and now imagine you have to do that to tolerances of less than a thousandth of an inch. It just can’t be done manually, but it’s easy for a CNC mill to accomplish.

An example of a part that would have been impossible to machine without CNC (photo courtesy of HAAS)

That same concept gets taken even further when the shapes become more complex, and when you add in a third, fourth, fifth, or sixth axis. Many of the products we take for granted now simply weren’t possible to manufacture until CNC came along, because they couldn’t be manually machined.

A CNC mill doesn’t care if it’s just moving in a straight line in a single axis, or if it’s coordinating the movement of six axes simultaneously. Sure, the part program gets bigger, but with modern storage and processing, that’s no longer an issue.

Types of CNC Systems

The most basic types of CNC are two-axis or three-axis systems designed to retrofit manual machines. These come in varieties for both milling machines and lathes, and essentially just integrate a computer and power feed. The computer controls the power feed for each axis, and attempts to compensate for backlash in each axis. That compensation is handled in either a closed loop or open loop manner.

In an open loop CNC system, there is no feedback. Signals are only sent one way, and the computer has no idea if what the machine is actually doing is correct. It simply relies on the machine to do what it’s supposed to do. Backlash is compensated for by a fixed amount, and so it has to be known before hand. This is how most inexpensive machines work, and it generally produces good results. However, the lack of feedback means backlash usually isn’t dealt with perfectly, and so it can be difficult to keep tolerances tight.

Closed loop CNC systems use encoders to provide feedback to the computer. This means things like backlash can be automatically compensated for — the computer simply verifies that the axis is moving by the desired amount, and adjusts accordingly if it’s not. However, closed loop systems require additional hardware and more sophisticated control computers, and so they are more expensive.

The major alternative to retrofit systems, of course, are machines designed from the ground up to be controlled by CNC. This is how most modern machines are built, as they can integrate a lot of additional features that are desirable. These include tool changers, automated coolant systems, additional axes (for rotating the part, machining at angles, and reaching into cavities), advanced spindles, and more. With a purpose-built machine, this can also all be packaged nicely in an enclosure to contain coolant and chips.

A 5-axis CNC VMC (photo courtesy of Bridgeport)
A 5-axis CNC VMC (photo courtesy of Bridgeport)

Both retrofit and purpose-built machines usually have two methods of creating part programs: G-code and conversational. The G-code mode takes instructions created on a separate computer (either by CAM software or manually written), and runs it exactly as it’s written. Conversational modes do that all on the control computer, allowing the operator to create programs right at the machine.

The benefit of conversational modes is that an operator can quickly create simple programs without having to involve a CNC programmer using CAD/CAM software. The downside is that the programs are usually simplistic, and making complex parts gets very cumbersome. Conversational programs are almost always only 2.5D as well, meaning that the Z axis can’t be moved at the same time as the X or Y axes. Creating G-code from CAD/CAM software allows you to take a complex 3D model and create a part program for it directly, so there are virtually no limits to the complexity of the program. Most modern job shops will use a combination of the two methods depending on need, but hobbyists will probably be most comfortable designing parts in CAD and using CAM to produce G-code.

The CNC Workflow

Conversational controls vary quite a bit depending on the manufacturer and model, and most of you will probably be interested in designing parts in CAD anyway. So, we’re going to be focusing on the G-code method of running a CNC machine. The process is pretty analogous to 3D printing (which also uses G-code), with CAM software taking the place of 3D printing slicer software.

The workflow starts with creating a 3D model of your part in CAD software, paying close attention to keeping all of your dimensions exact. It’s best to use parametric CAD software designed for mechanical engineering, as opposed to free form 3D modeling tools like Blender. Once you’ve got your 3D model, you’ll need to process it in CAM to create toolpaths, and then output G-code. Most modern CAD systems have integrated CAM software, and there is also standalone CAM software available. However, this software is generally very expensive. Autodesk Fusion 360 is a good free (for hobbyists) option that has both CAD and professional quality CAM.

When you switch to CAM, you’ll first need to set up the part to tell the machine how the part will be oriented, how big the piece of stock is, and how the part will be positioned within that stock. If the part will need to be reoriented (to mill the bottom, for example), then you’ll need to create multiple setups for each operation. You’ll also need to set up a tool library, which defines what tools are available (end mills, drills, etc.), and what their dimensions are.

The next step is to start creating tool paths to cut out the features of your part. Unlike with 3D printing, where the model is simply sliced into layers, CNC tool paths have to be manually created. You’ll be given a bunch of different options for kinds of toolpaths, such as contours (for cutting out a 2D profile), facing, and a variety of 3D contouring techniques. It takes a lot of experience to figure out which kinds of toolpaths to use, but you’ll find yourself using a handful very frequently.

When you create the toolpath, you’ll be given a number of options and parameters to define. These are things like which tool to use, spindle speed, feed rates, depth of cut, stepover, and so on. Again, these take a lot of experience to get right, but there are a number of tools like HSM Advisor out there that can help you with these settings. Generally, you’ll be balancing time, quality, and tool life. For this reason, it’s very common to take quick and heavy roughing passes to remove a lot of material in a short time, and then light finishing passes to remove the last little bit of material precisely and with a good surface finish.

Creating the toolpaths is where you’ll most likely spend most of your time, and it’s important to get it right to avoid wasting material on bad part programs, breaking tools, or possibly even damaging your machine. For that reason, it’s always a good idea to run the built-in simulation to make sure it’s cutting in the expected way, and that there are no collisions. Pay particular attention to where your fixtures, vice, and table are going to be, and that the tool won’t collide with any of them.

Autodesk Fusion 360 offers professional-level CAM
Autodesk Fusion 360 offers professional-level CAM

Once you’re satisfied that your toolpaths are all correctly setup, you’ll need to run a post processor to create the G-code for your machine to run. G-code is fairly standardized, but most machines have their own way of interpreting the code. So, the post processor acts as an intermediary between the CAM software and the CNC, and makes sure the G-code that is output is compatible with your machine. Most CAM software will have a fairly substantial post processor library, and it’s likely your CNC is already in there. If not, searching online for your CAM and CNC will allow you to find a compatible post processor (or a generic one might even work).

With G-code in hand, you’ll need to load it into the memory on your CNC. This is highly dependent on the CNC system you’re using. Some will let you simply load it from a USB stick or over a network, while other older controls might require you to load it over a serial or parallel connection. But, once the G-code is in memory, most will give you a visualization of the toolpaths that you can check to make sure everything looks right.

Once your stock is loaded into the machine, it’s important that you precisely set the origin point in X, Y, and Z. This has to match what was in the setup in the CAM software. Usually you’ll use a corner of the stock, or a specific point on your vice/fixture. What matters is that it’s a tangible point that you can reference. With that all set, you get to push the big alluring “start” button and let the machine get to work.

Don’t be surprised if you break a tool, or your surface finish is bad. These are all things that have a learning curve, and good design is always an iterative process. With enough experience, you’ll begin to learn what settings work best, and how to produce high quality parts. So, relish the learning process, and enjoy the fact that you no longer have to spend hours turning handles!

40 thoughts on “An Introduction To CNC Machine Control

    1. As a new CNC enthusiast about to take the leap into getting a medium-sized CNC router/mill, I’m interested in hearing more about this and some pitfalls or underestimated aspects that make it so hard!

      Does an auto Z probe (like solve or help the tool offset aspect?

      As for part offset, I thought it was common to zero the machine at a corner of the stock and start jobs from there. What other considerations are there that make it one of the “hardest things to learn”?

      1. Z-probe definitely helps. You don’t have to buy one though, sufficient one can be made from e.g. a piece of PCB. I use a small magnet for attaching the other end on the tool in my machine.

        I’ll just list my most common failures:

        1. Workpiece accidentally moves. Vibration does funny things to nuts, and sometimes it is also difficult to estimate how much force the cutting tool will apply. Cutting fluid can also make things slip. Double-sided tape is actually a pretty nice way to mount planar stock, but it will fail instantly with cutting fluid. Annoying thing about workpiece moving is that it escalates very quickly: after it has moved a tiny bit, the cutting forces on next round are larger and it moves more, until eventually the force grows high enough to snap or stall the tool.

        2. Workpiece is not straight. Getting a piece straight simultaneously in X, Y and Z is hard enough. Not so much of a problem if you can cut everything in one go with one mounting, but if you want to add details to an already partially finished piece then it is a big problem. Applying clamps can also distort flimsier materials. Sometimes also cutting away the material changes stress distribution and makes things bend a bit.

        3. Mounting tabs/bridges fail. To keep a to-be-cut piece attached to the bulk of the material, one adds tiny bridges that will be removed manually. Of course you want to make them as tiny as possible.. but don’t make them too tiny, or your piece will get separated, wedge itself between the bit and the remaining material and either break the cutting tool or get marred itself.

        4. Forget to tighten the collet. I know, stupid mistake, but it happens. If you just put it finger tight, it will appear to work fine at first. But undetectably the bit will slowly drift downwards out of the collet, cutting too deep and possibly breaking off.

        This list omits the easy to detect problems such as wrong feed/speed/cutting depth, which will be quite quickly apparent as you start the job. You can just stop then and adjust until it seems to cut fine, so they are just minor annoyances.

  1. I want to suggest a low cost toolchain of sorts for home made CNC machines or retrofits. First, a beaglebone running Machinekit can be used as the machine controller. Its cost could be comparable to an old PC with a parallel port, but is by far less space consuming. It can be used with practically every motor controller that supports the step/direction interface.

    For the CAD/CAM side of things, Fusion360 is a good choice if using Windows and cloud software is not a problem. I disagree with Cameron in regard that mosf CAD software packages have integrated CAM functionality. Take Solidworks for example, it needs a third party plugin to take care of that.

    What I found most tedious when I started using CAM software was finding what the correct parameters for the tools were, as they vary a lot with the material being machined, the kind of operation one’s performing and the slight variations in geometry for different manufacturers of the same tool. Tuning the PID for closed loop motor controllers is also not fun at all :(

    And you should check this too (was featured on Hackaday a while ago)

  2. I recall once visiting a job shop where the machinists would simply carry the blueprints to the machinery and type in the G code. The systems didn’t have any sort of conversational mode programming – they just wrote the G code programs themselves, at the machine. Seemed a bit inefficient, but it worked for them.

    1. Been there, done that. 20 years ago a lot of molds were drawn in 2D with autocad, and CAM software was extremelly expensive for small shops.

      Also programed 5 axis machines with closed eyes. CAM software have evolved a lot.

    2. This is still somewhat practiced; though, the machinist will have a computer and compiler for exporting code to the machine, after interpreting the blueprints – still huge paper. I remember one place, where the guy was standing at the machine pendant typing in the code, we sold him a communication cable for his machine, as his arms were getting tired standing and typing

    3. Seen it done plenty of times (even had to do it myself occasionally), but it’s a horribly inefficient way of doing anything even remotely complicated. It’s also practically impossible for anything that you couldn’t just machine manually anyway…

    1. 3D hydraulic tracer mills could do complex curves automatically, and slowly. Bridgeport sold one back in the day that could get up to the blistering speed of 13 inches per minute. Those mills could have two or more heads to simultaneously cut from the same master. Typical on Bridgeport and other knee mills was three cutting heads and one tracer probe, mounted on a T-slotted crossbeam that itself was mounted where a standard single head would be.

      A big downside to them was all the hoses, a sometimes finicky tracer probe, and the huge hydraulic fluid tank and pump. 2D hydraulic tracers were used on lathes.

      Of course this is a very obsolete technology but there are still a few being used, likely because they’ve been paid for long ago and can still do any job their owners need to do. When they come up for auction, the only people who bid are scrap buyers, someone who has one just like it and needs parts, and crazy hobbyists thinking they can fix it and get it running – then find out they’ll need to have 440 volt 3 phase power installed to their garage.

      1. Oh, think I’ve seen those running back in the day, probably worn out ones, they were pretty big like a minibus sitting on it’s axles in their enclosure, and had a dam all round them with absorbent kitty litter type stuff, because they were hella leaky.

    2. yes and no.
      It is amazing how much they did and quite well before CNC. But it took a lot more time, often several steps by multiple people. It also was not as precise.

      The same can be said about what metal 3D printing is starting to do in select applications.

    3. If you just assume all the time that everything everybody says has an implicit caveat, “within the normal real-world constraints that people actually doing this face” then a lot of things suddenly become obviously correct instead of “bullshit.”

      It is pretty obvious that the statement would be true, because there are things that CNC is good at that were hard before, as described. The photo is probably not presented as scientific proof of the statement that could then be refuted, but rather just as an example that is illustrative of the type of thing that would be price-prohibitive before.

  3. For starters (and Windows-haters like me) I can recommend a simple but surprisingly powerful 2.5D workflow: Model design with freeCAD (can export outlines to .svg) or inkscape. The inkscape plugin gcodetools as CAM processor (Annoying at the beginning but after practice gives excellent results). CAMotics as simulation (saved me from a lot of stupid mistakes). Works great at least for hobby-grade machines.

  4. Before CNC, automation was done with interchangeable cams. I worked at an automated screw machine shop in my youth, where we had a couple dozen six-spindle lathes that had been built for the war effort. The six spindles were mounted in a rotating carriage, and all were driven from a common set of gears and spun at the same speed. Every cycle, a set of cam driven tools mounted on the end would plunge into the rotating stock. In the second station, we might have a centering bit, in the third a drill bit to penetrate halfway down the hole, the fourth might have another drill bit to finish the rest of the hole, and the fifth might have a tap or a broach. Each station also had cam driven accessories that fed in from the sides, and could put various shapes, grooves, etc. onto the part. The sixth station was always equipped with a cam-driven cutoff blade, severing the part from the bar stock where it dropped into the basket below. The first station was the feed station; the tool was a flat backstop so when the collet pushed out more barstock, it delivered the correct length.

    The cams were contoured to control the depth of cut. Steeper slopes meant faster travel. The drum these cams rode on was a large drum mounted at the top of the machine, and was probably 18″ in diameter. The cams were half inch thick plates of curved steel that bolted on; the rotation of the drum provided all the power to all of the tools simultaneously. Very big, very expensive. So the cams were never custom made; if you needed a 1″ throw at .005″ feed per revolution, that’s the cam you pulled off the shelf.

    Because all spindles rotated at the same speed, you had to slow the machine to the least common denominator. If the twist drills could only run at 300 RPM, you had to run all the spindles at 300 RPM even if your other tools could run at 1200 RPM.

    And the noise! Imagine a 10 foot long, 2″ tube with a 1″ hex bar rattling around in it at 600 RPM; multiply by six tubes per machine, by 24 machines. Even with ear plugs and ear muffs, some days the stock was so bad it was almost unbearable.

  5. “The most obvious benefit of CNC, particularly in manufacturing, is automation”

    Whilst automation is a great benefit, I think the original motivation was the machining of complex shapes, which could only previously be done with hard templates. Being able to control multiple axis simultaneously allows for a vastly increased speed of development, especially in the aerospace sector.

  6. I never thought about the fact that CNC is just automation of machining. You go on to say that the first fully automated control systems began to appear in the 1950s. I think it’s a good idea to choose a processing company that gets their metals from quality sources.

  7. I am not all familiar with the CNC machine, but I love how useful technology has really become! Back in my day, there was no way that we could build things like this and we had to do everything by hand. Now, because of the CNC machinery, we can do things we could not have dreamed of. Thanks for the post!

  8. CNC machines have proven to be revolutionary, and they are only making things rapidly.
    The CNC machines benefit numerous significant industries and will continue to do shortly.
    Who knows robot controlled CNCs could be the next big thing?

  9. Good guide on CNC machine control. It’s pretty tough to find good information on CNC machines online (perhaps it’s not “online-friendly”), but this is a great introduction. The company I work for is looking to transition over to CNC for much of their manufacturing, so this is helpful. In my research I’m come across a few other helpful resources such as this ( and it’s a great help in many respects, but it misses out on a lot of the things you cover here. It’s not my site, but I thought I’d share the link. Now onto the next phase… thanks for this!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.