The Ultimate Guide to Standard G-Codes and M-Codes For Milling

CNC machining is the backbone of modern manufacturing. As a seasoned CNC machinist, I can tell you that these magical codes breathe life into the CNC machines, guiding their every move. Let’s dive into this treasure trove and unearth the secrets of standard G-Codes and M-Codes. Keep in mind these codes are focused on CNC milling.

You can learn about how to read and write g-codes from here.

You can find G-Codes and M-Codes for turning from here.

For specific machine language codes, you need to check your machine`s manufacturer guide.

G-Codes: Geometrical movement codes

G-Codes, my friends, are like the conductor of an orchestra. They dictate the movements, the rhythm, and the flow. Here’s a nifty table to get you started:

G-CodeDescriptionPossible Parameters
G00Rapid positioningX, Y, Z
G01Linear interpolation (Straight line move)X, Y, Z, F
G02Circular interpolation (Clockwise)X, Y, Z, I, J, K, F
G03Circular interpolation (Counterclockwise)X, Y, Z, I, J, K, F
G04Dwell (Pause)P or X
G09Exact stop checkNone
G10Programmable data inputL, P, X, Y, Z
G17XY plane selectionNone
G18ZX plane selectionNone
G19YZ plane selectionNone
G20Programming in inchesNone
G21Programming in millimetersNone
G28Return to the secondary home positionX, Y, Z
G30Return to the secondary home positionX, Y, Z
G31Return to the secondary home positionX, Y, Z, F
G32Threading with a single-point toolX, Z, F
G33Constant pitch threadingK, Z, F
G40Cutter compensation cancelNone
G41Cutter compensation leftD
G42Cutter compensation rightD
G43Tool length compensation positiveH, Z
G44Tool length compensation negativeH, Z
G49Cancel tool length compensationNone
G53Machine coordinate systemNone
G54Workpiece coordinate system 1None
G55Workpiece coordinate system 2None
G56Workpiece coordinate system 3None
G57Workpiece coordinate system 4None
G58Workpiece coordinate system 5None
G59Workpiece coordinate system 6None
G61Exact stop modeNone
G64Cutting modeP
G73High-speed peck drilling cycleR, Z, Q, F
G76Fine boring cycleZ, R, P, Q, F
G80Cancel canned cycleNone
G81Simple drilling cycleR, Z, F
G82Counter boring cycleR, Z, P, F
G83Peck drilling cycleR, Z, Q, F
Standard common G-Codes used with parameters in CNC programming.

M-Codes: The Puppet Masters

M-Codes are like puppet masters controlling the machine’s states. Spindles, coolant, you name it! They turn things on and of, and they are more functional.

M-CodeDescriptionPossible Parameters
M00Program stopNone
M01Optional program stopNone
M02End of programNone
M03Spindle start (clockwise)S (speed)
M04Spindle start (counterclockwise)S (speed)
M05Spindle stopNone
M06Tool changeT (tool number)
M07Coolant on (mist)None
M08Coolant on (flood)None
M09Coolant offNone
M13The spindle on (counterclockwise) with coolant onS (speed)
M14The spindle is on (counterclockwise) with coolant onS (speed)
M19Spindle orientationNone
M21Mirror image X-axis onNone
M22Mirror image X-axis offNone
M23Mirror image Y-axis onNone
M24Mirror image Y-axis offNone
M30Program end and resetNone
M98Call subprogramP (program number), L (number of repeats)
M99End of subprogramNone
Standard common M-Codes used with parameters in CNC programming

Controller-Specific Variations

Different controllers have their own flavors of G-Codes and M-Codes. Variety is the spice of life, isn’t it? From my experience, I can say that easily most of the codes are the same, but some manufacturers have special M-codes and G-codes.

For example, some of the codes I found very helpful;

  • G05.1 Q1: I used this code on Fanuc Milling controller-OM to activate highspeed machining mode with high precision mode. Machined parts are more precise with this mode and the controller also looks ahead automatically to smoothen movements.
  • G08 P1: On Fanuc Milling controller-OM & Mitsubishi controller is a mode you can cancel very sharp movements to increase preciseness. But the program will move more slowly than before.

Mazak

Mazak, the maverick, has its own variation called Mazatrol. It’s like having a friendly chat with your machine.

Mazak Specific G-Codes, M-Codes(Milling)

CodeDescription
G12.1Polar coordinate interpolation mode on
G14Scaling on
G15Polar coordinate interpolation mode off
G22Stored stroke limit on
G23Stored stroke limit off
G31Skip function
G35Coordinate system rotation on
G37Coordinate system rotation off
G68Mirror image on
G69Mirror image off
G135Cylindrical interpolation cancel
G136Cylindrical interpolation (X-axis)
Special, Specific G codes for Mazak
CodeDescription
M26Spindle gear range change, high gear
M27Spindle gear range change, low gear
M30End of the subprogram, wrap it up
M36Automatic door open, let the breeze in
M37Automatic door close, keep the secrets safe
M38Chip conveyor forward, keep it moving
M39Chip conveyor reverse, back it up
M48Cancel override, back to normal
M49Enable override, take control
M97Local subprogram call, let’s get specific
M98Call external subprogram, bring in the cavalry
M99End of subprogram, wrap it up
Special, Specific M-codes for Mazak

Siemens Specific G-Codes, M-Codes(milling)

Siemens, the stalwart, with its SINUMERIK series, is all about precision and finesse.

CodeDescription
G70Finishing cycle
G73Pattern repeating cycle
G74Face grooving or drilling
G75Outer/internal longitudinal grooving
G76Fine boring cycle
G96Constant cutting speed on
G97Constant cutting speed off
Special, Specific G-Codes for Siemens
CodeDescription
M17Chip the conveyor off, hold the debris
M21External M-function, the wild card
M22Spindle cooling on, keep it frosty
M23Spindle cooling off, let it heat
M25Engage the clamping device, lock it down
M26End of the program with reset, the final bow
M29High-speed spindle mode, turbocharge it
M30Chip the conveyor off, hold the debris
M38Chip conveyor on, clear the stage
M39Chip the conveyor off, hold the debris
M50Override cancel, back to basics
M51Feedrate override, take the reins
M52Rapid traverse override, speed it up or slow it down
M53Spindle override, control the spin
Special, Specific M-codes for Siemens

Fanuc Specific G-Codes, M-Codes(milling)

Fanuc, the workhorse, is everywhere. It’s like the bread and butter of CNC controllers.

CodeDescription
G10Programmable offset setting
G11Programmable offset cancel
G28Return to the reference point
G30Return to 2nd, 3rd, or 4th reference point
G92Threading cycle with no-load constant pitch
G96Constant surface speed on
G97Constant surface speed off
Special, Specific G-codes for Fanuc
CodeDescription
M19Spindle orientation, get it just right
M21Mirror image X-axis on, like a reflection in the water
M22Mirror image X-axis off, back to the original
M26Spindle gear range change, like shifting gears on a mountain bike
M29High-speed spindle mode, unleash the fury
M41Low gear range, like treading carefully
M42High gear range, pedal to the metal
M52Single-direction positioning, like an arrow flying straight
M53Disable override, stick to the plan
M61Set constant surface speed, smooth as silk
M62Single-direction positioning, like an arrow flying straight
Special, Specific M-codes for Fanuc

Conclusion

The best code is your machine’s specific code, so please check the guides if you have one. You should test these codes on MDI mode before using them on a real workpiece.

By Isaac Aloyan

Isaac Aloyan is a talented mechanical engineer with a background in machinery design and manufacturing. He completed his diploma from the Department of Machinery Design and Manufacturing at Kocaeli University and also graduated from Level 7 NZDE Mechanical Engineering at Manukau Institute of Technology (M.I.T). Isaac has developed strong expertise in various areas of mechanical engineering, including CNC programming and machining, vacuum mold design and production, manual machining, CAD and CAM, and thermoforming machine design and production. Also, he has educator experience in the area of CNC machinery and programming and mechanical design. With two decades of experience under his belt, Isaac has established a website called mechutopia.com to share his knowledge and help others who are interested in the field of mechanical engineering. The site is likely to feature a wealth of information, resources, and tips for those looking to learn about CNC machines, machining, mold production, and more. It is a testament to Isaac's dedication to the field and his commitment to helping others excel in sub-domains of mechanical engineering like design and manufacturing.