Quick answer
Paste or open a G-code file and the viewer draws the toolpath in 3D in your browser, with rapids in red and feed moves in blue, a cycle time estimate and a list of things to check. It reads G0 to G3 (arcs with I, J, K or R, and helical arcs), G17 to G19, G20/G21, G90/G91, G94/G95, G41/G42 cutter compensation and the canned cycles G73, G74, G76 and G81 to G89. Nothing is uploaded.
Table of common values
Common G-codes the viewer understands
| Code | Meaning |
|---|---|
| G0 | Rapid move |
| G1 | Straight feed move |
| G2 / G3 | Clockwise / counter-clockwise arc |
| G17 / G18 / G19 | XY / ZX / YZ plane |
| G20 / G21 | Inch / millimetre units |
| G40 / G41 / G42 | Cutter compensation off / left / right |
| G80 | Cancel canned cycle |
| G81 | Drilling cycle |
| G83 | Peck drilling cycle |
| G84 | Tapping cycle |
| G90 / G91 | Absolute / incremental positioning |
| G94 / G95 | Feed per minute / per revolution |
| G98 / G99 | Return to initial plane / R plane |
Source: Fanuc-style G-code conventions. Reviewed . Use the calculator below for any other size.
G-Code Viewer & Simulator
Paste or upload a program to simulate the toolpath in 3D. Use the controls at the bottom of the view: Play to watch the tool move, Step to go through it one line at a time (or press Space and the arrow keys), and drag the timeline to jump. The side panel has the program in the G-code tab and the cycle time, size, tools and checks in the Status tab. Arcs (I/J/K and R, G17/G18/G19), canned cycles, tool changes and G41/G42 cutter compensation are supported, and the Cut sim tab shows the stock being cut. Your code never leaves your browser.
How the G-Code Viewer Works
The viewer reads your program one block at a time and keeps track of the modal state the way a Fanuc-style control does. Each move becomes straight 3D line segments: rapids in red, feed moves in blue and canned-cycle feeds in green, or one colour per tool if you choose Colour by tool. Every move is also timed, so you get a cycle time estimate, the size of the toolpath and a list of things worth checking.
Most G-code words are modal: G90 or G91, the motion mode (G0, G1, G2, G3), the plane (G17, G18, G19), G98 or G99, the feed rate and an active canned cycle stay in force until something replaces them. The viewer remembers these, so a line that only says X20. is read as another move, or another hole, in whatever mode is active. Words can be written with or without spaces, so G1X10.Y5.F200 reads the same as G1 X10. Y5. F200. Text in brackets and anything after a ; is a comment, and a / at the start of a line (block delete) is ignored. The tool starts at X0 Y0 Z0.
G20 sets inches and G21 millimetres; with neither, the program is treated as millimetres. The grid and tool marker resize to fit the part, and the legend shows the grid square size.
What This G-Code Simulator Supports
- Moves: G0 rapid, G1 feed, G2/G3 arcs with I, J, K or R, full circles and helical arcs
- Planes: G17 (XY), G18 (ZX) and G19 (YZ)
- Units and modes: G20/G21, G90/G91, G94/G95 (feed per minute or per revolution)
- Cutter compensation: G41, G42 and G40 in the G17 plane, using the tool radius you enter for the D numbers
- Canned cycles: G73, G74, G76, G81 to G89 and G80, with G98/G99 and L or K repeats
- Dwell: G4 with P or X, added to the cycle time
- Tools and spindle: T with M6, M3/M4/M5 (cutting with the spindle off is flagged)
- Return: G28 and G53 Z0, shown as Z going up to a clear height
- Program end: M30 and M2, plus comments in brackets or after ;
- Not followed: M98 sub-programs, macro variables and logic, G52, G68 rotation and work offset values (all flagged under Checks in the Status tab)
Cutter Compensation (G41 and G42)
With cutter compensation the program follows the part outline and the control moves the tool centre one radius to the side: G41 to the left of the direction of travel, G42 to the right, and G40 cancels it. The tool radius lives in the machine's D offsets, not in the program, so type it into Cutter compensation tool radius: one number for every D, or a list such as D1=5 D2=3. The solid path then shows the tool centre and a dashed grey line shows the programmed outline, and playback, cycle time and size all follow the tool centre. Leave the box empty and the programmed line is drawn, as before. Click Cutter comp example to see a G41 climb-milled profile and bore with a 10 mm end mill.
The block that turns compensation on ramps the tool on to the offset, and the first move after G40 ramps it off. Inside corners are trimmed where the two offset moves meet; outside corners are drawn as an arc of the tool radius around the corner. Fanuc-style controls usually join outside corners with straight lines instead, which moves the tool centre a little differently but leaves the same sharp corner on the part. Under Checks in the Status tab, the viewer warns when an inside arc is smaller than the tool radius, when the tool does not fit an inside corner, and when compensation is still on at a canned cycle, G28, a tool change or the end of the program. For the rules behind it, see the cutter compensation guide.
Cut Simulation (Stock Removal)
Tick Cut sim over the 3D view, or open the Cut sim tab of the side panel, to see a block of stock being cut as the program plays. The stock is a grid of columns, each holding the height of the material at that point (a height field, up to about 300,000 columns, or 150,000 on a phone). Every move lowers the columns under the cutter to the shape of the cutter's end: level moves are swept exactly, and moves that change Z are stamped every half column. The stock is coloured by the tool that cut it last and follows the playback timeline, so dragging the timeline, Step and clicking a line all show the stock at that point. It runs in a background worker using a WebAssembly module written in Rust, so the page doesn't freeze, and it shows how much material has been removed.
- Stock: From the toolpath uses the X and Y range of the cutting moves (plus the margin you enter), the top at Z0 when the program cuts below Z0, and the bottom 1 mm (0.04 in) under the deepest cut. Choose Enter it to type your real stock, which is what makes the below-the-bottom check meaningful.
- Tools: the table is filled from the T numbers and the comments, for example (T2 10MM END MILL), (T1 D=6. CR=1.) or (T3 6.8MM DRILL). Set each tool's type (flat, ball, bull nose with its corner radius, V or drill point with its included angle, tapered ball) and diameter. Tools marked with a question mark were guessed.
- Checks: rapid (G0) moves that cut material, straight plunges with a flat end mill deeper than the limit you set (one diameter by default), and cuts below the stock bottom. Click one to jump to its line.
- Limits: it is a 3-axis height field, so it cannot show undercuts, a T-slot cutter's or dovetail's undercut, or 4th and 5th axis work, and lathe programs are not simulated (Cut sim says so). It does not model holders, clamps or chip load.
Programs from the STL to G-Code Relief Carving tool open here with their stock and tools already filled in.
The Method
Playback runs in real machine time multiplied by the speed setting (1× to 1000×), from the controls along the bottom of the 3D view. The timeline lets you jump to any point, Step runs to the end of the current program line for single-block checks, step back returns to the start of the line, and clicking a line in the G-code tab moves the tool to that line. On a keyboard, Space plays and pauses and the left and right arrow keys step.
Worked Examples
- G0 Z10., then G98 G83 X10. Y10. Z-5. R2. Q1.5 F150. and X20.
- Pecks feed to Z0.5, −1, −2.5, −4 and −5, retracting to R2 between pecks
- Each re-approach rapids to 0.1 above the last depth, so each feed after the first is 1.6 mm and the last is 1.1 mm
- Feed per hole = 1.5 + 3 × 1.6 + 1.1 = 7.4 mm, at F150 = 2.96 s
- Two holes: 14.8 mm of feed (5.92 s) plus 0.56 s of rapids at 15,000 mm/min = 6.5 s, ending back at the initial Z10
- G0 X20 Y0, then G2 X0 Y-20 I-20 J0 F200
- Centre = (20 − 20, 0 + 0) = (0, 0), radius 20
- G2 X0 Y-20 R20 gives the same centre: d = 28.28, h = √(400 − 200) = 14.14 from the chord midpoint (10, −10)
- Arc length = π × 20 ÷ 2 = 31.42 mm, at F200 = 9.42 s
- It runs clockwise from (20, 0) through the fourth quadrant to (0, −20), drawn as 36 short chords
Paste either program and read the cycle time in the Status tab of the side panel. Click Load example for a full part with three tools.
Tips for Using the Results
- Treat the cycle time as a minimum. Moves are timed at the programmed F and the rapid rate you enter, without acceleration, tool changes or spindle start-up. Real run times are usually somewhat longer, more so on short moves and 3D surfacing.
- Check the size and deepest Z. The Time & size section of the Status tab lists the X, Y and Z range of the cutting moves. Compare it with your stock and the deepest Z with your stock thickness and tool length.
- Turn on the cut simulation for new programs. Enter your real stock size and check the tool sizes: a rapid that cuts material or a cut below the stock bottom usually means a wrong Z0, a wrong tool length or a missing retract.
- Read the checks. The Checks list in the Status tab flags rapids below Z0, cutting with no feed rate or with the spindle off, arcs that don't meet the circle, R arcs too small to reach, G28 in G90, and code the viewer can't follow. Click a check to jump to its line.
- Some things are not simulated. Sub-program calls (M98), macro variables and logic (#, IF, WHILE), G52 shifts and work offset changes are not applied, and cutter compensation (G41/G42) is only applied when you enter the tool radius. G28 is shown as Z going up to a clear height; the X/Y move to machine home is not drawn because its position in part coordinates is unknown. Check sub-programs separately, for example output from the Sub-routine Generator.
- Check helical paths. Paths from the Thread Milling Generator show up as helices, which makes it easy to check the start depth, direction and number of turns.
- Share a program. Copy link packs the program into the link itself (nothing is stored on a server), so it works for programs up to a few hundred lines.
Frequently Asked Questions
The viewer is a visual check, not a full machine simulation. The cut simulation models the cutter's shape and a block of stock, but not holders, fixtures, work offsets or machine limits, so always prove programs on the machine with a dry run.
Open-source credits. The G-code reader and the cut simulation are written in Rust and compiled to WebAssembly with wasm-bindgen and js-sys (MIT or Apache-2.0), with serde and serde_json (MIT or Apache-2.0). The 3D view uses three.js (MIT).