CNC Machining

CNC Machining

G code

G Code is used to control the path of the machine tool. There isn’t one universal list of all CNC G- and M-codes: G-codes vary by controller (Fanuc, Haas, Siemens, Mitsubishi, LinuxCNC, etc.), and M-codes are especially machine-builder-specific. Below is a comprehensive Fanuc/Haas-style reference covering the commonly encountered codes. Some codes have different meanings depending on the controller or machine.

CNC G Codes

G CodeFunctionDescription
G00Rapid positioningMoves the tool rapidly to a specified position
G01Linear interpolationCuts in a straight line at the programmed feed rate
G02Circular interpolation CWCuts an arc clockwise
G03Circular interpolation CCWCuts an arc counterclockwise
G04DwellPauses for a specified amount of time
G05High-speed/high-precision modeController-dependent; advanced contouring
G09Exact stopTemporarily forces an exact stop at the end of a block
G10Programmable data inputAllows offsets/settings to be programmed
G11Cancel programmable data inputCancels G10 mode
G12Circular pocket milling CWController-dependent
G13Circular pocket milling CCWController-dependent
G15Polar coordinates cancelCancels polar coordinate mode
G16Polar coordinate modeEnables polar coordinate programming
G17XY plane selectionSelects XY plane for circular interpolation
G18XZ plane selectionSelects XZ plane
G19YZ plane selectionSelects YZ plane
G20Inch programmingCoordinates interpreted in inches
G21Metric programmingCoordinates interpreted in millimeters
G28Return to machine zeroReturns machine to reference/home position
G30Return to 2nd/other reference pointReturns to an alternate machine reference position
G31Skip/probe functionUsed for probing or skip movements
G32Thread cuttingSynchronizes feed with spindle for threading
G33Thread cuttingController-dependent threading cycle
G40Cutter compensation cancelCancels tool-radius compensation
G41Cutter compensation leftApplies cutter compensation to the left of the programmed path
G42Cutter compensation rightApplies cutter compensation to the right
G43Tool length compensation +Applies positive tool-length offset
G44Tool length compensation −Applies negative tool-length offset; controller-dependent
G49Tool length compensation cancelCancels G43/G44
G50Scaling/spindle speed limitMeaning varies by controller; commonly cancels scaling or sets maximum spindle speed
G51ScalingEnables programmable scaling
G52Local coordinate systemEstablishes a temporary local coordinate shift
G53Machine coordinate systemExecutes movement using machine coordinates
G54Work coordinate system 1Selects work offset #1
G55Work coordinate system 2Selects work offset #2
G56Work coordinate system 3Selects work offset #3
G57Work coordinate system 4Selects work offset #4
G58Work coordinate system 5Selects work offset #5
G59Work coordinate system 6Selects work offset #6
G54.1 P1–P48Extended work offsetsAdditional work coordinate systems; availability varies
G61Exact stop modeCommands exact stopping/precision behavior
G61.1High-precision contour controlController-dependent
G64Cutting/continuous modeCancels exact-stop behavior on controllers that support it
G65Macro callCalls a custom macro/subprogram with arguments
G66Modal macro callCalls a macro repeatedly in subsequent blocks
G67Cancel modal macroCancels G66
G68Coordinate rotationRotates the coordinate system
G69Cancel coordinate rotationCancels G68
G70Finishing cycleFinishing cycle for turning
G71Rough turning cycleAutomatic roughing cycle
G72Facing roughing cycleRough-facing cycle
G73Pattern/peck drilling cycleMeaning varies between mill and lathe
G74Left-hand tapping / peck drillingFunction depends on machine
G75Grooving/peck cycleCommonly used for repetitive grooving on lathes
G76Threading cycleAutomatic multi-pass threading cycle
G80Canned cycle cancelCancels active drilling/boring cycle
G81Drilling cycleBasic drilling canned cycle
G82Spot drilling/counterboringDrilling cycle with dwell
G83Peck drillingDeep-hole drilling with retracts
G84Tapping cycleRight-hand tapping
G85Boring cycleBoring with feed in and feed out
G86Boring cycleBores then stops spindle/retracts
G87Back boring cycleBoring from the opposite side
G88Boring cycleController-dependent
G89Boring cycle with dwellBoring cycle with dwell
G90Absolute programmingCoordinates measured from the active work zero
G91Incremental programmingCoordinates measured from the current position
G92Coordinate/spindle settingMeaning varies; often coordinate-system or spindle-speed limiting function
G94Feed per minuteFeed specified in distance per minute
G95Feed per revolutionFeed specified per spindle revolution
G96Constant surface speedAutomatically varies spindle RPM to maintain surface speed
G97Constant RPMCancels constant surface speed
G98Return to initial pointCanned cycle returns to initial Z position
G99Return to R pointCanned cycle returns to the R-plane

Common Turning-Specific G Codes

G CodeFunctionDescription
G20Inch modeProgramming in inches
G21Metric modeProgramming in millimeters
G32Thread cuttingSingle-point threading
G50Spindle speed limitSets maximum RPM during CSS
G70Finishing cycleFinishes a previously defined roughing profile
G71Rough turningRemoves material from OD/ID profile
G72Rough facingRemoves material from a facing profile
G73Pattern repeating cycleRepeats a profile with controlled depth
G74Peck drillingCommon lathe drilling/pecking cycle
G75Grooving cycleRepetitive grooving/pecking
G76Multiple-pass threadingAutomatic threading cycle
G96Constant surface speedMaintains programmed surface speed
G97Constant spindle speedRPM remains fixed
G98Feed per minuteFeed specified in distance/minute
G99Feed per revolutionFeed specified in distance/revolution

Common Milling-Specific G Codes

G CodeFunctionDescription
G00RapidRapid tool movement
G01Linear interpolationStraight-line cutting
G02CW arcClockwise circular movement
G03CCW arcCounterclockwise circular movement
G17XY planeStandard milling plane
G18XZ planeXZ circular interpolation
G19YZ planeYZ circular interpolation
G40Cancel cutter compensationTurns off G41/G42
G41Cutter comp leftTool compensation left of path
G42Cutter comp rightTool compensation right of path
G43Tool length compensationApplies H offset
G49Cancel tool length compensationCancels G43
G54–G59Work offsetsSelects work coordinate system
G80Cancel canned cycleTurns off drilling cycle
G81DrillStandard drilling
G82Spot drillDrill with dwell
G83Peck drillDeep-hole drilling
G84TapRight-hand tapping
G85BoreFeed in/feed out boring
G86BoreSpindle stop before retract
G87Back boreBack boring
G88BoreController-dependent boring cycle
G89Bore with dwellBoring with dwell
G90AbsolutePosition from work zero
G91IncrementalPosition from current location
G94Feed/minuteF value represents distance/minute
G95Feed/revolutionF value represents distance/revolution
G98Initial-point returnCanned cycle returns to starting Z
G99R-plane returnCanned cycle returns to R-plane

 

M Code

CNC M-Codes

M-codes control machine functions rather than tool motion. Unlike G-codes, M-codes are heavily dependent on the machine builder and controller. The following are common Fanuc/Haas-style M-codes.

M Code

Function

Description

M00

Program stop

Stops program completely; operator must restart

M01

Optional stop

Stops only when optional-stop switch is enabled

M02

End of program

Ends program

M03

Spindle CW

Starts spindle clockwise

M04

Spindle CCW

Starts spindle counterclockwise

M05

Spindle stop

Stops spindle

M06

Tool change

Executes programmed tool change

M07

Mist coolant

Turns mist coolant on; machine-dependent

M08

Flood coolant

Turns flood coolant on

M09

Coolant off

Turns coolant off

M10

Chuck/clamp

Machine-dependent; commonly clamps

M11

Chuck/unclamp

Machine-dependent; commonly unclamps

M13

Spindle CW + coolant

Starts spindle CW and coolant

M14

Spindle CCW + coolant

Starts spindle CCW and coolant

M19

Spindle orientation

Orients spindle to a specified position

M21

Tailstock forward

Lathe-specific

M22

Tailstock reverse

Lathe-specific

M23

Chamfer/departure

Controller/machine-dependent

M24

Threading/chamfer function

Machine-dependent

M30

End and reset

Ends program and resets to beginning

M31

Chip conveyor forward

Starts chip conveyor; machine-dependent

M32

Chip conveyor reverse

Machine-dependent

M33

Chip conveyor stop

Machine-dependent

M41

Low gear

Selects low spindle gear

M42

High gear

Selects high spindle gear

M48

Override enabled

Enables feed/spindle overrides; controller-dependent

M49

Override disabled

Disables feed/spindle overrides

M51

Auxiliary output ON

Machine-builder dependent

M52

Auxiliary output OFF

Machine-builder dependent

M60

Pallet change

Executes pallet change on supported machines

M61

Fixture/clamp function

Machine-dependent

M62

Output ON

Turns programmable output on

M63

Output ON

Alternative programmable output

M64

Output OFF

Turns programmable output off

M65

Output OFF

Alternative programmable output

M66

Wait for input

Waits for an input signal; controller-dependent

M67

Analog output

Machine/controller-dependent

M68

Hydraulic chuck clamp

Common lathe function; machine-dependent

M69

Hydraulic chuck unclamp

Common lathe function; machine-dependent

M70

Mirror image

Controller-dependent

M71

Mirror image

Controller-dependent

M72

Mirror image cancel

Controller-dependent

M73

Mirror image cancel

Controller-dependent

M80

Auto door open

Machine-dependent

M81

Auto door close

Machine-dependent

M88

Through-spindle coolant ON

Turns TSC on

M89

Through-spindle coolant OFF

Turns TSC off

M97

Local subprogram call

Calls a local subprogram; common on Haas

M98

Subprogram call

Calls an external/local subprogram

M99

Subprogram return

Returns from subprogram; can also create a loop

M101+

Auxiliary functions

Machine-builder/controller dependent

Important: M-codes vary significantly

For example, M10 and M11 can mean chuck clamp/unclamp on one machine but something completely different on another. Likewise, M08 is commonly flood coolant, but additional coolant functions such as through-spindle coolant can use different codes depending on the manufacturer.

The same applies to G-codes. For example, G73 can represent a drilling cycle on a mill but a completely different cycle on a lathe.

The most important codes to memorize

If you’re learning CNC programming, I’d start with these:

Movement

  • G00 — Rapid

  • G01 — Linear cut

  • G02 — CW arc

  • G03 — CCW arc

Coordinates

  • G20 — Inch

  • G21 — Metric

  • G90 — Absolute

  • G91 — Incremental

  • G54–G59 — Work offsets

Tool compensation

  • G40 — Cancel cutter compensation

  • G41 — Cutter compensation left

  • G42 — Cutter compensation right

  • G43 — Tool length compensation

  • G49 — Cancel tool length compensation

Drilling

  • G80 — Cancel canned cycle

  • G81 — Drill

  • G82 — Drill with dwell

  • G83 — Peck drill

  • G84 — Tap

Spindle/cutting

  • G94 — Feed per minute

  • G95 — Feed per revolution

  • G96 — Constant surface speed

  • G97 — Constant RPM

Machine functions

  • M00 — Program stop

  • M01 — Optional stop

  • M03 — Spindle CW

  • M04 — Spindle CCW

  • M05 — Spindle stop

  • M06 — Tool change

  • M08 — Coolant on

  • M09 — Coolant off

  • M30 — End/reset

  • M98 — Subprogram call

  • M99 — Subprogram return

Note: This is a practical reference, not a universal controller manual. For actual machining, the specific control’s programming manual (e.g., Haas NGC, Fanuc 0i/31i, Siemens SINUMERIK, Mitsubishi, LinuxCNC) should take precedence because unsupported or differently defined codes can cause unexpected machine behavior.