Email Us
en

M Code / G Code List – The CNC Programming Essentials Explained

Table of Content [Hide]

    Whether you’re a CNC machinist, programmer, or manufacturer looking to optimize production, understanding M codes and G codes is non-negotiable. These two types of commands form the foundation of CNC programming, enabling precise control of machine operations like cutting, tool changes, coolant flow, and motion paths.

    This article provides a comprehensive guide to common G and M codes, how they function, and where they're used—especially within FANUC-controlled CNC systems.


    What Are G Codes and M Codes?

    • G Codes (Geometric Codes) define machine movement and tool paths.

    • M Codes (Miscellaneous Codes) handle machine functions such as turning on coolant, stopping the spindle, or tool changing.

    Think of it this way:

    • G codes = How the machine moves.

    • M codes = What the machine does while moving (or before/after).

    Both are essential for a successful CNC program.


    G Code List – Common Geometric Commands

    G CodeFunctionDescription
    G00Rapid positioningMoves tool quickly from point to point without cutting
    G01Linear interpolationMoves tool in a straight line at a set feed rate
    G02Circular interpolation (clockwise)Cuts arcs or circles in a clockwise direction
    G03Circular interpolation (counter-clockwise)Cuts arcs or circles counter-clockwise
    G04DwellPauses the machine for a set time
    G17Select XY planeDefault plane for 2D machining
    G18Select ZX planeUseful in turning centers
    G19Select YZ planeFor vertical or sidewall machining
    G20Inch unitsSets machine units to inches
    G21Metric unitsSets machine units to millimeters
    G28Return to machine zeroSends tool to home position
    G40Cancel cutter compensationTurns off tool radius offset
    G41Cutter compensation leftOffsets tool to the left of path
    G42Cutter compensation rightOffsets tool to the right of path
    G43Tool length compensation +Compensates for tool height
    G49Cancel tool length compensationResets tool length offset
    G54 – G59Work coordinate systemsAllows multiple part setups
    G80Cancel canned cycleStops any active drilling cycle
    G81Drilling cycleBasic vertical drilling operation
    G82Drilling with dwellPauses at bottom of drill before retract
    G83Peck drilling cycleBreaks chips while drilling deep holes
    G90Absolute programmingCoordinates based on part origin
    G91Incremental programmingCoordinates based on last position
    G94Feed per minuteFeed rate in mm/min or in/min
    G95Feed per revolutionFeed rate based on spindle RPM

    Note: G codes can vary slightly depending on the machine type (mill vs. lathe) and the controller (FANUC, Siemens, Haas, etc.)


    M Code List – Common Machine Function Commands

    M CodeFunctionDescription
    M00Program stopStops machine until manually restarted
    M01Optional stopStops only if optional stop is enabled
    M02Program endEnds the program
    M03Spindle on (CW)Starts spindle clockwise
    M04Spindle on (CCW)Starts spindle counter-clockwise
    M05Spindle stopStops the spindle rotation
    M06Tool changeAutomatically changes to next tool
    M08Coolant onActivates coolant flow
    M09Coolant offStops coolant flow
    M30Program end and rewindEnds program and resets to the top
    M98Call subprogramRuns a separate subroutine
    References
    Weite Welcomes Your Inquiries for More Fanuc Parts
    Talk to Us
    Need Fanuc Parts Details?
    Weite Welcomes Your Inquiries for More Fanuc Parts
    East side of the 2nd floor, Building B, No. 333, Heting Street, Qingshan Lake Street, Hangzhou
    Weite Welcomes Your Inquiries for More Fanuc Parts
    Talk to Us
    East side of the 2nd floor, Building B, No. 333, Heting Street, Qingshan Lake Street, Hangzhou
    fanucalex@gmail.com +8613858013242
    Need Fanuc Parts Details?
    Weite Welcomes Your Inquiries for More Fanuc Parts