CNC G-Code Examples Every Beginner Must Know

G-Code is essential for anyone starting out in CNC machining. G-Code is the language that tells the machine where to move, how fast to move, and what path to follow.

Here are the foundational G-Code examples every beginner must know, covering standard motion commands and canned cycles.

1. Safe Startup and Initialization Block

This is a very important part of programming. Whenever a new program is started, the purpose of this block is to bring the machine settings to a safe and known state so that no accidents or errors occur due to any previous incorrect settings or modes.

G21 G90 G40 G80

  • G21: Sets all program units to millimeters (if working in inches, G20 is used instead)
  • G90: Absolute positioning mode (coordinates are relative to the workpiece origin).
  • G40: Cutter radius compensation cancel.
  • G80: Canned cycle cancel (stops any active drilling/tapping cycles).

2. Rapid Positioning (G00)

The G00 command is used to move the CNC machine tool from one point to another at very high speed without cutting material (non-cutting move). This command operates at the maximum possible speed of the machine (rapid traverse rate), not at the feed rate.

G00 X0 Y0 Z50.0

  • G00: Rapid traverse.
  • X0 Y0 Z50.0: Moves the tool to the X and Y origin and raises the Z-axis to a safe height of 50 mm above the part.

3. Linear Interpolation / Cutting Feed (G01)

G01 is the most commonly used and most important command in CNC machining. It is used to cut material by moving the tool in a straight line at a controlled and set speed (feed rate).

G01 X50.0 Y25.0 F200

  • G01: Linear feed move.
  • X50.0 Y25.0: These are the target coordinates where the tool has to reach while cutting the material.
  • F200: There is a feed rate, which specifies how fast the tool will move (for example, 200 millimeters per minute or inches per minute).

Unlike G00, which is only for moving from one place to another at high speed without cutting, with G01 it is always necessary to give a feed rate (F command) so that the tool can cut the material accurately.

4. Circular Interpolation (G02 / G03)

These commands are used for cutting arcs and circles in a CNC machine. They cause the tool to move in a specific curve instead of a straight line.

G02 (Clockwise Arc):
This command moves the tool in a clockwise direction in a circle or arc.

G03 (Counter-Clockwise Arc):
This command moves the tool in a counter-clockwise direction.

G03 X30.0 Y30.0 R15.0 F150

  • G03: Move in a counter-clockwise arc.
  • X30.0 Y30.0: The end point of the arc where the tool has to reach.
  • R15.0: The radius of the arc (remember that in addition to the radius, the I and J parameters are also used to specify the center).
  • F150: Feed rate during the arc cut.

5. Simple Drilling Canned Cycle (G81)

Canned Cycles make repetitive tasks (such as drilling, boring, or tapping) much easier in CNC programming. Instead of having to write multiple lines of code for each hole, you can complete the entire drilling process in a single line.

G99 G81 Z-15.0 R2.0 F100

  • G81: This tells the machine to start a straight drilling operation. It will bring the tool down quickly, drill the hole at the set speed, and then bring it back up.
  • Z-15.0: Total depth of the hole.
  • R2.0: Return plane (the Z height the tool retracts to before moving to the next hole).
  • G99: Returns the tool to the R-plane after each hole (use G98 to return to the initial starting Z plane).
  • F100: Plunge feed rate.

6. Program End and Reset (M30)

This command is used at the very end of the program. When the machine reads this command, it automatically stops the cutting spindle, turns off the coolant flow, and resets the program pointer back to the first step. Its main purpose is to tell the machine that all operations have been completed and it is now ready for the next command or a new part.

M30

  • M30: End of program and reset rewind.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *