LinuxCNC G Codes M Codes Functions

LinuxCNC is a software system for computer control of machine tools such as milling machines and lathes.
LinuxCNC is free software with open source code.
LinuxCNC provides, several graphical user interfaces including one for touch screens.


G Codes

G CodeDescription
G0Rapid Linear Motion
G1Linear Feed
G2CW Arc Feed
G3CCW Arc Feed
G5.1Quadratic B-Spline
G5.2 G5.3NURBs Block
G7Diameter Mode (lathe)
G8Radius Mode (lathe)
G10 L1Set Tool Table Entry
G10 L10Set Tool Table, Calculated, Workpiece
G10 L11Set Tool Table, Calculated, Fixture
G10 L2Coordinate System Origin Setting
G10 L20Coordinate System Origin Setting Calculated
G17XY Plane
G18ZX Plane
G19YZ Plane
G17.1UV Plane
G18.1WU Plane
G19.1VW Plan
G20Inch Units
G21Millimeter Units
G28Go to Predefined Position
G28.1Store Current Absolute Position for G28
G30Go to Predefined Position
G30.1Store Current Absolute Position for G30
G33Spindle Synchronized Motion
G33.1Rigid Tapping
G38.2 – G38.5Probing
G38.2Probe toward workpiece, stop on contact, signal error if failure
G38.3Probe toward workpiece, stop on contact
G38.4Probe away from workpiece, stop on loss of contact, signal error if failure
G38.5Probe away from workpiece, stop on loss of contact
G40Cutter Compensation Cancel
G41Cutter Compensation Left of Path
G42Cutter Compensation Right of Path
G41.1Dynamic Cutter Compensation Left of Path
G42.1Dynamic Cutter Compensation Right of Path
G43Tool Length Offset
G43.1Dynamic Tool Length Offset
G49Cancel Tool Length Offset
G53Motion in Machine Coordinate System
G54Select Coordinate System 1
G55Select Coordinate System 2
G56Select Coordinate System 3
G57Select Coordinate System 4
G58Select Coordinate System 5
G59Select Coordinate System 6
G59.1Select Coordinate System 7
G59.2Select Coordinate System 8
G59.3Select Coordinate System 9
G61Exact Path Mode (Path Control Mode)
G61.1Exact Path Mode (Path Control Mode)
G64Path Control Mode with Optional Tolerance
G73Drilling Cycle with Chip Breaking
G76Multi-pass Threading Cycle (Lathe)
G80Cancel Canned Cycle
G81Drilling Cycle
G82Drilling Cycle with Dwell
G83Peck Drilling Cycle
G85Boring Cycle, Feed Out
G86Boring Cycle, Spindle Stop, Rapid Out
G89Boring Cycle, Dwell, Feed Out
G90Absolute Distance Mode
G91Incremental Distance Mode
G90.1Absolute Distance Mode for Arc (I, J & K offsets)
G91.1Incremental Distance Mode for Arc (I, J & K offsets)
G92Coordinate System Offset
G92.1Cancel Coordinate System Offsets
G92.2Cancel Coordinate System Offsets
G92.3Restore Axis Offsets
G93Inverse Time Mode
G94Units per Minute Mode
G95Units per Revolution Mode
G96Constant Surface Speed
G97RPM Mode
G98Retract to Start Position (Canned Cycle Z Retract Mode)
G99Retract to R Position (Canned Cycle Z Retract Mode)

M Codes

M CodeDescription
M0 M1Program Pause
M2 M30Program End
M60Pallet Change Pause
M3 M4 M5Spindle Control
M6Tool Change
M7 M8 M9Coolant Control
M48 M49Feed / Spindle Overrides Enable/Disable
M50Feed Override Control
M51Spindle Override Control
M52Adaptive Feed Control
M53Feed Stop Control
M61Set Current Tool Number
M62-M65Output Control
M66Input Control
M67Analog Output Control
M68Analog Output Control
M100-M199User Defined M codes

Binary Operators

ORNon-exclusive or
XORExclusive or
ANDLogical and
MODModulus operation
**Power operation
EQEquality (EQ)
NEInequality (NE)
GTStrictly greater than
GEGreater than or equal to
LTStrictly less than
LELess than or equal to


Function NameFunction Result
ATAN[Y]/[X]Four quadrant inverse tangent
ABS[arg]Absolute value
ACOS[arg]Inverse cosine
ASIN[arg]Inverse sine
EXP[arg]e raised to the given power
FIX[arg]Round down to integer
FUP[arg]Round up to integer
ROUND[arg]Round to nearest integer
LN[arg]Base-e logarithm
SQRT[arg]Square Root
EXISTS[arg]Check named Parameter

Words Letters

AA axis of machine
BB axis of machine
CC axis of machine
DTool radius compensation number
FFeed rate
GGeneral function (See table Modal Groups)
HTool length offset index
IX offset for arcs and G87 canned cycles
JY offset for arcs and G87 canned cycles
KZ offset for arcs and G87 canned cycles.
Spindle-Motion Ratio for G33 synchronized movements.
MMiscellaneous function (See table Modal Groups)
NLine number
PDwell time in canned cycles and with G4.
Key used with G10.
QFeed increment in G73, G83 canned cycles
RArc radius or canned cycle plane
SSpindle speed
TTool selection
UU axis of machine
VV axis of machine
WW axis of machine
XX axis of machine
YY axis of machine
ZZ axis of machine
/Block delete

Common Error Messages

G code out of range
A G code greater than G99 was used, the scope of G codes in LinuxCNC is 0 – 99. Not every number between 0 and 99 is a valid G code.

Unknown g code used
A G code was used that is not part of the LinuxCNC G code language.

i,j,k word with no Gx to use it
i, j and k words must be used on the same line as the G code.

Cannot use axis values without a g code that uses them
Axis values can not be used on a line without either a modal G code in effect or a G code on the same line.

File ended with no percent sign or program end
Every G code file must end in a M2 or M30 or be wrapped with the percent sign %.