G-Code Minifier

Compress long toolpaths for older CNC controls (like vintage Fanuc or Haas) with strict memory limits by stripping non-essential characters.

Strip Options
Strips all ( text ) and ; text blocks.
Strips N10, N100 codes from the start of lines.
Combines intermediate points on straight, single-axis cuts (e.g. X10 X20 X30 becomes X30).
Combines consecutive, co-radial arc segments into a single smooth arc.
G0 X1. Y1. becomes G0X1.Y1.
Removes trailing zeros. X1.5000 becomes X1.5. Preserves required whole-number decimals.
Deletes empty carriage returns.
Original File
Click or drag G-code file here Supports .nc, .txt, .gcode
Minified Result
Original Size
0.00 KB
New Size
0.00 KB
Space Saved
0.0%

How the G-Code Minifier Works

The minifier makes a program smaller by removing characters the control does not need and, if you allow it, by merging moves that do not change the path. It is aimed at older controls with very little program memory and at slow serial (DNC) links.

Each option can be switched on or off. Removing comments, blank lines, line numbers and spaces and compacting decimals only change how the program is written. The two merging options rewrite moves, so they need more care. Sizes are counted in bytes and shown in KB, where 1 KB is 1,024 bytes.

How It Works

Pass 1: Structure
Comments: ( … ) and ; … removed
Blank lines removed
Linear: X0.5, X1.0, X1.5 → X1.5
Arcs: same-centre G02/G03 run → one arc
A linear run merges only when each line is a G00 or G01 move along the same single axis, in the same direction, with no F, M, S or other words. An arc run merges only when the arcs turn the same way about the same centre (within 0.005 of a unit), stay flat in Z, carry no F or other words, and add up to no more than one full turn. Both merges happen only in G90 absolute mode and assume the XY plane.
Pass 2: Characters
Line numbers: leading N10, N100 removed
Spaces: G0 X1. Y1. → G0X1.Y1.
Decimals: X1.5000 → X1.5, X1.0000 → X1.
Decimals are compacted on X, Y, Z, I, J, K, R and F values that already have a decimal point. The point itself is always kept. A merged arc is written with 4 decimals and an explicit G02 or G03, then compacted like any other line.

Worked Examples

All options on
Original (0.22 KB)
%
O1001 (BRACKET)
N10 G90 G17 G20
N20 G0 X0.0000 Y0.0000
N30 G1 Z-0.1000 F15.0
N40 X0.5000
N50 X1.0000
N60 X1.5000

N70 G3 X2.0000 Y0.5000 I0.0000 J0.5000
N80 X1.5000 Y1.0000 I-0.5000 J0.0000
N90 G0 Z0.1000 ; RETRACT
N100 M30
%
Minified (0.07 KB, 67.4% saved)
%
O1001
G90G17G20
G0X0.Y0.
G1Z-0.1F15.
X1.5
G03X1.5Y1.I0.J0.5
G0Z0.1
M30
%
What happened
  • N40 to N60 move X the same way along one line, so only the last point, X1.5, is kept.
  • N70 and N80 are two quarter arcs about the same centre (X1.5 Y0.5), so they become one half circle from X1.5 Y0 to X1.5 Y1.
  • N30 keeps its own line because it carries a feed rate. Comments, the blank line, N numbers, spaces and trailing zeros are gone.
  • Direction matters: G1 X2.0 followed by X0.5 is not merged, because jumping straight to X0.5 would leave X0.5 to X2.0 uncut. A G01 peck sequence such as Z-0.2, Z0.05, Z-0.4 is kept for the same reason.

Paste the original into the page with every option switched on and you will get the same output and the same size figures.

Tips for Using the Results

  • Start with the safe options. Removing comments, blank lines and spaces and compacting decimals never change the path. If that saves enough, switch the two merging options off.
  • Keep N numbers the program relies on. GOTO, M97 P and M99 P jumps refer to sequence numbers, and many shops restart part-way through a program by searching for an N number.
  • Keep a commented master. Comments often hold tool lists, setup notes and messages shown at an M00 or M01 stop. Store the full version and send only the minified copy to the machine.
  • Check merged arcs. A merged arc takes the centre of the first arc in the run, and centres up to 0.005 apart count as the same. A control with a tight arc radius check may alarm, so backplot the output in the G-Code 3D Viewer first.
  • Check your control accepts no spaces. Most ISO-style controls read G0X1.Y1. without trouble, but confirm it in your control manual before you rely on it.

Frequently Asked Questions

Removing comments, blank lines, line numbers and spaces and compacting decimals do not change any move. The two merging options rewrite moves, but only where the path stays the same: a run of moves along one line in one direction, or arcs that carry on round the same centre. Always backplot the output to confirm.

Usually, yes, because most controls do not need N numbers to run a program. Keep them if the program uses GOTO, M97 or M99 with a P address that jumps to a sequence number, or if you restart programs part-way through by searching for an N number.

Without a decimal point, many Fanuc-style controls read the number as a count of the smallest input increment, so X1 can mean 0.0001 in or 0.001 mm instead of 1. Keeping the point makes the value mean what it says.

Arcs merge only when they follow each other directly, turn the same way about the same centre, have no Z movement, carry no feed rate or other words, use I and J rather than R, and the program is in G90. A run is also split once it would go past a full turn, and any comment left on a line stops it merging.

It depends on the file. CAM output with long comments, line numbers and four-decimal coordinates shrinks the most. The panel under the output shows the original size, the new size and the percentage saved for your own file.

Minified programs are harder to read and check. Keep the original, backplot the minified version and prove it out with single block before running it unattended.