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.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Key takeaways
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.
- 1Drawing with datumsTolerances, surface finish, and which faces are reference.
- 2Stock size and allowanceEnough material for facing and for the first setup.
- 3Workholding planVise, soft jaws, fixture plate, or a second-op soft jaw set.
- 4Tool listWhat is actually in the crib, with stick-out lengths.
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.
- 1G54 for op 1, G55 for op 2Keep the same convention on every job in the shop.
- 2Z zero on the finished faceRe-touch after facing, not before.
- 3Rotary workPut part zero on the centerline, not on a corner.
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.
- 1Aluminum 6061350–450 m/min, 0.08–0.12 mm/tooth, 40% radial.
- 2Stainless 304/31680–120 m/min, 0.04–0.06 mm/tooth, light radial.
- 3Titanium Ti-6Al-4V40–60 m/min, high pressure coolant, rigid setup.
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.
- 1Same tool change orderReadable by any operator on any shift.
- 2Comment every featureOperation, tool, and the drawing dimension it serves.
- 3Subprograms for repeatsOne value at the top, whole family updates.
- 4One clearance plane5–10 mm above stock, used everywhere.
Step by step: from drawing to proven part
Follow this order. Skipping a step moves the cost to the machine.
- 11. 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.
- 22. 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.
- 33. 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.
- 44. 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.
- 55. 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.
- 66. 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.
- 77. 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.
- 88. 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.
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.
| Material | Surface speed | Feed per tooth | Notes |
|---|---|---|---|
| Aluminum 6061-T6 | 350–450 m/min | 0.08–0.12 mm | Runs dry or with air blast |
| Aluminum 7075 | 300–400 m/min | 0.08–0.10 mm | Sharper tool, more brittle chips |
| Stainless 304 / 316L | 80–120 m/min | 0.04–0.06 mm | Flood coolant, no dwell in corners |
| Steel 4140 | 120–180 m/min | 0.05–0.08 mm | Watch heat at the tool tip |
| Ti-6Al-4V | 40–60 m/min | 0.03–0.05 mm | High pressure coolant, rigid setup |
| PEEK / POM | 200–300 m/min | 0.05–0.10 mm | Sharp tool, avoid rubbing |
| Inconel | 25–40 m/min | 0.02–0.04 mm | Expect 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.
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