NC Lathe Programming Basics: A Browser Simulator and Graded Exercises
Type it, run it, get it wrong, and learn. You can't break the machine here!


NC lathe programs use only a few codes, but the hard part is checking whether what you wrote is actually right. Trying it on a machine takes setup, and a mistake can break the tool or the machine. So for this article, we built an NC lathe simulator that runs in your browser. Type a program and press ▶: the tool moves, the material is cut, and you get spindle speed, cycle time, and warnings for collisions and missing decimal points. The second half has 5 graded exercises that automatically check whether your part matches the drawing. You can share your program as a link, so you can also use it to have a senior colleague check your work.
This article follows FANUC-compatible G-code system A , which is used on many machines. FANUC's manuals are not publicly available, so the FANUC-compatible format was checked against the public manuals of the Siemens ISO dialect[1] and Mitsubishi Electric[2], which document the FANUC-compatible format. Differences from Haas and others are noted as they come up. On a real machine, always follow that machine's manual and your shop's rules.
Try it first: NC lathe simulator
The drawing on top is a cross-section of the lathe seen from directly above (chuck on the left; the tool cuts from above the centerline, the +X side), and the black box below it is the NC program. The faint lines show the path the tool is about to take. Press ▶ Run. You can edit the program. Change numbers or make mistakes on purpose, and see what happens.
┅ Rapid G00━ Cutting feed━ Threading
- Gray dotted lines are rapid (G00), green lines are cutting feed (G01, G02, G03), and orange is threading. The black strip under the drawing (DRO) shows the current X, Z, spindle speed, tool and elapsed time, and the line being run
- Click a message to select that line in the editor. Your program is saved in this browser ("Reset to the original program" clears it)
- Press "Copy a link to this program" to make a link that contains the program you are writing. When someone opens it, the program runs automatically on their screen
- Machining classes at technical colleges (kosen) and elsewhere have reported teaching students to check the tool motion and the cutting process on screen in a simulation before moving on to the real machine[18][19][20]. A report from a vocational high school abroad found that students who used a simulator, where they could try again and again without fear of accidents, had more confidence and understanding before working on the real machine[23]
- On the other hand, in an experiment where beginners used VR for a 5-axis machine (a headset-based course that puts you inside the machine), it looked fun, but the controls distracted them and they scored lower on comprehension tests[24]. That is why this simulator is deliberately 2D cross-section only. It focuses only on how the program matches the tool motion
- This simulator is a simplified version for learning. The tool tip is a point (nose radius = 0), tool shapes are simplified, and holes (ID) are not handled. The rapid rate (12 m/min) and the maximum spindle speed (4000 min⁻¹) are also placeholder values
Coordinates: X is diameter, Z is length, the origin is the center of the face
A lathe has two axes. The Z axis runs along the spindle (along the length of the work), and the X axis is the radial direction at right angles to it. For both X and Z, the rule is: plus is the direction in which the tool moves away from the work (JIS B 6310 / ISO 841)[17][2]. In other words, +Z is to the right, away from the chuck, and +X is outward from the center.
- Write X as a diameter: drawing dimensions are given as diameters, so on a lathe X is normally commanded as a diameter (diameter programming)[1][2]. X30. means "the position at diameter 30 mm". Cutting 1 mm deeper reduces X by 2 mm
- The origin is at the center of the finished face (X0 is the spindle centerline, Z0 is the face); this is the usual practice[13][1]. So everything to the right of the face (where the tool waits) is Z plus, and the part being cut is Z minus
- The shift from the machine origin (machine coordinates) to the work origin is not written in the program; it is entered on the screens for tool offsets, the work coordinate system, and the like. So you can write the drawing dimensions in the program as they are
Program format: O numbers, blocks and words
An NC program is a series of lines (blocks), each made up of words (a letter plus a number). A block ends with EOB (shown on screen as ;), and the program starts with an O number. This format is defined in ISO 6983-1 (JIS B 6315-1)[17][2].
Most programs follow a standard start and end, with the cutting moves in between.
O0001 (program number) G28 U0 W0 (to machine zero; U and W are incremental, so it goes from where it is now) T0101 (call tool 1 with offset 1) G50 S3000 (max spindle speed 3000 min-1) G96 S150 M03 (start spindle at constant surface speed 150 m/min) G99 (feed in mm per revolution) G00 X44. Z2. M08 (rapid to near the work, coolant on) ... cutting moves ... G00 X100. Z100. M09 (retract, coolant off) G28 U0 W0 (to machine zero) M05 (spindle stop) M30 (end of program, back to the start)
| Code | Meaning | Notes |
|---|---|---|
| M03, M04, M05 | Spindle forward, reverse, stop | Choose according to how the tool is mounted (edge up or edge down). Check the machine's manual for which direction is forward[12][2] |
| M08, M09 | Coolant on, off | |
| M00, M01 | Program stop, optional stop | M01 stops only when the switch on the operator panel is on. Used for measuring or clearing chips |
| M30 | End of program | Returns to the start |
| T0101 | Tool selection | First 2 digits: tool (turret position); last 2 digits: offset number[1][2] |
| G28 U0 W0 | Return to machine zero | Goes to machine zero with "where it is now" as the intermediate point. Writing G28 X0 Z0 makes it try to pass through the work origin, which is dangerous[22][5][2] |
Text inside ( ) is a comment, and the NC skips it. Some controls cannot display Japanese or other non-ASCII characters, so it is safest to write comments in plain letters and numbers. This simulator also skips anything inside ( ).
Spindle: G50, G96, G97 and spindle speed
The relationship between cutting speed Vc (m/min), diameter D (mm) and spindle speed n (min⁻¹) is n = 1000 × Vc ÷ (π × D) .[16] On a lathe, there are two ways to program it, depending on whether you leave this relationship to the NC.
| Code | Meaning of S | Used for |
|---|---|---|
| G96 S150 | Keeps the surface speed (cutting speed) at 150 m/min. The smaller the diameter, the higher the spindle speed | Cuts where the diameter changes: OD, face, taper, etc. |
| G97 S800 | Constant spindle speed of 800 min⁻¹ | Threading, drilling, center drilling and other cuts at the center, or when you don't want the speed to change[10][1] |
| G50 S3000 | Max spindle speed 3000 min⁻¹ (system A) | Always before G96. In systems B and C, it is G92 S |
When facing with G96, the spindle speeds up as the tool approaches the center, and in theory the speed becomes infinite at the center. In practice it rises to the machine's maximum speed, centrifugal force reduces the chuck's grip, and the work may fly out. That is why you set the upper limit with G50 S before G96[8][9][13][22]. Use the sliders below to see how the spindle speed rises as the diameter gets smaller.
Motion: G00, G01, G02, G03
| Code | Action | Code | Caution |
|---|---|---|---|
| G00 | Rapid (positioning) | G00 X_ Z_ | Never cut with it. When X and Z move together, each axis moves at its own rapid rate, so the path is not necessarily straight[1] |
| G01 | Cuts in a straight line | G01 X_ Z_ F_ | X and Z on the same line give a diagonal (chamfer, taper) |
| G02 | Cuts an arc (clockwise) | G02 X_ Z_ R_ | End point and radius R (use a negative R for arcs over 180°). To specify the center, use I and K (incremental from the start point to the center; I is a radius value even on diameter-programming machines)[1][2] |
| G03 | Cuts an arc (counterclockwise) | G03 X_ Z_ R_ | Same as above |
G02 and G03: which way is which
On a lathe, the arc direction is defined by looking at the working plane (ZX plane, G18) from the plus side of the Y axis and seeing whether the arc turns clockwise or counterclockwise[2][1][3]. The figures and simulator in this article show a machine with the turret beyond the centerline (at the back), viewed from above (+X up), so clockwise as you see it is G02 . When cutting the OD from the face side toward the chuck, a bulging corner (convex R) is G03 and a hollow corner (concave R) is G02.
On a front-turret machine, the direction looks reversedIf you look from above at a lathe with the turret on the operator's side (+X toward you), the view is flipped upside down, so the same G02 looks counterclockwise. The program is the same; only the view changes. Mitsubishi Electric's manual writes the same shape as the same G02 in figures for both rear and front turrets, and the LinuxCNC manual also warns that G2 and G3 look reversed when viewed from above[2][15]. Check the orientation of your textbook or drawing, and of your own machine, before reading.
Forget the decimal point and the value becomes 1/1000
Many FANUC-compatible NCs read a number without a decimal point in the least input increment (0.001 mm). X30 is not 30 mm but 0.03 mm .[1][2] It is a typical cause of accidents: the tool plunges toward the center. If you type X30 in the simulator, a warning appears and the tool really moves to 0.03 mm. Check "Read numbers without a decimal point as mm (calculator type)" and it behaves like a machine set to calculator-style decimal input.
Absolute X, Z and incremental U, W
In system A, X and Z are positions from the origin (absolute), while U and W are distances from the current position (incremental). U is a diameter value like X, so U-2. means "2 mm inward on diameter (1 mm on radius)". The U0 W0 in G28 U0 W0 means "without moving from where it is now", and the tool returns to the origin with that as the intermediate point[1][2]. Note that, unlike on a machining center, you do not switch with G90 and G91 (on a system A lathe, G90 is the OD canned cycle).
Feed: F and surface finish
Lathe feed is normally written in mm per revolution (feed per revolution). In system A, G99 is feed per revolution and G98 is feed per minute.[2][11] Which one is active at power-on depends on the machine settings, so writing G99 at the start makes sure. In systems B and C the same functions are G95 and G94, and G98 and G99 mean something else: the return level of drilling cycles[2][1]. With F0.2, the tool advances 0.2 mm per spindle revolution. When G96 raises the spindle speed as the diameter gets smaller, the feed rate per minute also rises (the simulator's cycle time takes this into account too).
A larger feed cuts faster but leaves a rougher surface. With nose radius r and feed f, the theoretical height of the surface profile is h ≒ f² ÷ (8r) . For example, with f = 0.2 mm/rev and r = 0.8 mm, it is about 6.3 µm[16].
| Feed f (mm/rev) | Nose R 0.4 | Nose R 0.8 | Nose R 1.2 |
|---|---|---|---|
| F0.1 | 3.1 µm | 1.6 µm | 1.0 µm |
| F0.15 | 7.0 µm | 3.5 µm | 2.3 µm |
| F0.2 | 12.5 µm | 6.3 µm | 4.2 µm |
| F0.25 | 19.5 µm | 9.8 µm | 6.5 µm |
| F0.3 | 28.1 µm | 14.1 µm | 9.4 µm |
These are theoretical values. Actual roughness varies with tool wear, built-up edge, chatter and the material. The basic rule: a large feed for roughing, a small feed for finishing.
Tools and offsets: T0101 and tool nose radius compensation
T0101 has the offset number in its last 2 digits, and that offset applies the stored tool length offsets (X and Z geometry offsets) and wear offsets. Because of the offsets, the program needs only the drawing dimensions, not the tool lengths[1][2].
Another important feature is tool nose radius compensation. The insert tip is rounded (nose radius), but the NC moves the point where the X and Z edge lines intersect (the imaginary tool tip). There is no problem when cutting parallel to X or Z, but on tapers and arcs, the point where the rounded tip touches shifts away from the imaginary tool tip, and the dimensions come out wrong[1][7].
With taper angle θ (measured from the Z axis) and nose radius r, cutting without compensation leaves stock of thickness r(sin θ + cos θ − 1) normal to the surface, or r(1 + tan θ − 1/cos θ) in the X direction (radius) (formulas derived from geometry; they agree with the compensation table in the Haas manual)[14].
| Nose R | Taper 30° | Taper 45° | Taper 60° |
|---|---|---|---|
| R0.4 | φ0.34 mm oversize | φ0.47 mm oversize | φ0.59 mm oversize |
| R0.8 | φ0.68 mm oversize | φ0.94 mm oversize | φ1.17 mm oversize |
| R1.2 | φ1.01 mm oversize | φ1.41 mm oversize | φ1.76 mm oversize |
- When cutting the OD toward the chuck, use G42 (offset to the right of the tool's direction of travel); for ID, use G41 (left), and G40 cancels the compensation[1][2][7]
- For compensation, enter on the offset screen the nose radius and the imaginary tool tip number (0–9), which tells which way the tip faces. In a drawing with +X up and +Z to the right, a standard OD turning tool is 3 (the same number in Siemens, Mitsubishi Electric and Haas). If the number is wrong, the dimensions get even worse[1][2][14]
- At the start of compensation (the block with G41 or G42) and at the end (G40), the tool moves diagonally by the amount of the offset, so start it away from the work and cancel it away from the work, too
Grooves and threads: G04, G32, G92
Grooving is basically done by feeding a grooving tool in the X direction with G01 and, at the bottom of the groove, adding G04 (dwell: wait in place) so the tool sweeps the bottom for at least one revolution before retracting. G04 X0.5 , G04 U0.5 give 0.5 seconds, and G04 P500 gives 500 milliseconds (P takes no decimal point)[1][2][4]. Choose the dwell time from the spindle speed. For example, for 2 revolutions at 500 min⁻¹, 60 ÷ 500 × 2 = 0.24 seconds.
Threading requires the spindle rotation and the Z feed to match exactly, so keep the spindle speed constant with G97, and write the lead (the distance advanced in one revolution; the pitch for a single-start thread) in F. G32 is just one threading pass; G92 is a single canned cycle that combines 4 motions (infeed → thread → retract → return), and if you list lines with only X below it, it repeats while cutting a little deeper each time[1][2][6]. Threading starts the feed in sync with the spindle's once-per-revolution signal, so the tool enters the same groove however many passes you make.
- At the start and end of a thread, the lead is not correct because of the delay while the feed catches up with or stops with the spindle (incomplete thread), so when programming, add run-up and run-out distances to the required thread length[1][2]. The required distances depend on spindle speed, lead and machine, so check them with the formula in your machine's manual (Exercise 5 starts 5 mm before the face)
- A relief groove at the end of the thread lets the tool exit safely (Exercise 5)
- To let the NC calculate the number and depth of passes, use G76 (Lathe Multiple Repetitive Cycles)
Exercises: can you cut to the drawing? (graded)
The blue dotted line is the drawing shape. Write the missing moves in the "(---- ... ----)" line of the program and press ▶; the cut shape is compared with the drawing and graded (±0.02 mm on diameter). If there are warnings or errors, the result is also "Not yet". A sample answer is below each exercise.
Exercise 1Face the end
The stock is φ40, with a 1 mm allowance on the face. The tool (OD turning tool T0101) is already at X44. Z0. From here, feed to the center to finish the face at Z0.
Hint
One G01 line that moves only X. Feed about F0.15.
┅ Rapid G00━ Cutting feed━ Threading┅ Drawing line
Show a sample answer
O0001 G28 U0 W0 T0101 G50 S3000 G96 S150 M03 G99 G00 X44. Z0. M08 G01 X0. F0.15 G00 Z2. G00 X100. Z100. M09 G28 U0 W0 M05 M30
Exercise 2Turn a step in 2 passes
Turn φ40 stock down to φ30 for a length of 25 mm from the face. This tool can cut up to 2.5 mm deep on radius. The first pass (X35.) is already written, so finish to X30. with the second pass.
Hint
Same form as the first pass, with only X changed to 30. Don't forget to retract to X42. at the end.
┅ Rapid G00━ Cutting feed━ Threading┅ Drawing line
Show a sample answer
O0001 G28 U0 W0 T0101 G50 S3000 G96 S150 M03 G99 G00 X42. Z2. M08 X35. G01 Z-25. F0.2 X42. G00 Z2. X30. G01 Z-25. X42. G00 Z2. G00 X100. Z100. M09 G28 U0 W0 M05 M30
Exercise 3Chamfer C1 and taper
The stock is φ30. Chamfer the corner of the face at C1 (1 mm × 45°), turn φ26 to Z-15, and from there cut a taper that reaches φ30 at Z-25.
Hint
For both the chamfer and the taper, writing X and Z on the same line moves the tool diagonally (G01 X26. Z-1.).
┅ Rapid G00━ Cutting feed━ Threading┅ Drawing line
Show a sample answer
O0001 G28 U0 W0 T0101 G50 S3000 G96 S150 M03 G99 G00 X24. Z2. M08 G01 Z0. F0.15 X26. Z-1. Z-15. X30. Z-25. X32. G00 Z2. G00 X100. Z100. M09 G28 U0 W0 M05 M30
Exercise 4Convex R and concave R
The stock is φ24. Round the tip corner with R3 (φ14 → φ20), turn φ20 to Z-18, and round the root with R2 to blend into φ24.
Hint
Rounding the tip (convex R) is G03; rounding the root (concave R) is G02. For both, write the end point X, Z and R.
┅ Rapid G00━ Cutting feed━ Threading┅ Drawing line
Show a sample answer
O0001 G28 U0 W0 T0101 G50 S3000 G96 S150 M03 G99 G00 X14. Z2. M08 G01 Z0. F0.12 G03 X20. Z-3. R3. G01 Z-18. G02 X24. Z-20. R2. G01 X26. G00 Z2. G00 X100. Z100. M09 G28 U0 W0 M05 M30
Exercise 5Relief groove and M20×1.5 thread
The stock is φ20 (already turned to the thread's major diameter). With grooving tool T0202 (3 mm wide, referenced to its left corner on the chuck side), cut a φ17 relief groove from Z-20 to Z-23, then cut an M20×1.5 external thread with threading tool T0303 using G92. The final X is 18.16 (= 20 − 2 × 0.6134 × 1.5).
Hint
Cut the groove with G01 X17. and pause briefly with G04. For the thread, listing lines with only X below G92 repeats the same cycle a little deeper each time.
┅ Rapid G00━ Cutting feed━ Threading┅ Drawing line
Show a sample answer
O0005 G28 U0 W0 T0202 (GROOVE W3) G97 S600 M03 G00 X22. Z-23. M08 G01 X17. F0.05 G04 X0.5 G00 X22. G28 U0 W0 T0303 (THREAD 60DEG) G97 S800 M03 G00 X22. Z5. G92 X19.4 Z-21.5 F1.5 X18.9 X18.5 X18.3 X18.16 G00 X100. Z100. M09 G28 U0 W0 M05 M30
Common mistakes (the simulator warns you too)
- Forgetting the decimal point:
X30is 0.03 mm. The tool plunges toward the center[1][2] - G96 without G50: when facing, the spindle speeds up to the machine's maximum as the tool nears the center[8][9]
- Entering the material still in G00: you forgot to switch to G01. Hitting the work at rapid damages the tool and the machine
- Changing tools near the work: when the turret indexes, a neighboring tool hits the work. Do it at G28 U0 W0 or at a position well away
- Forgetting M03, or no S: the tool hits a work that is not turning
- Threading still in G96: when the spindle speed changes, the point where the tool enters on each pass (the thread phase) shifts. Use G97 for threading[1][2]
- Mixing up G02 and G03: remember that convex R and concave R differ, and that the view depends on the turret position (rear or front)
- Too deep a single cut: going beyond the tool's recommended depth of cut causes chipping or chatter. Split it into several passes
- Finishing tapers or radii without tool nose radius compensation: the dimensions come out wrong (see the figure above)
FAQ
- Does this simulator move exactly like a real machine?
- No, it is a simplified version for learning. It reads the basic codes of FANUC-compatible system A (G00–G03, G04, G28, G32, G50, G90, G92, G94, G96–G99 and the main M codes), but does not account for the nose radius, tool shape, machine acceleration and deceleration, or parameter settings. It does not run multiple repetitive cycles such as G71, custom macros or ID work.
- What is the difference between G50 and G92?
- The numbers differ by G-code system. In system A, G50 S (spindle speed limit) and G50 X Z (coordinate system setting) correspond to G92 in systems B and C. In system A, G92 is the threading cycle, so take care when reusing a program from a machine that uses a different system[1].
- Why feed X into negative values?
- When facing to the center, stock equal to the nose radius is left at the center, so in practice you may feed past the center to an X of about twice the nose radius (e.g. X-1.6). How far past is allowed depends on the tool and the machine.
- Can I use this to study for Japan's national trade skill test (NC lathe operation)?
- It works for practicing and checking the basics of programming by hand. Check the exam tasks and past questions on the public pages of JAVADA[25][26] (the questions on the public site are for viewing only; copying and secondary use are prohibited).
As a next step, we cover leaving roughing to the NC in Lathe Multiple Repetitive Cycles (G71, G70, G76), using variables and calculations in Custom Macro Basics, the meaning of each code in the G and M code dictionary, and spindle speed and feed calculations in the turning cutting conditions calculator. For an introductory article in an academic journal, there is also "Creating Your First NC Program" (2026) in the Journal of the Japan Society for Precision Engineering[21].
Sources
- Siemens: SINUMERIK ISO Dialects Turning Programming Manual (ISO dialect, 2007)
- Mitsubishi Electric: 700/70 Series Programming Manual (Lathe System), IB-1500057
- Haas Automation: G02 CW / G03 CCW Circular Interpolation Motion (lathe)
- Haas Automation: G04 Dwell (lathe)
- Haas Automation: G28 Return to Machine Zero Point (lathe)
- Haas Automation: G32 Thread Cutting (lathe)
- Haas Automation: G41 / G42 Tool Nose Compensation (lathe)
- Haas Automation: G50 Spindle Speed Limit (lathe)
- Haas Automation: G96 Constant Surface Speed ON (lathe)
- Haas Automation: G97 Constant Surface Speed OFF (lathe)
- Haas Automation: G99 Feed Per Revolution (lathe)
- Haas Automation: M03 / M04 / M05 Spindle On Fwd / Rev / Stop (lathe)
- Haas Automation: Lathe Programming Workbook (PDF)
- Haas Automation: Lathe Operator’s Manual (NGC, 2018), 5.7 Tool Nose Compensation
- LinuxCNC: Lathe User Information (tool orientation, lathe arcs)
- Tool maker's technical data (turning surface roughness, cutting speed formula)
- Japanese Standards Association: JIS Handbook 2023 Machine Tools, table of contents (JIS B 6310:2003 = ISO 841:2001 IDT, JIS B 6315-1:2013 = ISO 6983-1:2009 MOD)
- Okamoto, Yaguchi, Asami: “Multi-Axis Machining Education Using Machining Simulation,” Gunma Kosen Review 37 (2018) (in Japanese)
- Kanamata, Asahina: “Machining Education Using Machine Simulation at Tokyo Metropolitan College of Technology,” Proceedings of the JSME Technology and Society Division Conference (2005) (in Japanese)
- Imai, Shintani: “Development and Practice of an NC Machine Tool Designed for Safety in Hands-On Education,” Journal of the Japanese Society for Engineering Education 63(3) (2015) (in Japanese)
- Nishida: “Creating Your First NC Program,” Journal of the Japan Society for Precision Engineering 92(3) (2026) (in Japanese)
- Ministry of Health, Labour and Welfare: NC Lathe Operation (commentary on trade skill test tasks, Monozukuri Meister program) (in Japanese)
- “A Case Study of using Swansoft CNC Simulator Software in Vocational Education,” Atlantis Press (a case at a vocational high school)
- “The Cognitive Cost of Immersion: Experimental Evidence from VR-Based Technical Training,” Applied Sciences 15(23) (2025)
- JAVADA: Trade Skill Tests: Job Content (Machining, NC lathe operation) (in Japanese)
- JAVADA: Trade Skill Test Question Public Site (in Japanese)
More articles
Machining for the Semiconductor Industry: Types of Machining, Large to Small Parts, Major Japanese Companies, Machine Tools and Cutting Tools, New Technologies, How to Enter
GearsTwo New Fixes for Gear Skiving's Weak Points: Nachi-Fujikoshi's Air Skiving and Liebherr's SkiveFinishing, Illustrated
Gears