GreatLight CNC Machining Factory logo
CNC Machining
Rapid Prototyping
Materials
Industries
News
About GL

Get Instant Quote

CNC programming basics

How to Make a Program in CNC Machine

This guide walks through the full path from a 2D drawing to a proven G-code file: setup sheet, coordinate system, tool list, feeds and speeds, dry run and first-article check. Written for engineers and shop programmers who need a repeatable order of work, not a list of codes.

±0.005 mm tolerance16 five-axis centers3–5 day shipping12-hour quote
how to make program in cnc machine
Quick answer

Key takeaways

Program from the setup, not the geometryDecide how the part sits in the vise or fixture first. Every coordinate, tool and reach limit follows from that.
One datum, written on paperPick X0 Y0 Z0 and record it on the setup sheet. Operators set offsets to that sheet, not to a verbal description.
Feeds come from the tool and the materialChip load per tooth times teeth times RPM. Start conservative in aluminum 6061 and stainless 304.
Dry run before the tool touches metalSingle block, rapid override down, distance-to-go on screen. Two minutes here saves a crashed spindle.
First article decides the restMeasure the proved part against the drawing before running the full batch. Adjust wear offsets, then walk away.
Section 1

What you need before you write a single line of G-code

Programming starts on paper, not on the controller. You need three inputs: a drawing with tolerances and datums, a stock size with enough allowance, and a decision about how the part is held. If any of those is missing, the program you write will be rewritten at the machine, and that is the most expensive place to rewrite anything.

Read the drawing for the datum first. A part dimensioned from a bore is not the same as a part dimensioned from an outside face. The datum you choose becomes X0 Y0 Z0, and every other number in the program hangs off it. Most first-article arguments trace back to two people assuming two different datums.

Then fix the setup. A 100 × 80 × 30 mm aluminum block in a 150 mm vise behaves differently from the same block clamped on a fixture plate with toe clamps. Overhang matters. If the tool has to reach 60 mm below the jaw line, you have already limited your tool choices before you typed anything.

Materials set the tone. Aluminum 6061-T6 cuts fast and forgives small mistakes. Stainless 316 and Inconel do not. We machine 6061, 7075, 304, 316L, 17-4PH, Ti-6Al-4V and PEEK in the same shop, and the same geometry takes three different programs because the cutting data and the rigidity limits are not the same.

  • 1
    Drawing with datumsTolerances, surface finish, and which faces are reference.
  • 2
    Stock size and allowanceEnough material for facing and for the first setup.
  • 3
    Workholding planVise, soft jaws, fixture plate, or a second-op soft jaw set.
  • 4
    Tool listWhat is actually in the crib, with stick-out lengths.
Section 2

Choosing the coordinate system and work offsets in a program in CNC machine work

A work offset is a stored distance between machine home and your part zero. On a Fanuc-style control you have G54 through G59; on Siemens you name them. Use G54 for the first setup and G55 for the second op, and write both numbers on the setup sheet. Operators should never have to guess which offset the program expects.

Set Z zero on the top face of the finished part whenever possible. Touching off on the rough stock top means every depth in the program shifts when the face is cleaned up. If the top face is critical, cut it first in the same setup, then re-touch Z to the fresh face before running the profile.

For parts with rotation, define a second coordinate system rather than doing trigonometry in your head. A four-axis program with a rotary table at Ø400 mm is easier to trust when the part zero sits on the rotary centerline and the program uses G55 for the rotated face. This is also how we keep 12 four-axis mills and 16 simultaneous five-axis centers consistent across shifts.

Write the offset values into the setup sheet with the tool numbers. Tool 1 face mill, Tool 2 Ø12 mm 3-flute carbide, Tool 5 Ø6 mm ball nose for the blend radius. A program without a matching tool sheet is a program that will be stopped at the machine.

  • 1
    G54 for op 1, G55 for op 2Keep the same convention on every job in the shop.
  • 2
    Z zero on the finished faceRe-touch after facing, not before.
  • 3
    Rotary workPut part zero on the centerline, not on a corner.
Section 3

Speeds, feeds and depth of cut that survive the first run

Cutting data is not a preference. It comes from surface speed, tool diameter and chip load. For a Ø12 mm 3-flute carbide end mill in 6061-T6, a starting point is 350–450 m/min surface speed, 0.08–0.12 mm per tooth feed, and 6 mm axial depth with 40% radial engagement. That is a conservative cut that will not chatter in a standard vise.

In 304 or 316 stainless, drop surface speed to 80–120 m/min and keep the chip load around 0.04–0.06 mm per tooth. Stainless work-hardens, so a light rub is worse than a real cut. Keep the feed per tooth up and the radial engagement low, and never let the tool dwell in the corner.

Roughing strategy matters more than the finishing numbers. Trochoidal or dynamic paths keep radial engagement constant at 8–10% of the diameter and let you use the full flute length. On deep pockets this is the difference between a 40-minute cycle and a broken 3-flute cutter.

Finishing targets depend on what the drawing asks for. Ra 0.8–1.6 μm is a normal machined finish on aluminum and steel. Ra 0.2–0.8 μm usually needs a smaller stepover, a sharper tool, and sometimes a separate finishing pass at reduced feed. Do not chase the finish in the roughing operation.

  • 1
    Aluminum 6061350–450 m/min, 0.08–0.12 mm/tooth, 40% radial.
  • 2
    Stainless 304/31680–120 m/min, 0.04–0.06 mm/tooth, light radial.
  • 3
    Titanium Ti-6Al-4V40–60 m/min, high pressure coolant, rigid setup.
Section 4

Structure inside the program: blocks, subprograms and comments

A readable program has a fixed shape. Header with program number, tool, offset and safe Z. Then the tool change, spindle start, coolant on, and approach move. Then the cutting sequence. Then retract, spindle stop and end of program. Every tool change uses the same order of operations so an operator reading it cold can follow the logic.

Use comments. On Fanuc, put them in parentheses after the block; on Haas and Siemens the same idea with a different delimiter. Mark the operation, the tool, and any dimension that comes from the drawing. A line that says (Ø25.4 bore, H7, finish pass) tells the operator more than a bare G81 cycle ever will.

Subprograms pay off on repeated features. A bolt pattern, a series of identical pockets, or a family of parts with one changing dimension all belong in a subprogram called with M98. Change one value at the top and the whole family updates. This is how a shop runs 10,000+ part runs without maintaining ten separate files.

Finally, keep the safe Z consistent. Pick one clearance plane, usually 5–10 mm above the stock top, and use it after every retract. Mixed clearance heights are the quiet cause of most fixture crashes.

  • 1
    Same tool change orderReadable by any operator on any shift.
  • 2
    Comment every featureOperation, tool, and the drawing dimension it serves.
  • 3
    Subprograms for repeatsOne value at the top, whole family updates.
  • 4
    One clearance plane5–10 mm above stock, used everywhere.
Workflow

Step by step: from drawing to proven part

Follow this order. Skipping a step moves the cost to the machine.

  • 1
    1. Prepare the setup sheetList stock size, material, workholding, part zero, and every tool with its number, diameter and stick-out. One page. If it does not fit on one page, the job is not ready.
  • 2
    2. Build the CAD model for machiningWork from the finished drawing. Add stock allowance of 0.5–1.0 mm on faces to be finished. Remove features that no cutter can reach and flag them for the customer before programming starts.
  • 3
    3. Choose the coordinate systemPick the datum from the drawing and assign G54. For a second op, assign G55 and model the soft jaws in CAD so you can check for interference before the machine runs.
  • 4
    4. Create the CAM operations in orderFace, rough, semi-finish, finish, then drill or tap. Rough with a dynamic path at 8–10% radial engagement. Leave 0.3–0.5 mm on walls for the semi-finish pass.
  • 5
    5. Set feeds, speeds and depthsUse the material table, not memory. Aluminum 6061 at 350–450 m/min, stainless 304 at 80–120 m/min. Keep the chip load per tooth constant through the whole path.
  • 6
    6. Simulate and check the toolpathRun the CAM simulation with the actual holder geometry. Check for gouges, rapid moves through stock, and any place where the shank enters the cut. Fix it here, not at the machine.
  • 7
    7. Post and dry runPost to the controller, then run with single block, rapid override at 25%, and distance-to-go on screen. Confirm every tool change height and every approach move before switching to automatic.
  • 8
    8. Cut the first article and inspectMeasure the proved part against the drawing with the same instruments the customer will use. Adjust wear offsets, then release the batch. We inspect 100% of parts before shipment and supply reports on request.
Reference

Cutting data and setup reference by material

Starting points for a Ø12 mm 3-flute carbide end mill, 6 mm axial depth, 40% radial engagement.

MaterialSurface speedFeed per toothNotes
Aluminum 6061-T6350–450 m/min0.08–0.12 mmRuns dry or with air blast
Aluminum 7075300–400 m/min0.08–0.10 mmSharper tool, more brittle chips
Stainless 304 / 316L80–120 m/min0.04–0.06 mmFlood coolant, no dwell in corners
Steel 4140120–180 m/min0.05–0.08 mmWatch heat at the tool tip
Ti-6Al-4V40–60 m/min0.03–0.05 mmHigh pressure coolant, rigid setup
PEEK / POM200–300 m/min0.05–0.10 mmSharp tool, avoid rubbing
Inconel25–40 m/min0.02–0.04 mmExpect short tool life, plan spares

The order of work is the whole trick

Get the setup sheet, the datum and the tool list right before you type, and the G-code almost writes itself. Skip them, and every later step costs more.

FAQs

Common questions about writing a program in CNC machine work

Do I need CAM software, or can I write G-code by hand?

Hand-written G-code is fine for simple turning, drilling patterns, and one-off facing operations. It is fast and it forces you to understand the controller.

Anything with a curved surface, a deep pocket, or more than about 20 tools belongs in CAM. Five-axis toolpaths in particular are not practical to write by hand. The simulation alone justifies the software.

How do I decide the order of operations?

Face first so Z zero is real. Rough everything that removes the most material, then semi-finish, then finish. Drill and tap after the surfaces are stable so the hole positions do not shift.

Leave the most tolerance-critical feature for the last operation in the setup, when the part has the least internal stress and the machine is thermally settled.

What is the most common cause of a crash on a new program?

Wrong work offset or wrong tool length. Both are setup errors, not programming errors. The dry run with distance-to-go catches them.

Second most common: a rapid move at clearance height that is lower than the tallest feature on the part. Set one clearance plane and use it everywhere.

How do I hold ±0.005 mm on a machined part?

Rigidity first. Short tool stick-out, minimum overhang, sharp tool, and a machine that is not fighting chatter. Then control temperature: let the part settle before final measurement.

Finish passes should be light, 0.1–0.2 mm radial, at consistent feed. Use wear offsets to correct the proved part rather than rewriting the geometry.

When should the program be reused instead of rewritten?

When the part family shares geometry and only a few dimensions change. Put the changing values in variables or a subprogram and keep one master file.

Rewrite when the workholding changes. A program proved in a vise is not proved on a fixture plate, even if the part is identical.

Can you program and prove parts for us?

Yes. Send a drawing or a 3D model and we return a quotation with a free DFM analysis within 12 hours. Production can start within 24 hours, and parts ship in 3–5 days.

Uploads are secure and confidential. An NDA is available on request, and we work from one prototype up to 10,000+ part runs with no minimum order quantity.

Send a drawing, get a program-ready quote

Upload your model and we return a quotation with a free DFM analysis within 12 hours. 127 CNC machines, 16 simultaneous five-axis centers, and 100% inspection before shipment.

12-hour quote100% inspectionNo minimum order quantityNDA on request

Follow our shop

More machining notes from GreatLight

We publish setup notes, tooling trials and inspection data from the factory floor.

FacebookTikTokYouTubeLinkedInInstagramThreadsPinterest

Trusted by engineers and manufacturers worldwide

Tesla Ford Motor Company BYD Auto Denso Magna International Boeing Airbus Medtronic KUKA FANUC