Education | Career | Guidance

Search This Blog

CNC G-Codes Explained with Examples and Real Programs (Beginner Guide)

Introduction

G-codes are the foundation of CNC programming. They control the movement of the tool and define how machining operations are performed.

Based on my experience working with CNC machines, not all G-codes are used regularly in practical machining. In this guide, we focus on the top 25 most important G-codes that every CNC operator and student must understand for practical machining.

Why G-Codes Matter in Real Machining

In real shop-floor conditions, improper use of G-codes can lead to tool breakage, poor surface finish, or even machine crashes. From my experience, most beginners make mistakes not because they don’t know the codes but because they don’t understand when and how to use them correctly.

Top 25 G-Codes – Quick Reference Table

G-Code

Function

G00

Rapid positioning

G01

Linear interpolation

G02

Clockwise arc

G03

Counterclockwise arc

G17

XY plane

G18

XZ plane

G19

YZ plane

G90

Absolute mode

G91

Incremental mode

G94

Feed per minute

G95

Feed per revolution

G96

Constant surface speed

G97

Fixed RPM

G54

Work offset

G71

Rough turning cycle

G72

Facing cycle

G73

Pattern repeating

G74

Peck drilling

G76

Threading cycle

G28

Machine home return

G40

Cancel tool comp

G41

Tool compensation left

G42

Tool compensation right

G50

Spindle limit

G92

Threading / preset

Basic Motion G-Codes

1.     G00 – Rapid Positioning

·       Used for fast, non-cutting movement.

·       G00 X50.0 Z5.0;

Mistake: Using near the workpiece may cause a tool crash.

2.     G01 – Linear Interpolation

·       Used for straight cutting movement.

·       G01 X30.0 Z-10.0 F0.2;

Mistake: Forgetting the feed rate.

3.     G02 & G03 – Circular Interpolation

·        G02 → Clockwise arc

·        G03 → Counterclockwise arc

 Mistake: Selecting the wrong plane results in an incorrect arc.

4.     Plane Selection

·        G17 / G18 / G19

·        G17 → XY plane

·        G18 → XZ plane (used in turning)

·        G19 → YZ plane

Mistake: Wrong plane causes wrong tool path.

5.     Positioning Modes

·        G90 – Absolute Mode: Coordinates from a fixed zero.

·        G91 – Incremental Mode: Coordinates from the current position.

Mistake: Confusing G90 & G91 leads to major errors.

6.     Feed Control

·        G94 – Feed per minute

·        G95 – Feed per revolution

Mistake: Wrong mode affects surface finish and tool life

7.     Speed Control

·        G96 – Constant Surface Speed: Automatically adjusts RPM.

·        G97 – Fixed RPM: Always use G50 with G96 to limit speed.

8.     Work Offsets

·        G54 (and G55–G59)

·        Defines work coordinate system.

Mistake: Incorrect offset leads to an incorrect machining position.

9.     Turning Cycles

·        G71 – Rough Turning Cycle: Used for rough cutting profiles.

·        G72 – Facing Cycle: Used for facing operations.

·        G73 – Pattern Repeating: Used for repeating patterns.

·        G74 – Peck Drilling: Used for deep drilling with chip breaking.

·        G76 – Threading Cycle: Used for automatic threading.

10.  Machine Control

·        G28 – Return to Home

·        G28 U0.0 W0.0;

Mistake: A direct move can cause a crash.

11.  Tool Compensation

·        G40 / G41 / G42

·        G40 → Cancel compensation

·        G41 → Left compensation

·        G42 → Right compensation

     12.    Safety Codes

·        G50 – Spindle Speed Limit: Very important when using G96.

·        G92 – Threading / Position Set: Used for threading or setting position.

Example CNC Program

O1987;

G21 G90 G54;

G00 X50.0 Z5.0;

G96 S150 M03;

G50 S2000;

G01 X30.0 Z-10.0 F0.2;

G00 X50.0;

G71 U2.0 R1.0;

G71 P10 Q20 U0.2 W0.1 F0.25;

N10 G00 X40.0;

N20 G01 Z-30.0;

G00 Z5.0;

M30;

Common Mistakes (Very Important )

·        Using G00 instead of G01

·        Not setting the feed rate

·        Wrong plane selection

·        Not limiting speed in G96

·        Wrong offset usage

Conclusion

Understanding these 25 G-codes is essential for every CNC operator. Instead of memorising all codes, focus on practical usage, examples, and safety. Mastering these will improve your programming skills, machining quality, and confidence on the shop floor.

Note: “I strongly request that all the above programs be carefully checked and dry-run before execution to prevent tool damage or machine errors.”

Frequently Asked Questions

1. What are G-codes in CNC?
G-codes are programming instructions used to control the movement and operation of CNC machines.

2. Which G-code is most important?
G00, G01, G96, G71, and G72 are widely used.

3. Why is G50 important?
It limits spindle speed and prevents machine damage.

4. Why are G-codes important in CNC machining?
They define tool movement, cutting operations, speed, and positioning, making them essential for accurate machining.

5. What is the difference between G00 and G01?
G00 is used for rapid (non-cutting) movement, while G01 is used for controlled cutting with a specified feed rate.

6. What is the difference between G02 and G03?
G02 is used for clockwise circular interpolation, while G03 is used for counterclockwise circular movement.

7. What is the difference between G90 and G91?
G90 uses absolute coordinates from a fixed reference point, while G91 uses incremental coordinates from the current position.

8. What is the use of G96 and G97?
G96 is used for constant surface speed, and G97 is used for fixed spindle speed (RPM).

9. Why is G50 important in CNC programming?
G50 limits the maximum spindle speed, which is especially important when using G96 to prevent machine damage.

10. What is the function of G54 in CNC machines?
G54 is used to set the work coordinate system, defining the position of the workpiece.

11. What are canned cycles like G71 and G72?
Canned cycles are pre-programmed operations used to simplify repetitive tasks such as rough turning (G71) and facing (G72).

12. What are common mistakes while using G-codes?
Common mistakes include using G00 near the workpiece, forgetting the feed rate in G01, wrong plane selection in G02/G03, and not setting spindle limits in G96
.