G-code / M-code

Quick reference

Motion

  • G00Rapid positioning

    Moves the tool at max speed to the coordinate. Positioning only — never use it to cut.

    Syntax
    G00 X__ Z__
    Example
    G00 X50. Z2.  (approach the part)
  • G01Linear interpolation

    Straight-line move at feed rate F. The most common straight-cut mode.

    Syntax
    G01 X__ Z__ F__
    Example
    G01 Z-30. F0.2  (turn 30 mm in Z)
  • G02Clockwise circular interpolation

    Arc clockwise. Use I/K (offset from start to arc center) or R (radius).

    Syntax
    G02 X__ Z__ I__ K__ F__  or  G02 X__ Z__ R__ F__
    Example
    G02 X40. Z-10. R5. F0.15
  • G03Counter-clockwise circular interpolation

    Same as G02 but counter-clockwise.

    Syntax
    G03 X__ Z__ R__ F__
    Example
    G03 X30. Z-15. R8. F0.15
  • G04Dwell (pause)

    Pauses for the time given in X (seconds) or P (milliseconds). Useful at groove bottoms.

    Syntax
    G04 X__  or  G04 P__
    Example
    G04 X0.5  (half a second)

Plane

  • G17XY plane

    Selects the XY plane for circular interpolation. Default on milling machines.

    Syntax
    G17
  • G18ZX plane

    Selects the ZX plane. Default on lathes.

    Syntax
    G18
  • G19YZ plane

    Selects the YZ plane. Used on 4/5-axis mills.

    Syntax
    G19

Unit

  • G20Inches

    Sets units to inches.

    Syntax
    G20
  • G21Millimeters

    Sets units to millimeters.

    Syntax
    G21

Reference

  • G27Reference return check

    Checks that the current coordinates match the reference point. Lights the zero lamp.

    Syntax
    G27 X__ Z__
  • G28Return to machine zero

    Returns the commanded axes to the reference point through an intermediate point.

    Syntax
    G28 X__ Z__
    Example
    G28 U0 W0  (incremental direct return)
  • G29Return from reference point

    Moves from the reference point to the intermediate point and then to the destination.

    Syntax
    G29 X__ Z__
  • G302nd/3rd/4th reference point

    Moves to a secondary reference point set by parameter.

    Syntax
    G30 P__ X__ Z__

Thread

  • G32Single-pass threading

    Single-pass threading (straight or tapered). F sets the thread pitch.

    Syntax
    G32 X__ Z__ F__
    Example
    G32 Z-25. F1.5  (1.5 mm pitch thread)

Compensation

  • G40Cancel cutter compensation

    Turns G41/G42 off. Program it before leaving the profile.

    Syntax
    G40
  • G41Left compensation

    Offsets the toolpath one tool radius to the left, viewed along the feed direction.

    Syntax
    G41 D__  or  G41 (lathe uses insert nose radius)
  • G42Right compensation

    Same as G41 but to the right of the feed direction. Most common on external turning.

    Syntax
    G42

Spindle

  • G50Spindle speed limit (lathe)

    Sets the maximum RPM while G96 (constant surface speed) is active.

    Syntax
    G50 S__
    Example
    G50 S3000
  • G96Constant surface speed (lathe)

    The machine adjusts RPM automatically with diameter to keep Vc (m/min) constant.

    Syntax
    G96 S__
    Example
    G50 S3000
    G96 S200
  • G97Constant RPM

    S directly sets spindle speed in RPM. Required for threading.

    Syntax
    G97 S__
    Example
    G97 S1200

Work zero

  • G54Work zero 1

    Activates work coordinate system 1. Goes up to G59.

    Syntax
    G54

Lathe cycle

  • G70Finishing cycle

    Re-runs the profile defined between P (start line) and Q (end line) in a single fine pass.

    Syntax
    G70 P__ Q__
    Example
    G70 P100 Q200
  • G71Longitudinal roughing

    Removes material parallel to Z in automatic passes. U depth per pass, R retract, U/W finishing stock.

    Syntax
    G71 U__ R__ ;  G71 P__ Q__ U__ W__ F__
    Example
    G71 U2. R1.
    G71 P100 Q200 U0.4 W0.1 F0.25
  • G72Facing roughing

    Same as G71 but passes parallel to X (stepped facing).

    Syntax
    G72 W__ R__ ;  G72 P__ Q__ U__ W__ F__
  • G73Pattern repeating

    Ideal for forged/cast parts: repeats the P–Q profile shifting it in X and Z until the final size.

    Syntax
    G73 U__ W__ R__ ;  G73 P__ Q__ U__ W__ F__
  • G74Face peck drilling

    Axial peck drilling on the lathe: drills, retracts to break the chip, and continues.

    Syntax
    G74 R__ ;  G74 Z__ Q__ F__
  • G75Radial grooving

    Cuts radial grooves in X with automatic retract to break chips.

    Syntax
    G75 R__ ;  G75 X__ Z__ P__ Q__ F__
  • G76Automatic threading cycle

    Threads in several passes computing decreasing depth and insert angle.

    Syntax
    G76 P(mmrra) Q__ R__ ;  G76 X__ Z__ P__ Q__ F__
    Example
    G76 P020060 Q100 R0.02
    G76 X28.16 Z-24. P920 Q200 F1.5

Mill cycle

  • G80Cancel canned cycle

    Turns off any active G81–G89 cycle.

    Syntax
    G80
  • G81Simple drilling

    Feeds down to Z, retracts in rapid. No chip breaking.

    Syntax
    G81 X__ Y__ Z__ R__ F__
  • G83Peck drilling

    Deep drilling with programmed retracts to break the chip.

    Syntax
    G83 X__ Y__ Z__ Q__ R__ F__
  • G84Tapping

    Tapping cycle (rigid or floating).

    Syntax
    G84 X__ Y__ Z__ R__ F__
  • G98Return to initial plane

    In canned cycles, returns the tool to the initial Z plane.

    Syntax
    G98
  • G99Return to R plane

    In canned cycles, returns only to the R plane.

    Syntax
    G99

Mode

  • G90Absolute coordinates

    Coordinates measured from the work zero.

    Syntax
    G90
  • G91Incremental coordinates

    Coordinates relative to the current position.

    Syntax
    G91

Feed

  • G94Feed per minute

    F in mm/min. Default on mills.

    Syntax
    G94
  • G95Feed per revolution

    F in mm/rev. Default on lathes.

    Syntax
    G95