Skip to content
LatheCalculator
    Turning
    Speeds & feedsLathe RPMTapersSurface finishKnurlingWork & boring bar deflectionGrinding wheel speed
    Threading
    Thread calculatorChange gearsThree-wire measurementCutting a thread (guide)
    Milling & boring
    Dividing head & rotary tableBoring headPCD / bolt circleSine bar & sine plateMilling feeds & chip thinning
    Drilling & tapping
    Tap drill finderChamfer & countersinkDrill chartBolt torque
    Pipe & welding
    Pipe threads (NPT, BSPT, BSPP)Weld bevel & counterbore
    Maths
    Right-angle triangleMetal weightHole & shaft fitsUnit converterJob costing
    CNC
    G-code viewerG-code referenceBolt hole G-codeHelical bore G-codeThread milling G-codeFace milling G-codeTurning G-codeArc I/J/K ↔ RCycle timeG76 threading cycleTool nose compensation
    Reference
    Materials listGlossaryHardness conversionHeat treatmentDrill chartPrintable cheat sheets
    Guides
    Machine guidesHow-to guidesMarking out a PCD (guide)

    Home › CNC & G-code › G-code reference

    G-code reference

    The common G and M codes for mills and lathes, in our own words. Codes whose meaning or format changes from one control to another are marked Control-specific. Your machine’s own manual always wins.

    Each code below has been checked against at least two public sources (listed in the last column and at the bottom of the page). We have left out codes we could not confirm in two places, and the many maker-specific codes (pocketing cycles, probing, bolt-hole cycles and so on).

    CodeWhat it doesWatch out forChecked against
    G0Move at the machine’s full rapid rate to the given point. Not for cutting.Plan rapid moves well clear of the work and clamps.LinuxCNC, Grbl, Haas
    G1Straight-line cutting move at the current feed rate F.LinuxCNC, Grbl, Haas
    G2 / G3Arc clockwise (G2) or anticlockwise (G3), looking down on the active plane from its positive side. Give the end point and either the centre (I, J, K) or a radius (R). Adding a move on the third axis makes a helix.By default I/J/K are distances from the arc’s start point. Radius-format arcs are unreliable near a half or full circle; centre format is safer.LinuxCNC, Grbl, Haas
    G4Dwell: pause for a set time.Control-specific The unit of the time word (seconds or milliseconds, and whether a decimal point is allowed) varies by control.LinuxCNC, Grbl, Haas
    G17 / G18 / G19Choose the plane for arcs and compensation: XY, XZ or YZ. Lathes normally work in G18.LinuxCNC, Grbl, Haas
    G20 / G21Program in inches (G20) or millimetres (G21).Put it at the start of every program, before any moves.LinuxCNC, Grbl, Haas
    G28Go to a reference position, usually through any intermediate point given on the same line.Control-specific What the reference position is, and whether the intermediate point is used, depends on the control and its settings.LinuxCNC, Grbl, Haas
    G40Cancel cutter (or tool nose) radius compensation.LinuxCNC, Grbl, Haas
    G41 / G42Cutter radius compensation with the tool to the left (G41) or right (G42) of the path, looking along the direction of travel. On lathes the same codes are tool nose compensation.Control-specific Lead-in rules, how the radius is called up and tip direction settings vary. Some hobby controls (for example Grbl) do not have G41/G42.LinuxCNC, Haas
    G43Apply a tool length offset, normally with an H number.Control-specific Grbl uses its own G43.1 form instead.LinuxCNC, Haas
    G49Cancel tool length offset.LinuxCNC, Grbl, Haas
    G53Move in machine coordinates for this line only.LinuxCNC, Grbl, Haas
    G54 to G59Select one of six work offsets (work coordinate systems).LinuxCNC, Grbl, Haas
    G76A multi-pass lathe threading cycle.Control-specific The format varies a lot: a two-block form on many Fanuc-style lathes, a one-block form on others (for example Haas and LinuxCNC), with different letters and meanings. On some mills G76 is a fine boring cycle instead.LinuxCNC, Haas, Tutorials
    G80Cancel a canned (drilling) cycle.LinuxCNC, Grbl, Haas
    G81Drilling cycle: rapid to R, feed to Z, rapid back out.Control-specific Not available on Grbl.LinuxCNC, Haas
    G82As G81 with a dwell at the bottom.Control-specific Dwell units vary, as for G4. Not available on Grbl.LinuxCNC, Haas
    G83Peck drilling: feeds down in steps of Q, retracting between pecks to clear chips.Control-specific How far it retracts between pecks varies by control and settings. Not available on Grbl.LinuxCNC, Haas
    G90 / G91Absolute (G90) or incremental (G91) positions on mills and most routers.Control-specific On many Fanuc-style and Haas lathes, G90 is a turning cycle instead and incremental moves use U and W.LinuxCNC, Grbl, Haas
    G94 / G95Feed per minute (G94) or per revolution (G95) on mills.Control-specific On many Fanuc-style and Haas lathes, G94 is a facing cycle and feed modes are G98/G99.LinuxCNC, Grbl, Haas
    G96 / G97Constant surface speed on (G96) or off, so S is rev/min (G97). Mainly used on lathes.Control-specific Set a maximum spindle speed before using G96. How the limit is set varies by control.LinuxCNC, Haas
    G98 / G99On mills: after a drilling cycle return to the start height (G98) or only to the R plane (G99).Control-specific On many Fanuc-style and Haas lathes, G98 and G99 mean feed per minute and feed per revolution.LinuxCNC, Haas
    M0 / M1Program stop (M0); optional stop that only acts when the operator has it switched on (M1).LinuxCNC, Grbl, Haas
    M2 / M30End of program. On many controls M30 also resets the program to the start.LinuxCNC, Grbl, Haas
    M3 / M4 / M5Spindle forwards (clockwise), reverse (anticlockwise) and stop, at speed S.LinuxCNC, Grbl, Haas
    M6Tool change to the tool chosen with T.Control-specific Lathes with turrets often change tool with the T word alone.LinuxCNC, Haas
    M7 / M8 / M9Coolant: M8 flood on, M9 all coolant off. M7 is a second coolant output.Control-specific What M7 drives (mist, shower or something else) varies by machine.LinuxCNC, Grbl, Haas

    Words used with the codes

    X, Y, Z are positions. I, J, K are arc centre distances. R is an arc radius or, in a drilling cycle, the height the feed starts from. F is the feed rate, S the spindle speed, T the tool, H a length offset number and P and Q are used for dwell times, peck depths and cycle settings. A word in brackets ( ) is a comment.

    Sources

    We read these public pages for facts only (checked 25/10/2026). No wording, tables or examples were copied from them.

    • LinuxCNC: the G-code and M-code reference pages in the LinuxCNC documentation, linuxcnc.org/docs.
    • Grbl: the Grbl v1.1 commands page on the project’s GitHub wiki.
    • Haas: the public mill G-code, lathe G-code and mill M-code lists and the lathe G76 page on haascnc.com.
    • Tutorials: the public two-block G76 explanations on gcodetutor.com and cncprogramminghub.com, for the Fanuc-style two-block format.

    Codes are general reference only and are not an official description of any control. See the terms of use.

    FANUC, Haas, Siemens, Heidenhain, LinuxCNC and Grbl are names or trademarks of their respective owners. They are mentioned only to describe which controls a code format relates to. Lathe Calculator is not affiliated with or endorsed by any of them. Trademarks.

    Try the G-code viewer or the generators for bolt holes, helical boring, thread milling and G76 threading.

    Next step

    • Preview a program →

    Related tools

    G-code viewerDraw a program’s toolpath, check extents and estimate run time.Bolt hole G-codeG81 or G83 drilling program for holes on a PCD.Helical bore G-codeHelical interpolation program to bore a hole with an end mill.Thread milling G-codeInternal or external thread milling program, right or left hand.

    AboutMaterialsDrill chartPrintable sheetsJust for funGlossaryContactPrivacyCookiesAffiliate disclosureDisclaimerTermsTrademarksLicences

    Results are starting points only – always check against your tooling maker’s data and work safely. See the disclaimer.

    Trade names such as INCONEL®, MONEL®, INCOLOY®, NIMONIC®, HASTELLOY®, ZERON®, 254 SMO® and STELLITE® are trademarks of their respective owners and are used here only to identify materials. Machine brand names (Colchester, Harrison, Myford, Boxford, XYZ, Warco, Chester, Axminster, Sieg, Clarke, Bridgeport, Tom Senior, Kearns-Richards, TOS) and CNC control names (FANUC, Haas, Siemens, Heidenhain, LinuxCNC, Grbl) are used only to describe machines and controls; this site is not affiliated with or endorsed by any manufacturer. More.

    © 2026 Lathe Calculator · lathecalculator@outlook.com · No ads, no analytics, no cookies. Privacy · Cookies · Cookie settings · Disclaimer · Terms · Contact

    Threads Drills Speeds Machines