What Is G-code?
Upload your image to convert to G-code
Drag & drop or click — PNG, JPG, WebP up to 25MB
One watermarked preview a day, without an account. The clean G-code file: $6.99 for that one file, or 18 files for $7.99 a month with the Starter plan.
G-code is a plain-text file of short lines that a laser engraver, a CNC router or a plasma cutter carries out in order, one after the other: where to go, how fast, and when to switch the beam, the bit or the torch on and off. G0 travels between shapes, G1 cuts in a straight line at the feed rate F, M3 starts the tool and M5 stops it. To get G-code from a logo or a drawing, drop the picture in the box.
- Traces a PNG, JPG or WebP of a logo or a drawing, then writes it as G-code
- Writes millimeters and absolute coordinates (G21, G90), with settings for lasers, CNC routers and plasma cutters
- Shows the traced shapes before the download, watermarked unless the conversion used your credits
The laser file, line by line
This is mounting-plate-laser.gcode: an 80 x 40 mm mounting plate with 5 mm rounded corners and two holes 6 mm across, drawn as an SVG for this page, then written by the G-code engine of the converter with the first entry of its settings menu, Generic, the one for people who set power and speed in their own laser software. With a picture, the converter first traces it into shapes, then writes the G-code from them with this same engine. In these files, each line that is not blank or a comment is one step: a code such as G1 or M3, then the values it needs. A semicolon starts a comment: the rest of the line is a note for people, and the G-code reader of the site skips it.
| Line | In the file | What it does |
|---|---|---|
| 2 | ; Machine: laser | A comment: the machine this setting writes for. |
| 3 | ; Paths: 3 | A comment: three shapes, the two holes and the outline. |
| 4 | ; Feed rate: 1000 mm/min | A comment: the cutting speed used further down. |
| 5 | ; Laser power: S800 | A comment: the power used further down. |
| 7 | G21 ; Units: mm | Every length that follows, X, Y and Z, is in millimeters, and F in millimeters per minute. G20 would mean inches. |
| 8 | G90 ; Absolute positioning | Coordinates count from the origin: X17 means 17 mm from it, not 17 mm further on. |
| 9 | M5 S0 ; Laser off | The laser off, at power 0, before anything moves. |
| 11 | ; Path 1 of 3 | A comment: the first shape, the left hole. |
| 12 | G0 X17 Y20 F3000 | A rapid travel move, laser off, to X 17, Y 20: the right edge of the left hole. On GRBL and Mach3 a G0 runs at the machine's own rapid speed: the F3000 the converter writes on it does not set that speed, and the first G1 sets the cutting speed. |
| 13 | M3 S800 | Laser on, at power 800 on the scale up to 1000 that the converter writes. |
| 14 | G1 X16.942 Y20.585 F1000 | The first cut: a straight move at 1000 mm per minute. The feed rate stays set, so the next lines leave F out. |
| 15 | G1 X16.772 Y21.148 | The next side of the hole. 32 straight sides go round it. |
| Line | In the file | What it does |
|---|---|---|
| 124 | G1 X40 Y40 | The last side of the outline, back to where it started, in the middle of the top edge. |
| 125 | M5 S0 | Laser off. |
| 127 | ; End of cutting | A comment. |
| 128 | M5 ; Laser off | The laser off once more. |
| 129 | G0 X0 Y0 ; Return to origin | Back to X 0, Y 0, where the coordinates count from: a corner of the box around the plate, about 2 mm off its rounded edge. |
| 130 | M2 ; Program end | The end of the program. |
| 132 | ; Stats: 3 paths, 269.004 mm total cut length (1 pass) | A comment: the length the laser cuts. The last line, a comment too, is the estimate of the cutting time the converter adds. |
In all, the file holds 133 lines: 101 G1 lines cut, 4 G0 lines carry the laser between shapes and back to the origin, and the rest are switches, settings, comments and blank lines.
The words in these files
Each word is a letter followed by a number, and a line can hold several words: G0 X17 Y20 F3000 holds four. Files from CAM software may also put two codes on one line, such as G90 G21. In the three files of this page, each word does the following.
- G0
- A rapid travel move to the point given, at the machine's own rapid speed on GRBL and Mach3: between shapes, at the start and at the end.
- G1
- A straight move at the feed rate F. With the tool on, that is the cut.
- G4
- A pause: the router waits for its spindle, the plasma torch while it pierces. P says how long.
- G21
- Millimeters for every length after it, and millimeters per minute for F. The converter writes it in every file.
- G90
- Absolute coordinates, measured from the origin. Its opposite, G91, makes each move relative.
- M3, M5
- Tool on, tool off: the laser, the spindle or the torch.
- M2
- The end of the program.
- X, Y, Z
- Where the move ends: across, along, and for the router and the torch, the height.
- F
- The feed rate of the G1 moves, in millimeters per minute in these files.
- S
- The laser power, or the spindle speed of the router.
One drawing, three G-code files
The plate started as an SVG made for this page (mounting-plate.svg, 295 bytes). The G-code engine of the converter wrote it three times, with three entries of its G-code Material Preset menu: "Generic" for a laser, "Engrave wood, 1mm deep (V-bit)" for a CNC router and "Mild Steel 3mm (55A plasma)" for a plasma cutter. Each number in the table is counted or measured in the files themselves.
| G-code file | Machine | Setting in the converter | Lines | Cutting moves | Tool on | Height (Z) | Cut length | Toolpath size |
|---|---|---|---|---|---|---|---|---|
| mounting-plate-laser.gcode2,242 bytes | Laser | Generic | 133 | 101 | M3 S800, before each shape | No Z move | 269.0 mm | 80 x 40 mm |
| mounting-plate-cnc-router.gcode4,507 bytes | CNC router | Engrave wood, 1mm deep (V-bit) | 258 | 202 | M3 S12000, once | 0.5 mm deep, then 1 mm | 538.0 mm | 80 x 40 mm |
| mounting-plate-plasma.gcode2,889 bytes | Plasma cutter | Mild Steel 3mm (55A plasma) | 151 | 101 | M3, before each shape | Pierce at 3.8 mm, cut at 1.5 mm, safe at 25 mm | 265.2 mm | 81.2 x 41.2 mm |
Cutting moves count the G1 lines that move in X and Y. The cut length and the toolpath size are what the G-code reader of the site measures in each file, in millimeters. The router goes round the plate twice, once per depth, so its cut length is twice the laser one.
In all three files, Path 1 and Path 2 are the holes and Path 3 is the outline: for a drawing of up to 1,500 shapes, the converter cuts what lies inside a shape before the shape around it.
The SVG drawing behind the three files: mounting-plate.svg, 295 bytes.
The CNC router file: depth and a spindle
mounting-plate-cnc-router.gcode engraves the same lines 1 mm deep, in two passes of 0.5 mm. Z is the height of the bit: 0 on the top of the wood, as the file asks, and below it when negative. The spindle starts once, and the bit lifts between shapes.
| Line | In the file | What it does |
|---|---|---|
| 7 | ; Final depth: 1mm (2 x 0.5mm) | A comment: two passes of 0.5 mm. |
| 8 | ; Zero Z on the TOP of the stock. Toolpath follows the line (no tool offset). | A note for whoever runs the job: set Z to 0 on the top of the wood. The bit runs on the line itself. |
| 13 | G0 Z5 ; Safe Z | Lift the bit to 5 mm above the wood. |
| 14 | M3 S12000 ; Spindle on | Start the spindle. Here S is a speed, 12000 RPM, not a power. |
| 15 | G4 P3 ; Let the spindle reach speed | A pause, so the spindle is up to speed before the bit goes down. |
| 17 | ; === Pass 1 of 2 === | A comment: the first pass. |
| 19 | G0 X17 Y20 | Travel to the left hole, bit up. |
| 20 | G1 Z-0.5 F200 ; Plunge | Down 0.5 mm into the wood at 200 mm per minute, a third of the cutting speed. |
| 21 | G1 X16.942 Y20.585 F600 | Follow the line at 600 mm per minute. |
| 53 | G0 Z5 ; Retract | Lift the bit before the next travel move. |
| 134 | ; === Pass 2 of 2 === | A comment: the second pass, over the same three shapes. |
| 137 | G1 Z-1 F200 ; Plunge | Down to 1 mm this time, the final depth. |
The plasma file: heights, a pierce and a torch
mounting-plate-plasma.gcode cuts the plate out of the sheet. Z is the height of the torch above it. For each shape the torch comes down to pierce, waits, drops to its cutting height, cuts, then switches off and rises.
| Line | In the file | What it does |
|---|---|---|
| 9 | ; Kerf compensation: 1.2mm kerf, paths offset 0.6mm, outside parts and inside holes | A comment: the setting counts on a cut 1.2 mm wide, so every closed path moves by half of that, 0.6 mm: outward around the plate, inward inside each hole. |
| 13 | M5 ; Torch off | Torch off before anything moves. |
| 14 | G0 Z25 ; Safe Z | Raise the torch to 25 mm above the sheet. |
| 17 | G0 X16.397 Y20 F3000 | Travel to the left hole. X is 16.397 here, not 17: the path starts about 0.6 mm inside the hole. |
| 18 | G0 Z3.8 ; Pierce height | Down to 3.8 mm above the sheet, the height it pierces from. |
| 19 | M3 ; Torch on | Torch on. There is no S: no power value in this file. |
| 20 | G4 P0.6 ; Pierce delay | A pause while the torch pierces the sheet: the pierce delay of the 3 mm mild steel setting. |
| 21 | G1 Z1.5 F550 ; To cut height | Down to 1.5 mm, the cutting height, at 550 mm per minute. |
| 22 | G1 X16.351 Y20.468 F2200 | Cut at 2200 mm per minute. |
| 54 | M5 ; Torch off | Torch off at the end of the hole. |
| 55 | G0 Z25 ; Retract to safe Z | Back up to 25 mm before the next shape. |
Kerf compensation in this file
The "Mild Steel 3mm (55A plasma)" setting carries a kerf of 1.2 mm: the width of the cut the torch leaves, half of it on each side of its path. So before writing the plasma file, the converter moved every path by half of that, 0.6 mm, toward the waste: the outline outward, which makes the toolpath 81.2 x 41.2 mm, and each hole inward, a circle about 4.8 mm across. Each straight move runs 0.6 mm from the matching move of the laser file, to within 0.001 mm, so a cut 1.2 mm wide leaves the plate and its holes at their drawn size. The file pierces on the path itself, with no lead-in, so the pierce leaves a small mark where each shape starts. The laser and router files carry no compensation. Before cutting parts that must fit, check on a test cut that your torch cuts 1.2 mm wide in that steel.
The converter reads which way to move a path from how the shapes sit inside each other: the outer edge of a part moves out, a hole in it moves in, and a part inside that hole moves out again. If the tracer paints one solid rectangle under a whole picture, the converter takes it out before it writes a G-code that follows outlines, like these three: kept, that rectangle would be the part, and every shape on it a hole.
Curves: short straight moves
The holes
32 G1 moves per 6 mm hole
In the laser and router files, each hole is 32 straight moves about 0.59 mm long. Their ends sit on the 6 mm circle to within 0.001 mm, and the middle of a side falls no more than 0.015 mm inside it.
The corners
8 G1 moves per 5 mm corner
Each rounded corner of the outline is 8 straight moves. With the straight edges, the outline takes 37 G1 lines.
Arcs in one line
G2 and G3: none in these files
G-code can also draw an arc in one line: G2 turns clockwise and G3 counterclockwise, around a center given by I and J. The converter on this page writes straight moves only. The G-code viewer of the site reads both.
Four ways to get G-code, or to check it
From a picture
The converter at the top of this page traces a PNG, JPG or WebP, then writes G-code with the setting you pick for your laser, router or plasma table.
Go to the converterCheck a file
Open a G-code file of up to 50 MB in the free G-code viewer of the site: its moves drawn from above, its size and its laser power, read in your browser before you run it.
G-code viewerPrepared for you
For a messy picture or a job that needs more than a trace, the cut-ready file service prepares a DXF or G-code for laser, CNC and plasma, and quotes it before you pay.
Cut-ready file serviceFor a shop with customers
A shop that resells, or sends its customers' logos out to be prepared, can work on a trade account: a watermarked proof first, then final files with nothing of ours in them, to pass on as your own work. CNC and plasma profiles with G-code get a date agreed with you before the work starts.
Trade accountsHow to make G-code from a picture
- 1
Start from the picture
Choose the PNG, JPG or WebP of your logo or drawing, drop it on the converter at the top of this page and press Convert to G-code.
- 2
Pick the machine and material
Under the preview, the G-code Material Preset menu lists settings for a laser, a CNC router and a plasma cutter. Generic is the entry for people who set power and speed in their own software.
- 3
Download and check
Press Download G-code File: if the conversion used your credits, a ZIP with the G-code, a DXF, the SVG and a PNG downloads at once; otherwise the button opens the payment options. Open the G-code in the G-code viewer to see its path before the first cut.
G-code questions
What does a line of G-code mean?
Read it word by word, a letter and a number each time. In G1 X16.942 Y20.585 F1000, G1 is a straight cutting move, X and Y give the point it ends at, in millimeters after G21, and F1000 sets the speed, 1000 mm per minute.
What is the difference between G0 and G1?
G0 is a rapid travel move between shapes, with the laser off or the bit and the torch lifted: on GRBL and Mach3 it runs at the machine's own rapid speed, whatever F says. G1 is a straight move at the feed rate F, and with the tool on, it cuts. In the laser file of this page, 4 G0 lines carry the laser around and 101 G1 lines cut.
What do M3 and M5 do?
They switch the tool on and off: the laser, the spindle of a CNC router or the plasma torch. The laser file turns the laser on with M3 S800 before each shape and off with M5 S0 after it; the router file starts its spindle once, with M3 S12000, and stops it at the end.
What units does G-code use?
The one the file names: G21 for millimeters, G20 for inches. The converter on this page writes G21 in every file. Read as inches, the 80 mm plate would come out 2,032 mm wide, so check that line when a job runs at the wrong size.
What file extensions does G-code use?
G-code comes under many endings. The converter on this page saves .gcode, and the G-code viewer of the site opens .gcode, .gc, .gco, .g, .nc, .ngc, .ncc, .tap, .cnc and .txt files.
Why is a circle written as many short lines?
Because the converter writes straight moves only. In the laser file, each 6 mm hole is 32 G1 moves about 0.59 mm long, and no side falls more than 0.015 mm inside the true circle. G-code can also draw an arc in one line, with G2 or G3; the converter does not write them, and the G-code viewer reads them.
Will this G-code run on my machine?
The converter describes its laser and router files as GRBL-compatible, and writes the plasma file in the Mach3 style, with M3, M5 and a G4 pierce delay. The software it names: GRBL, LightBurn, LaserGRBL, UGS and Candle. Open the file in your machine software and check the path before the first cut.
Can I check a G-code file before I run it?
Yes. The free G-code viewer of the site draws every move from above, with the size of the job and the laser power, and reads the file in your browser. Open the three files of this page in it to compare them.
Can I make G-code from a JPG or PNG?
Yes. Put it in the converter at the top of this page and press Convert to G-code. Without an account you get one watermarked preview a day, and the clean G-code file costs $6.99 for that one file, or 18 files for $7.99 a month with the Starter plan.
More: G-code viewer, cut-ready file service and all VectoSolve tools.
