MechSimulator

CNC G-Code Simulator

G00 • G01 • G02 • G03 • Tool Path • M-Codes — Simulate • Explore • Practice • Quiz

Mode
Example Program
G-Code Editor Line: 0
Speed 5x
Current X
0.000 mm
Current Y
0.000 mm
Feed Rate
0 mm/min
Spindle
0 RPM
Program Line
0
Path Length
0.0 mm

Understanding CNC G-Code — Free Interactive Simulator

CNC G-code is the standard programming language used to control Computer Numerical Control (CNC) machines, including milling machines, lathes, routers, and plasma cutters. Every movement a CNC machine makes — from rapid repositioning to precise cutting arcs — is defined by G-code instructions. Our interactive simulator lets you write G-code in a built-in editor, instantly visualize the 2D tool path on a virtual workpiece, and animate the cutting sequence step by step. Understanding G-code is fundamental for anyone working in manufacturing, machining, or CNC programming.

G-Code Commands Explained

G-code programs consist of lines called blocks, each containing one or more commands. The most common motion commands are G00 (rapid positioning at maximum speed without cutting), G01 (linear interpolation at a controlled feed rate), G02 (clockwise circular arc), and G03 (counter-clockwise circular arc). Supporting commands include G90/G91 for absolute and incremental positioning, G20/G21 for inch/metric units, and G28 for returning to the machine home position. Feed rates are specified with the F word (e.g., F200 for 200 mm/min), and spindle speed with the S word (e.g., S3000 for 3000 RPM).

Circular Interpolation — Arc Programming

Arc commands (G02 and G03) require specifying the endpoint coordinates (X, Y) and the arc center offset (I, J) relative to the start point. For example, starting at position (0, 0), the command G02 X20 Y0 I10 J0 creates a clockwise semicircle to (20, 0) with the center at (10, 0) and a radius of 10 mm. The I value is the X-distance and J is the Y-distance from the current position to the arc center. This method is called the incremental center method and is the most widely used approach in CNC programming.

M-Codes and Program Structure

While G-codes control geometry and motion, M-codes (miscellaneous codes) control machine functions like spindle rotation (M03 clockwise, M04 counter-clockwise, M05 stop), coolant (M08 on, M09 off), program stop (M00), and program end (M30). A typical CNC program begins with a safety line (G90 G21 G17), followed by spindle start (M03 S3000), tool positioning, cutting operations, and ends with spindle stop and program end (M05 M30). Understanding this structure is essential for writing safe, efficient CNC programs.

Who Uses This Simulator?

This CNC G-code simulator is designed for CNC programming students learning to write their first programs, manufacturing engineering trainees practising tool path visualization, CNC operators verifying code before running on real machines, and instructors teaching G-code fundamentals in technical education. It provides a safe, visual environment to experiment with G-code without risk to expensive equipment or materials.

Explore Related Simulators

If you found this CNC G-code simulator helpful, explore our Milling Machine Simulator, Lathe Machine Simulator, Drilling Machine Simulator, and Tolerance & Fits Calculator for more hands-on manufacturing practice.