CNC G Code List
CNC G code list: this page holds 91 G-code entries and 34 M-code entries, 101 different codes in all, taken from the documentation of Haas, LinuxCNC and Mach3, with Fanuc lathe and mill cycles marked where a Fanuc-focused list names them. G00 is a rapid move and G01 a straight move at the programmed feed rate, and on every controller read for this page they mean the same thing. 22 codes do not: they have more than one meaning in the list below. Filter the table by mill or lathe, or paste a line such as G01 X10 Y5 F200 into the decoder.
Where the entries in this G-code list come from
Every entry in the table comes from a document that was fetched and read for this page. The Haas entries come from the 2023 operator manuals for the Haas mill and the Haas lathe, which print a G-code table and an M-code table. The LinuxCNC entries come from its G-code and M-code documentation. The Mach3 entries come from chapter 10 of the Mach3 Mill and Mach3 Turn manuals, version 1.84. The names are short paraphrases, not copies of any manual's wording.
A code that is in a list is marked with that list's name in the Controllers column. A code that is missing from a list is not marked, which means only that the list does not print it. The table does not claim that a machine will refuse the code. The Haas manuals as downloaded show tables only, so the Haas rows carry a name and no behaviour notes. For what a Haas code does with its P, Q and R words, use the code's page in the Haas manual for your control.
Wikipedia describes the background in two sentences that matter for any list like this one. G-code, also called RS-274, was first standardised in the United States by the Electronic Industries Association in 1963, and it is standardised today in ISO 6983-1. In practice, extensions have been added independently by control builders and machine tool builders, so the operator of a specific controller has to know that controller's differences. That is why this table has a Controllers column instead of one meaning per code. The current Wikipedia article no longer carries a code table, so it is used here for that background only.
The list is not complete. It covers 101 codes, chosen because they appear on at least two of the lists or are the common codes for motion, plane, unit, offset, cycles, feed and coolant. Each Haas table prints more than 100 G codes, including the option and probing codes and the macro codes, and anything outside the table above should be looked up in your machine's manual.
Fanuc G codes: what the sources let this page say
Fanuc G codes are the most searched version of this question, and the honest position is that no Fanuc operator manual could be fetched for this page. The Fanuc America content site and the manual libraries that mirror Fanuc manuals refused automated requests. So the table has no column that says "Fanuc manual" and none of its meanings is attributed to one.
Three things can be said from what was read. First, Wikipedia says that from the 1970s to the 1990s many machine tool builders tried to solve compatibility problems by standardising on Fanuc controllers, with Siemens the other major name, especially in Europe. Second, the Haas lathe table itself tags some codes with the word FANUC: G50 (set global coordinate offset), G52 (set local coordinate system) and G54 to G59 (coordinate systems 1 to 6). Third, HelmanCNC, a Fanuc programming site, lists its explained Fanuc codes by heading, and 36 entries in the table are marked Fanuc* because a heading on that list names them. They include the turning cycles G70, G71, G72, G73, G74, G75 and G76, the thread-cutting code G32, the turning cycle G90, the threading cycle G92 and the facing cycle G94.
That list also shows where Fanuc-style names collide with other controllers. HelmanCNC lists G94 as a facing cycle and also as feed per minute, and it lists G98 and G99 as feed per minute and per revolution, which is how the Haas lathe uses them. It also lists G78 as a threading cycle for a Fanuc 21 T-B lathe, where Mach3 Turn uses G78 for a facing cycle. A third-party heading list is weaker evidence than a manual. Treat the Fanuc* mark as "a Fanuc-focused site uses this code", and check a code against your machine's own manual before you run it.
G-code list for a mill and for a lathe
The Machine column sorts the table into 72 entries that both mill and lathe lists carry, 20 that only mill lists carry and 33 that only lathe lists carry. An entry counts as mill if a Haas mill or Mach3 Mill list has it, and as lathe if a Haas lathe or Mach3 Turn list has it. LinuxCNC covers both kinds of machine, so its entries do not decide the class except where its own text says lathe, as it does for G7 and G8.
The lathe-only G codes in the table are G32, G50, G70, G71, G72, G73, G74, G75, G76, G77, G78, G07, G08, G90, G92, G94, G95, G96, G97, G98, G99, G390, G391. They are the diameter and radius modes, the finishing and roughing cycles for turning, the grooving and threading cycles, constant surface speed and the Haas lathe's own absolute and incremental codes. The mill-only G codes are G44, G49, G60, G70, G71, G72, G74, G76, G77, G90.1, G91.1, G93. They include the Haas bolt-hole patterns, fine boring, back boring and left-hand tapping cycles, tool length compensation in the subtract direction and its cancel, and a few modes, such as inverse time feed and the arc center mode codes, that no lathe list read here carries. Most of the basics, such as motion, planes, units, work offsets, cutter compensation and the drilling cycles G81 to G89, are on both. The Haas lathe table does list G81 to G89, and the Mach3 Turn manual lists several of them as well.
The roughing cycles show the split best. On the Haas lathe, G71 is the stock removal cycle for the outside or inside diameter and G72 is the one for the end face. LinuxCNC calls G71 and G72 lathe roughing cycles too, and warns that they are currently somewhat fragile. The same two numbers on the Haas mill are bolt-hole patterns, which is the clearest case of why the list needs to be read for the right machine.
Same code, different job: where the controllers differ
22 codes in the table have more than one entry because the lists give them different meanings. Check this table whenever a program comes from a different controller than the one you run it on.
| Code | Meanings and where each applies |
|---|---|
| G50 | Cancel scaling (Haas mill, Mach3 mill, Mach3 turn) Spindle speed limit, or set global coordinate offset (Haas lathe) |
| G70 | Bolt hole circle (Haas mill) Finishing cycle after roughing (Haas lathe, LinuxCNC, Fanuc*) Inch units (older synonym of G20) (Mach3 mill) |
| G71 | Bolt hole arc (Haas mill) Stock removal (roughing) cycle along the part (Haas lathe, LinuxCNC, Fanuc*) Millimetre units (older synonym of G21) (Mach3 mill) |
| G72 | Bolt holes along an angle (Haas mill) End face stock removal (roughing) cycle (Haas lathe, LinuxCNC, Fanuc*) |
| G73 | Chip-breaking peck drilling cycle (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn, Fanuc*) Irregular path (pattern repeating) stock removal cycle (Haas lathe, Fanuc*) |
| G74 | Left-hand or reverse tapping cycle (Haas mill, LinuxCNC, Fanuc*) End face grooving or peck drilling cycle (Haas lathe, Fanuc*) |
| G76 | Multi-pass threading cycle (Haas lathe, LinuxCNC, Mach3 turn, Fanuc*) Fine boring cycle (Haas mill, Fanuc*) |
| G77 | Back bore cycle (Haas mill) Turning canned cycle (Mach3 turn) |
| G78 | Facing canned cycle (Mach3 turn) Threading cycle (Fanuc lathe) (Fanuc*) |
| G90 | Absolute distance mode (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn) Turning cycle, outside or inside diameter (Haas lathe, Fanuc*) |
| G92 | Set coordinate offset (shift) (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn) Threading cycle (Haas lathe, Fanuc*) |
| G94 | Feed per minute (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn, Fanuc*) End facing cycle (Haas lathe, Fanuc*) |
| G95 | Feed per revolution (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn, Fanuc*) Live tooling rigid tap, face (Haas lathe) |
| G98 | Feed per minute (Haas lathe) (Haas lathe, Fanuc*) Canned cycle returns to the starting position (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn) |
| G99 | Feed per revolution (Haas lathe) (Haas lathe, Fanuc*) Canned cycle returns to the R plane (Haas mill, LinuxCNC, Mach3 mill, Mach3 turn) |
| M07 | Shower coolant on (Haas mill) Mist coolant on (LinuxCNC, Mach3 mill, Mach3 turn) |
| M08 | Coolant on (Haas mill, Haas lathe) Flood coolant on (LinuxCNC, Mach3 mill, Mach3 turn) |
| M88 | Through-spindle coolant on (Haas mill) High-pressure coolant on (Haas lathe) |
| M89 | Through-spindle coolant off (Haas mill) High-pressure coolant off (Haas lathe) |
| M10 | Engage 4th axis brake (Haas mill) Chuck clamp (Haas lathe) |
| M11 | Release 4th axis brake (Haas mill) Chuck unclamp (Haas lathe) |
| M48 | Enable feed and spindle overrides (LinuxCNC, Mach3 mill, Mach3 turn) Check the program suits the loaded pallet (Haas mill) |
Four of these are worth knowing by heart. The first is G70 to G72. On the Haas mill they are bolt-hole patterns, on the Haas lathe and in LinuxCNC they are the finishing and roughing cycles, and in the Mach3 Mill manual G70 and G71 are the inch and millimetre switches, which that manual says are synonyms for the preferred G20 and G21. A line that reads G70 can therefore put a cycle, a hole pattern or a unit change into the program.
The second is G98 and G99. On a Haas lathe they select feed per minute and feed per revolution. On the Haas mill, in LinuxCNC and in both Mach3 manuals they choose where a canned cycle retracts, LinuxCNC putting it as G98 back to where the axis was before the cycle and G99 to the R-word position. On those controllers feed per minute is G94 and feed per revolution is G95, while on the Haas lathe G94 and G95 are an end facing cycle and a live-tooling rigid tap.
The third is coolant. The LinuxCNC M-code page says M7 turns mist coolant on and M8 turns flood coolant on. The Mach3 manuals are not consistent: the M-code summary table in the Mach3 Mill manual lists M7 as mist and M8 as flood, the same as LinuxCNC, but its section 10.8.4 and the setup text in both manuals say M7 for flood and M8 for mist. The Haas mill table lists M07 as shower coolant on and M08 as coolant on, and the lathe table lists M08 and M09 without a mist or flood word. Each of these is what the manual says. Because the Mach3 manuals disagree with themselves and Haas uses different names again, check which output M7 and M8 drive on your own machine before relying on either.
The fourth is the M10 and M11 pair. The Haas mill table uses them for the 4th axis brake, and the Haas lathe table for the chuck clamp and unclamp. M48 is an override enable in LinuxCNC and Mach3 and a pallet program check in the Haas mill table.
CNC M code list: program, spindle and coolant functions
M codes are miscellaneous machine functions, and the Haas manual says that they do not command axis motion, are written as M followed by two or three digits, that only one M code is allowed per line, and that all M codes take effect at the end of the block. The M03 in a line like G01 X10 M03 therefore does not start the spindle until the move is complete, if that rule is applied as the Haas manual states it. That is the Haas rule. The sources read for the other controllers have different statements, so check this one before you rely on it elsewhere.
The program-flow codes are the same on all five lists. M00 stops the program. M01 stops it only if the optional stop switch is on, per the LinuxCNC page, which also says that both leave the control in Auto mode. M02 and M30 end the program. LinuxCNC lists a long set of effects at the end of a program: the origin offsets return to the default, the plane goes to XY, distance mode goes to absolute, the feed mode goes to units per minute, cutter compensation turns off, the spindle stops and coolant turns off. It adds that M30 also exchanges pallet shuttles. The Mach3 manual says M2 leaves the M2 line as the next line to execute and M30 rewinds the file, and that its list of end-of-program effects depends on options chosen in its Logic dialog.
M03, M04 and M05 are spindle clockwise, counterclockwise and stop on all five lists. LinuxCNC adds a $ word to address one spindle or, with $-1, all active spindles. M06 is the tool change on the Haas mill, LinuxCNC and Mach3, and the Haas lathe table has no M06 entry at all. The Haas lathe table instead has turret rotation codes M17 and M18, tailstock M21 and M22 and live tooling M133 to M135.
The subprogram calls are M98 and M99 on every list: M98 calls a subprogram and M99 returns from one. The two Haas tables also list M97 as a local subprogram call. Mach3 adds M47, which restarts the program from its first line. Use the Category filter on Coolant, Program flow or Spindle and tool to see the full set.
How to read a line of G-code word by word
The LinuxCNC overview defines the parts of a line. A word is a letter followed by a number, such as G1 or X3. An optional line number, the letter N and an integer, comes first and does not have to be used or kept in order. Spaces and tabs do not change the meaning, and input is not case sensitive except inside comments. Comments go in parentheses, or after a semicolon for the rest of the line. The decoder above follows those rules, so N20 g2x10y16 (arc) is read as N20, G2, X10, Y16.
The line G01 X10 Y5 F200 has four words. G01 is a straight move at the programmed feed rate. X10 and Y5 are the end point on the X and Y axes, in the active coordinate system and units. F200 sets the feed rate. LinuxCNC says the feed is usually in machine units per minute, unless the inverse-time or feed-per-revolution modes are on. Mach3 gives the same two modes, units per minute for G94 and units per revolution for G95. Use G20 or G21 to know whether the units are inches or millimetres.
Many codes are modal, which Mach3 explains as staying in effect until another code of the same kind replaces them, while non-modal codes such as G4 act only on their own line. LinuxCNC applies the idea to motion: G1 is optional on a line if the current motion mode is already G1, so a line holding only X20 moves in a straight line at the feed rate. LinuxCNC adds that it is an error to use G1 when no feed rate has been set.
The decoder explains axis letters, feed, speed, tool, line number and the arc and cycle words using LinuxCNC's word table, which lists I, J and K as the arc offsets from the X, Y and Z axes, R as the arc radius or canned cycle plane, P as the dwell time in cycles and with G4, Q as the feed increment in G73 and G83 and H as the tool length offset index. LinuxCNC warns that I, J, K, L, P and R can mean different things in different contexts, so the decoder gives the table's wording and not a verdict. If a G or M word appears on several controllers with different meanings, the decoder lists each one with its controllers.
Arc examples worked out: G02, G03, I, J and R
The Mach3 manual gives one worked arc, and the numbers can be checked step by step. The tool is at X7 Y7 in the XY plane, and the block is G17 G2 X10 Y16 I3 J4. G2 is clockwise, so the arc goes clockwise as seen from the positive Z axis. I and J are the offsets from the start point to the center, so the center is at X10 Y11, which is (10, 11). The distance from the center to the start is 5 and from the center to the end point is 5. Both are the same, which is what makes the arc valid. Mach3 raises an error if the two differ by more than 0.0002 inch, or 0.002 mm in a metric program. The arc turns through 143.13 degrees.
The same arc in absolute center mode needs I10 J11, since the center is given as coordinates. The center mode is a setting: Mach3 chooses it in Configure and State, and LinuxCNC selects it with G90.1 for absolute and G91.1 for incremental, with incremental the default. LinuxCNC calls center-format arcs more accurate than radius-format arcs and the preferred form, and notes that rounding error can appear if inch programs use fewer than four decimals or metric programs fewer than three.
In radius format the block is G2 X10 Y16 R5. Mach3 says a positive R is an arc of 180 degrees or less and a negative R an arc of more than 180 degrees. From the same start and end points, R5 gives the same center as above, (10, 11). R-5 gives a center at (7, 12) and an arc of 216.87 degrees, the long way round. The center for a given R is found from the chord between the start and end points: the center sits 1.581 units from the chord midpoint here, on the side that suits the direction and the sign of R.
Mach3 warns against radius-format arcs near a semicircle, because a small change in the end point moves the center a lot. The arithmetic shows why. With R20, the offset of the center from the chord midpoint is the square root of 20 squared minus half the chord squared. For a 30 unit chord the offset is 13.229. For a 39.9 unit chord it is 1.413, and for a 40 unit chord, an exact semicircle, it is 0. A 0.1 unit change in the end point has moved the center by 1.413 units, about fourteen times the change in the end point. Mach3 rates arcs from tiny up to 165 degrees, and from 195 to 345 degrees, as fine. It calls nearly semicircular arcs very bad and nearly full circles outrageously bad. A center-format block avoids the problem.
Feed, dwell, surface speed and tapping examples
Feed rate gives the time of a move. Taking G21 G94 with a straight move from X0 Y0 to X10 Y5 at F200, the length is the square root of 10 squared plus 5 squared, 11.180 mm. At 200 mm per minute that takes 0.056 minutes, which is 3.354 seconds. Under G95 the same F value is per spindle revolution, so F0.2 at 1000 RPM is 0.2 × 1000 = 200 mm per minute.
A dwell holds the axes still. LinuxCNC says the P word is in seconds, so G4 P0.5 waits half a second, that the P number may not be negative or missing, and that G4 does not affect the spindle, coolant or I/O. At 1000 RPM the spindle turns 8.33 revolutions during that half second. In Mach3 the P number can be seconds or milliseconds, set in the Config and Logic dialog, so in a milliseconds setup the same half second is G4 P500. A program written for one setting dwells 1000 times too long or too short on the other.
Constant surface speed is G96 on the Haas lathe and in LinuxCNC, and G97 returns to RPM mode. LinuxCNC's example is G96 D2500 S250, where S is the surface speed in meters per minute under G21 or feet per minute under G20, and D caps the spindle at 2500 RPM. LinuxCNC adds that X0 must be the center of rotation, or the speed will be wrong, and that G96 is not affected by radius or diameter mode. Under G21, the RPM for 250 m/min is 250 × 1000 ÷ (π × diameter). At a 50 mm diameter that is 1591.5 RPM. At 20 mm the formula asks for 3978.9 RPM, so the 2500 RPM cap applies, and it applies to every diameter below 31.83 mm. Under G20, the same 250 on a 2 inch diameter is 250 × 12 ÷ (π × 2) = 477.5 RPM. G7, LinuxCNC's lathe diameter mode, treats X as a diameter, so X1 puts the cutter 0.5 inch from center for a 1 inch part, and G8 returns to radius mode.
The Mach3 manual relates tapping speed and feed. For its G84 cycle, the spindle speed equals the feed rate times the pitch measured in threads per unit length, and its example has 2 threads per millimetre and F150, so S is 150 × 2 = 300. The reverse works for a thread given by its pitch: a 1.5 mm pitch is 1 ÷ 1.5 threads per mm, so at S400 the feed is 400 × 1.5 = 600 mm per minute. See the metric thread chart for the pitches.
G-code list PDF and cheat sheet: printing and downloading
People who search for a G-code list PDF usually want something to pin up by the machine. The Print button above prints the table with the filters you have set, and many browsers' print dialogs offer to save it as a PDF. The CSV link downloads every entry, with the controllers named, for use in a spreadsheet. A printed copy of this list is a cheat sheet and not a manual: the machine's own manual decides what a code does on that machine.
The two Haas manuals linked in the sources section carry the full code tables for those controls, and the Mach3 and LinuxCNC documents are linked there as well. This page does not copy any of them. Related reference pages are the speeds and feeds calculator and the drill size chart.
Mistakes that come from using the wrong list
Running a program on a different controller than the one it was written for is where a G-code list helps most, and where the table above shows the risk. Before a first run, look for the codes with more than one entry above. G70 to G72, G90, G92, G94, G95, G98 and G99 can each do a different job, M7 and M8 are described in opposite ways in different places, including inside the Mach3 manuals, and M10 and M11 move a brake or a chuck depending on the machine.
Check units next. Mach3 says it is usually a good idea to program G70 or G71 near the beginning of a program and nowhere else, and that G20 and G21 are the preferred codes. Check the distance mode as well: G90 is absolute on the Haas mill, LinuxCNC and Mach3, and on the Haas lathe the manual lists G390 and G391 for absolute and incremental positioning.
All entries as a spreadsheet: cnc-g-code-list.csv. This list is a reading aid. It is not a controller manual, and the Fanuc* mark is not a Fanuc source.
The same data as JSON, with units and source: cnc-g-code-list.json.