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

Common G-codes the viewer understands
CodeMeaning
G0Rapid move
G1Straight feed move
G2 / G3Clockwise / counter-clockwise arc
G17 / G18 / G19XY / ZX / YZ plane
G20 / G21Inch / millimetre units
G40 / G41 / G42Cutter compensation off / left / right
G80Cancel canned cycle
G81Drilling cycle
G83Peck drilling cycle
G84Tapping cycle
G90 / G91Absolute / incremental positioning
G94 / G95Feed per minute / per revolution
G98 / G99Return 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.

-- READY -- 0:00 / 0:00

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

Lines, arcs and time
Arc centre (I/J/K): Xc = X0 + I, Yc = Y0 + J
Arc centre (R): on the chord's bisector, h = √(R² − (d/2)²) from its midpoint
Feed time (s) = length ÷ F × 60
Rapid time (s) = length ÷ rapid rate × 60
G2 is clockwise and G3 anticlockwise, looking down the axis normal to the plane: Z for G17 (I, J), Y for G18 (K, I) and X for G19 (J, K). A positive R takes the short way round and a negative R the long way. When the end point equals the start point with I/J/K, a full circle is drawn. The third axis moves evenly along the arc, so helical moves show correctly. Arcs are split into short chords that stay within 0.005 mm (0.0002 in) of the true curve, and the viewer flags arcs whose end point is off the circle. With G95 (feed per revolution) the feed per minute is F × S.
Canned cycles
Rapid to the hole XY, then rapid to R
G81, G82, G86, G76, G87, G88: feed to Z, rapid out
G84, G74, G85, G89: feed to Z and feed back out
G83: pecks of Q with full retract to R
G73: pecks of Q with a small chip-break retract
Retract to initial Z (G98) or R (G99)
Q and P stay active for the following holes until a new cycle block, and L (or K) repeats the hole. In G91 mode, R is measured from the initial Z and Z from the R plane, as on Fanuc-style controls. A P dwell is added to the time for G82, G88 and G89. The G83 re-approach and G73 chip-break distances are set to 0.1 mm (0.004 in), close to typical control settings but not read from your machine.

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

Peck drilling two holes
  • 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
Quarter arc, I/J and R
  • 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

It adds up every move at its programmed feed rate, every rapid at the rapid rate you enter, and the dwells. It does not include acceleration, tool changes or spindle start-up, so treat it as a minimum. For typical 2D milling and drilling, real run times are usually somewhat longer; for 3D surfacing with many tiny moves the difference can be larger.

G2 and G3 with either I, J, K centre offsets or an R radius, in the G17, G18 and G19 planes, including full circles and helical moves. A negative R draws the long way round. Arcs whose end point is off the circle, or whose R is too small to reach the end point, are listed under Checks in the Status tab.

G73, G74, G76 and G81 to G89, with G98 and G99 retracts and L or K repeats. G83 and G73 are shown as pecks using Q. Tapping (G84, G74) and reaming or boring cycles G85 and G89 feed back out of the hole, and P dwells are added to the cycle time.

Yes. Moves in G91 are added to the current position, and in a G91 canned cycle R is measured from the initial level and Z from the R plane. G20 programs are shown in inches, with the rapid rate, grid and tolerances in inches too.

Yes. The program is read by a WebAssembly engine written in Rust, the whole toolpath is drawn as one object and the program listing only builds the lines on screen, so programs of a few hundred thousand lines load in a few seconds on a normal computer.

No. The file is read and drawn in your browser, and nothing is sent to a server. A shared link carries the program inside the link itself.

Both. It draws the whole toolpath in 3D and simulates the tool moving along it in real machine time, speeded up 1x to 1000x. You can play, pause and step one program line at a time from the controls in the 3D view (or with Space and the arrow keys), drag the timeline or click a line to jump to it. Tick Cut sim and it also simulates material removal, showing the stock being cut as the program plays.

Yes, in the G17 (XY) plane. Enter the tool radius for your D offsets (one number, or a list such as D1=5 D2=3) and the viewer draws the tool centre path one radius to the left (G41) or right (G42) of the programmed line, with the programmed line dashed underneath. The start-up block ramps on, the move after G40 ramps off, and inside arcs smaller than the tool radius are flagged. With the box empty it draws the programmed line.

G0, G1, G2 and G3 (I, J, K or R), G4, G17 to G19, G20 and G21, G28, G40 to G42, G53 Z0, G73, G74, G76, G80 to G89, G90 and G91, G94 and G95, G98 and G99, plus T, M6, M3, M4, M5, M2 and M30. Sub-programs (M98), macros, G52, G68 and work offset values are not followed and are listed under Checks in the Status tab.

The stock is a grid of columns, and every move lowers the columns under the cutter to the shape of a flat, ball, bull nose, V or tapered ball tool, taken from the T numbers and comments (you can edit them). It colours the stock by tool, follows the timeline, shows the volume removed, and flags rapids that cut material, deep plunges with a flat end mill and cuts below the stock bottom. It is 3-axis only: no undercuts, no 4th or 5th axis, and no lathe programs.

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).