The Fastest China Rapid Prototype,Small To Large Batch Manufacturer to Bring Your Ideal Project to Life - Be-Cu Discover Our Top Manufacturing Wiki And Guide in 2024 Eamil us : [email protected]

G-code Function Programming Of CNC Machine Tools, Detailed Function Explanation, Programming Examples, And Precautions

G codes are instructions in the NC program. Generally known as the G command.

  • Code function
  • Function details
  • Examples
  • Program name: P10
  • G331—Thread machining cycle
  • Example:
  • Notes

Code Function Editor

  • Code Name – Function Brief
  • G00 – quick positioning
  • G01——Linear interpolation
  • G02——Clockwise circular interpolation
  • G03——Counterclockwise circular interpolation
  • G04 – Timed Pause
  • G05——Circular interpolation through intermediate point
  • G06——Parabolic interpolation
  • G07——Z spline interpolation
  • G08——feed acceleration
  • G09——Feed Deceleration
  • G10 – Data Settings
  • G16 – Polar Coordinate Programming
  • G17——Processing XY plane
  • G18——Processing XZ plane
  • G19——Processing YZ planeG20 – Inch size (Frank system)
  • G21 – Metric Dimensions (Frank System)
  • G22——Radius dimension programming method
  • G220——–Used on the system operation interface
  • G23——Diameter dimension programming method
  • G230——–Used on the system operation interface
  • G24 – end of subroutine
  • G25——Jump processing
  • G26——Cycle Machining
  • G30 – Override cancellation
  • G31——Override Definition
  • G32——Equal pitch thread cutting, inch
  • G33 – Equal Pitch Thread Cutting, Metric
  • G34——Increased pitch thread cutting
  • G35——Reduced pitch thread cutting
  • G40——Tool compensation/tool ​​offset cancellation
  • G41 – Tool Compensation – Left
  • G42 – Tool Compensation – Right
  • G43 – Tool Offset – Positive
  • G44 – Tool Offset – Negative
  • G45——Tool offset++/+
  • G46 – Tool Offset +/-
  • G47——Tool offset-/-
  • G48——Tool offset -/+
  • G49——Tool offset 0/+
  • G50——Tool offset 0/-
  • G51——Tool offset+/0
  • G52——Tool offset-/0
  • G53——Linear offset, log off
  • G54——Set workpiece coordinates
  • G55——Set workpiece coordinate 2
  • G56——Set workpiece coordinate three
  • G57——Set workpiece coordinate four
  • G58——Set workpiece coordinate 5
  • G59——Set workpiece coordinate six
  • G60——Accurate path mode (fine)
  • G61——Accurate path mode (middle)
  • G62——Accurate path mode (coarse)
  • G63——Tapping thread
  • G68——Tool offset, inside angle
  • G69——Tool offset, outside corner
  • G70 – inch size (this is Siemens, Frank’s is G21)
  • G71 – Metric Dimensions in mm
  • G74——Return to reference point (machine zero point)
  • G75——Return to programming coordinate zero
  • G76——Threading compound cycle
  • G80 – Canned Cycle Logout
  • G81——External circle canned cycle
  • G331——–Thread canned cycle
  • G90 – Absolute size
  • G91 – Relative Dimensions
  • G92 – Prefab Coordinates
  • G93 – time countdown, feedrate
  • G94 – feed rate, feed per minute
  • G95——Feed rate, feed per revolution
  • G96——Constant Linear Speed ​​Control
  • G97——Cancel constant linear speed control


  Function DetailsEdit Rapid positioning Format: G00 X(U)__Z(W)__ Description:

  • This command makes the tool move quickly to the specified position according to the point control method.Do not touch the workpiece during the movementto be processed.
  • All programmed axes move at the speed defined by the parameters at the same time.The axis continues to move,
  • The coordinates that do not move do not need to be programmed.
  • G00 can be written as G0

Example: G00 X75 Z200

G01 U-25 W-100 First, take X and Z at the same time to go 25 fast to point A, then go to Z and then go 75 fast to point B. G01—Linear interpolation Format: G01 X(U)__Z(W)__F__(mm/min) Explanation:

  • This command makes the tool move to the specified position by linear interpolation.The moving speed is commanded by F Feed rate. All coordinates can be linked together.  
  • G01 can also be written as G1

Example: G01 X40 Z20 F150

Two-axis linkage from point A to point B Inverse circular interpolation Format 1: G02X(u)____Z(w)____I____K____F_____

When X and Z are in G90

The coordinates of the arc end point are absolute coordinates relative to the programmed zero point.

In G91, The arc end point is an incremental value relative to the arc start point.

Regardless of G90 or G91, I and K are the incremental coordinates of the arc center relative to the starting point. I is an X-direction value, and K is a Z-direction value. The coordinates of the circle center must not be omitted during circular interpolation unless programmed in other formats.

When G02 is programmed, quadrant circle, full circle, etc. can be programmed directly. Note: When the quadrant is passed, the gap compensation will be automatically performed. If the gap compensation and the actual backlash of the machine tool are entered at the end of the parameter area The disparity will produce obvious cuts on the workpiece.  

G02 can also be written as G2.

Example: G02 X60 Z50 I40 K0 F120 Format 2: G02X(u)____Z(w)____R(+-)__F__

  • It cannot be used for the programming of a full circle  
  • R is the radius of the R arc on one side of the workpiece. R is a sign, “+” indicates that the arc angle is less than 180 degrees; “-” indicates that the arc angle is greater than 180 degrees. The “+” can be omitted.  
  • It is based on the coordinates of the end point. When the length between the end point and the start point is greater than 2R, the arc is replaced by a straight line.  

Example: G02 X60 Z50 R20 F120

Format 3: G02X(u)____Z(w)____CR=__(radius)F__ Format 4: G02X(u)____Z(w)__D__ (diameter) F___ These two programming formats are basically the same as format 2 Circular interpolation Description: The format is the same as the G02 command except that the arc rotation direction is reversed.  

G04—Timed Pause

Format: G04__F__ or G04__K__ Description: The processing motion is suspended, and when the time expires, the processing continues. The pause time is specified by the data following F. The unit is seconds. The range is 0.01 seconds to 300 seconds.  

Intermediate Point Circular Interpolation

Format: G05X(u)____Z(w)____IX_____IZ_____F_____ Description: (1) X, Z are the coordinates of the end point, IX, IZ are the coordinates of the intermediate point.Others are similar to G02/G03 Example: G05 X60 Z50 IX50 IZ60 F120  


Format: G08 Explanation: They occupy a line in the program segment. When the program reaches this segment, the feed rate will increase by 10%. A 20% increase would need to be written in two separate paragraphs.  

Radius Programming

Format: G22 Explanation: If there is a line in the program, the system runs in radius mode, and the following values ​​in the program are also Based on radius.  

G23(G230)—Diameter Dimension Programming Method

Format: G23 Explanation: If there is a line in the program, the system runs in diameter mode, and the following values ​​in the program are also Based on diameter.  

Jump Processing

Format: G25 LXXX Explanation: When the program executes to this program, it transfers the specified block. (XXX is the block number).  

G26—Cycle Machining

Format: G26 LXXX QXX Description: When the program executes to this program, the specified program segment starts to this segment as a loop body, The number of loops is determined by the value after Q.  

magnification Cancellation

Format: G30 Description: It occupies a line in the program and is used in conjunction with G31 to cancel the function of G31.  

Magnification Definition

Format: G31 F_____ G32—Equal Pitch Threading (Inch) G33—Equal Pitch Threading (Metric) Format: G32/G33 X(u)____Z(w)____F____ Description:

  • X, Z are the coordinates of the end point, and F is the pitch
  • G33/G32 can only process single-tool and single-start threads.
  • The change of X value can process taper thread
  • When using this command, the spindle speed should not be too high, otherwise the tool wear will be large.

G50—Set Workpiece Coordinates/Set Spindle Maximum (Low) Speed

Format: G50 S____Q____ Description: S is the maximum speed of the spindle, Q is the minimum speed of the spindle  

G54—Set Workpiece Coordinate One

Format: G54 Description: There can be several coordinate systems in the system, G54 corresponds to the first coordinate system, and its origin position value is in the machine tool  

Set In The Parameters

G55—Set workpiece coordinate 2 Ditto G56—Set workpiece coordinate three Ditto G57—Set workpiece coordinate four Ditto G58—Set workpiece coordinate 5 Ditto G59—set workpiece coordinate six Ditto  

Exact Path Method

Format: G60 Description: In the actual processing process, when several actions are connected together, when programming with an accurate path, then During the next processing, there will be a buffering process (meaning deceleration)  

Continuous Path

Format: G64 Description: Relative to G60. Mainly used for rough machining. G74—return to reference point (machine zero) Format: G74 XZ

  • No other content shall appear in this paragraph.
  • The coordinates appearing after G74 will return to zero in order of X and Z.
  • Before using G74, it must be confirmed that the machine tool is equipped with a reference point switch.
  • Single-axis zero return can also be performed.

G75— Return To Programming Coordinate Zero

Format: G75 XZ Description: Return to the programming coordinate zero point

G76— Return To The Starting Point Of Programming Coordinates

Format: G76 Description: Return to the position where the tool starts processing. G81—external circle (internal circle) canned cycle Format: G81__X(U)__Z(W)__R__I__K__F__

  • X, Z are the coordinates of the end point, U, W are the incremental values ​​of the end point relative to the current point.
  • R is the diameter to be machined of the starting point section.
  • I is the rough turning feed, K is the fine turning feed, I and K are signed numbers, and the symbols of the two should be the same.
  • The symbol convention is as follows: cutting from the outer center axis (turning the outer circle) is “-“, otherwise it is “+”.
  • Different X, Z, R determine different switches of the outer circle, such as: with taper or without degree,
  • Forward taper or reverse taper, left or right cutting, etc.
  • F is the cutting speed (mm/min)
  • After machining, the tool stops at the end point.

Example: G81 X40 Z 100 R15 I-3 K-1 F100 Processing process:

  • G01 feeds 2 times of I (the first cut is I, and the last cut is I+K finishing), for deep cutting:
  • G01 two-axis interpolation, cutting to the end-point section, stop if the machining is over:
  • G01 retracts I to a safe position, and at the same time performs auxiliary cutting surface smoothing
  • G00 feeds the tool rapidly to the outside of the high working plane I, reserve I for the next cutting process, and repeat to 1.

G90—Programming In Absolute Value Mode

Format: G90 Explanation:

  • When G90 is programmed into a program, all coordinate values ​​programmed in the future are all based on the programmed zero point.
  • After the system is powered on, the machine tool is in the G state.
  • N0010 G90 G92 x20 z90
  • N0020 G01X40 Z80 F100
  • N0030 G03X60 Z50 I0 K-10
  • N0040 M02

Incremental Programming

Format: G91 Note: When G91 is programmed into the program, all the coordinate values ​​after that are calculated using the previous coordinate position as the starting point The programmed value of the movement. In the next coordinate system, the previous point is always programmed as the starting point. Example: N0010 G91 G92 X20 Z85 N0020 G01X20 Z-10 F100 N0030 Z-20 N0040 X20 Z-15 N0050 M02

Set The Workpiece Coordinate System

Format: G92 X__ Z__

  • G92 only changes the coordinate value currently displayed by the system, does not move the coordinate axis, and reaches the set coordinate
  • The origin of the purpose.
  • The effect of G92 is to change the displayed tool nose coordinates to the set value.
  • The XZ behind G92 can be programmed separately or in full.

G94—Feed rate, feed per minute Description: This is the default state of the machine when it is turned on. G20—Subprogram call Format: G20 L__ N__

  • After L is the program name after the subprogram N to be called, but N cannot be input.
  • Only numbers 1~99999999 are allowed after N.
  • No content other than those described above shall appear in this section of the program.

Return To The End Of The Subroutine

Format: G24 Explanation:

  • G24 indicates the end of the subprogram, and returns to the next section of the calling subprogram.
  • G24 and G20 appear in pairs
  • Other commands are not allowed in this section of G24.

Instance Editing

Example: The following example illustrates the parameter transfer process in the subprogram calling process. Please pay attention to the application Program name: P10 M03 S1000 G20 L200 M02 N200 G92 X50 Z100 G01 X40 F100 Z97 G02 Z92 X50 I10 K0 F100 G01 Z-25 F100 G00 X60 Z100 G24 If you want to call multiple times, please use the following format M03 S1000 N100 G20 L200 N101 G20 L200 N105 G20 L200 M02 N200 G92 X50 Z100 G01 X40 F100 Z97 G02 Z92 X50 I10 K0 F100 G01 Z-25 F100 G00 X60 Z100 G24 G331—Thread machining cycle Format: G331 X__ Z__I__K__R__p__

  • X-direction diameter changes, X=0 is straight thread
  • Z is the thread length, absolute or relative programming is available
  • I is the run-out length in the X direction after the thread is cut, ± value
  • The diameter difference between the outer diameter of the R thread and the root diameter, a positive value
  • K pitch KMM
  • The cycle processing times of the p thread, that is, the cutting is done in several knives


1. The depth of each feed is R÷p and rounded, and the last cut is not fed to smooth the thread surface 2. The name of the I value is determined according to the positive and negative directions of the internal thread. 3. The starting position of the thread machining cycle is to align the tool nose with the outer circle of the thread. example: M3 G4 f2 G0x30z0 G331 z-50 x0 i10 k2 r1.5 p5 G0 z0 M05 4   NotesEdit  


  • G00 and G01
  • There are two kinds of G00 motion path: straight line and polyline. This command is only used for point positioning and cannot be used for cutting processing.
  • G01 moves to the target point specified by the command in a linear motion mode according to the specified feed rate, which is generally used for cutting
  • G02 and G03
  • G02: Clockwise circular interpolation G03: Counterclockwise circular interpolation
  • G04 (delay or pause command)
  • Generally used for forward and reverse switching, processing blind holes, stepped holes, turning and grooving
  • G17, G18, G19 plane selection command, specifying plane processing, generally used for milling machines and machining centers
  • G17: XY plane, which can be omitted or a plane parallel to the XY plane
  • G18: XZ plane or a plane parallel to it, there is only XZ plane in CNC lathes, no special designation is required
  • G19: YZ plane or plane parallel to it
  • G27, G28, G29 reference point command
  • G27: Return to the reference point, check and confirm the position of the reference point
  • G28: Automatically return to the reference point (passing through the middle point)
  • G29: Return from the reference point, used in conjunction with G28
  • G40, G41, G42 radius compensation
  • G40: Cancel tool radius compensation
  • G43, G44, G49 length compensation
  • G43: Positive Length Compensation G44: Negative Length Compensation G49: Cancel Tool Length Compensation
  • G32, G92, G76
  • G32: Thread cutting G92: Thread cutting canned cycle G76: Thread cutting compound cycle
  • 9. Turning: G70, G71, 72, G73
  • G71: Axial roughing compound cycle command G70: Finishing compound cycle G72: End face turning, radial roughing cycle G73: Copy roughing cycle
  • Milling machines and machining centers:
  • G73: High-speed deep hole drilling G83: Deep hole drilling G81: Drilling cycle G82: Deep hole drilling cycle
  • G74: Left-hand threading G84: Right-hand threading G76: Fine boring cycle G86: Boring cycle
  • G85: Reaming G80: Cancel cycle command
  • Programming method G90, G91
  • G90: Absolute coordinate programming G91: Incremental coordinate programming
  • Spindle setting command
  • G50: Setting of maximum spindle speed G96: Constant surface speed control G97: Spindle speed control (cancel constant surface speed control command) G99: Return to point R (intermediate hole) G98: Return to reference point (last hole)
  • Spindle forward and reverse rotation stop commands M03, M04, M05
  • M03: Spindle forward M04: Spindle reverse M05: Spindle stop
  • Cutting fluid switch M07, M08, M09
  • M07: Mist cutting fluid on M08: Liquid cutting fluid on M09: Cutting fluid off
  • Motion stop M00, M01, M02, M30
  • M00: Program pause M01: Planned stop M02: Machine reset M30: Program ends, the pointer returns to the beginning
  • M98: call subroutine
  • M99: return to the main program

In the CNC China Forum dialog box, enter the following numbers to get exciting content:

  • 101: View all keywords of WeChat official account
  • 1001: FANUC PMC Programming Introduction Video Lecture
  • 1002: Powermill CNC Programming Introductory Course
  • 1003: Metal Material Density Table
  • G code: G code function programming, detailed function explanation

At,we use advanced equipment to offer you Unparalleled precision for producing metal and plastic machining parts

  • We combine the latest CNC milling and turning processes with proprietary technology to deliver high quality, on-demand parts.
  • Our team of engineers and machinists program the equipment to optimize cutting time, surface finish, and final tolerance to meet your design specifications
  • We specialize in cnc precision machining, single part prototyping, short to medium production runs, manufacture parts on time, every time, so you can stay ahead of schedule
  • CNC machining can create very similar parts to series parts. It is often more efficient and faster than other rapid prototyping technologies for the manufacture of a quantity of prototypes between 1 and 10 parts . We also recommend CNC machining for parts with large sizes (greater than 600 mm).

Contact Us ([email protected]) Now for your Custom CNC Machining, We are your best online cnc machining and rapid prototyping services choice!