Post · 8 min read· pp. 278–282

G-code and M-code List with Examples and Tutorials

Complete CNC G-code list with M-codes for milling in the Fanuc, LinuxCNC, GRBL, and Haas CNC machines dialects.  We give a quick definition for all G-codes along with a link to tutorials and examples of how to use it in CNC programming.  Click the G-code link (if any) to visit a tutorial from our popular Online Free G-code Training that shows examples and teaches how to program CNC machines using the G-code commands.  This page is your ideal G-code reference.

G-code List

CodeCategoryFunctionNotes
G00MotionRapid: Move in a straight line at rapid speed.XYZ of endpoint
G01MotionMove in a straight line at last speed commanded by a (F)eedrateXYZ of endpoint
G02MotionCircular Interpolation: Clockwise circular arc at (F)eedrateXYZ of endpoint IJK relative to center R for radius
G03MotionCircular Interpolation: Counter-clockwise circular arc at (F)eedrateXYZ of endpoint IJK relative to center R for radius
G04MotionDwell: Stop for a specified time.P for milliseconds X for seconds
G05MotionFADAL Non-Modal Rapids
G09MotionExact stop check
G10CompensationProgrammable parameter input
G15CoordinateTurn Polar Coordinates OFF, return to Cartesian Coordinates
G16CoordinateTurn Polar Coordinates ON
G17CoordinateSelect X-Y plane (Plane Selection)
G18CoordinateSelect X-Z plane (Plane Selection)
G19CoordinateSelect Y-Z plane (Plane Selection)
G20CoordinateProgram coordinates are inches
G21CoordinateProgram coordinates are mm
G27MotionReference point return check
G28MotionReturn to home position
G29MotionReturn from the reference position
G30MotionReturn to the 2nd, 3rd, and 4th reference point
G32CannedConstant lead threading (like G01 synchronized with spindle)
G40CompensationTool cutter compensation off (radius comp.)
G41CompensationTool cutter compensation left (radius comp.)
G42CompensationTool cutter compensation right (radius comp.)
G43CompensationApply tool length compensation (plus)
G44CompensationApply tool length compensation (minus)
G49CompensationTool length compensation cancel
G50CompensationReset all scale factors to 1.0
G51CompensationTurn on scale factors
G52CoordinateLocal workshift for all coordinate systems: add XYZ offsets
G53CoordinateMachine coordinate system (cancel work offsets)
G54CoordinateWork coordinate system (1st Workpiece)
G55CoordinateWork coordinate system (2nd Workpiece)
G56CoordinateWork coordinate system (3rd Workpiece)
G57CoordinateWork coordinate system (4th Workpiece)
G58CoordinateWork coordinate system (5th Workpiece)
G59CoordinateWork coordinate system (6th Workpiece)
G61OtherExact stop check mode
G62OtherAutomatic corner override
G63OtherTapping mode
G64OtherBest speed path
G65OtherCustom macro simple call
G68CoordinateCoordinate System Rotation
G69CoordinateCancel Coordinate System Rotation
G73CannedHigh speed drilling cycle (small retract)
G74CannedLeft hand tapping cycle
G76CannedFine boring cycle
G80CannedCancel canned cycle
G81CannedSimple drilling cycle
G82CannedDrilling cycle with dwell (counterboring)
G83CannedPeck drilling cycle (full retract)
G84CannedTapping cycle
G85CannedBoring cycle, no dwell, feed out
G86CannedBoring cycle, spindle stop, rapid out
G87CannedBack boring canned cycle
G88CannedBoring canned cycle, spindle stop, manual out
G89CannedBoring canned cycle, dwell, feed out
G90CoordinateAbsolute programming of XYZ (type B and C systems)
G90.1CoordinateAbsolute programming IJK (type B and C systems)
G91CoordinateIncremental programming of XYZ (type B and C systems)
G91.1CoordinateIncremental programming IJK (type B and C systems)
G92CoordinateOffset coordinate system and save parameters
G92 (alternate)MotionClamp of maximum spindle speedS
G92.1CoordinateCancel offset and zero parameters
G92.2CoordinateCancel offset and retain parameters
G92.3CoordinateOffset coordinate system with saved parameters
G93MotionInverse Time Feed Mode. For use with rotary axes
G94MotionUnits per minute feed mode. Units in inches or mm
G95MotionUnits per revolution feed mode. Units in inches or mm
G96MotionConstant surface speed
G97MotionCancel constant surface speed
G98CannedReturn to initial Z plane after canned cycle
G99CannedReturn to initial R plane after canned cycle

M-code List

Some Thoughts on G-codes and M-codes

G-codes and M-codes are the basic programming language used by most CNC Machines.  These same G-codes are probably the ones used by your CNC machine.

Most cnc programming of G-codes and M-codes is done using Computer Aided Manufacturing (CAM) Software.  If you are able to program directly in G-codes and M-codes, you can do things that CAM software cannot.  These things will make you a more productive CNC'er.  Being able to control cnc machines at this level is one thing that can give machine shops competitive advantage.

More In-Depth CNC Guides

If you're a CNC beginner, check out our CNC Beginner's Cookbook. It'll get you up to speed with a solid CNC foundation fast.

We also have Cookbooks for Feeds and Speeds, G-code Programming, CNC Manufacturing and Shop Management, DIY CNC, and don't forget the CNC Cookbook Blog-with over 4 million visitors a year it's the most popular CNC blog by far on the web.

More Resources

Mazatrol Training Classes

Fanuc CNC Training Classes

G-code Commands FAQ

How many G-codes are there in cnc machining?

There are about 100 G-code commands, give or take.  There are many dialects of G-code, and some have proprietary G-codes.

What are G-codes in CNC Machines?

This page lists all the G-code commands used in CNC programming and tells what they do.  It also gives links to tutorials and examples.  G-codes are single-letter commands that tell the CNC machine what to do.  They may command motion (i.e. tell the machine where to cut) or do things like turn the spindle on or off.

Is learning G-code hard?

Learning G-code isn't very hard.  We have a complete free online G-code tutorial to teach you and a G-code simulator that makes learning easy.

Why are G-codes used?

G-codes make CNC Machines programmable, which gives them the flexibility to make almost any part.

What is the difference between G-codes and M-codes?

The G in G-codes stands for Geometry, which means giving the CNC Machine directions on how and where to move.  The four simplest motion-related G-codes are:

  • G00:  Move at the machine's fastest speed in a straight line to the commanded coordinates.
  • G01:  Move at the last commanded feedrate (commanded by the "F" word) in a straight line to the commanded coordinates.
  • G02:  Move in a clockwise arc to the commanded coordinates at the last commanded feedrate.
  • G03:  Move in a counterclockwise arc to the commanded coordinates at the last commanded feedrate.

M-codes are about Machine functions on the CNC machine.

Do all CNC machines use G-code?

Not all CNC machines use G-code.  Some CNC machines may have both G-code and other ways of programming, for example, alternate languages such as Mazak's Mazatrol or Conversational Programming.  Others may have an alternate language and no ability to execute G-code at all.