G50 CNC Code: Full Guide & Programming Examples

This article provides a complete, practical explanation of the G50 CNC code. You will learn its exact function, correct syntax, and how to apply it in real-world turning operations. By the end, you will be able to write error-free G50 commands to set work coordinates and limit spindle speed on CNC lathes.

01What Is the G50 CNC Code? (Core Definition)

The G50 code has two essential and distinct functions on CNC lathes (Fanuc-type controls):

1. Set the workpiece coordinate system – Define the origin (zero point) of the part program relative to the machine home position.

2. Set the maximum spindle speed limit – Prevent the spindle from exceeding a safe RPM during constant surface speed (G96) mode.

Both functions use the same G50 command but with different addresses. Understanding this dual purpose is critical to avoid programming errors.

02Function 1: Setting the Workpiece Coordinate System with G50

When you power on a CNC lathe, the control does not know where your part is. You must tell it the distance from the machine home position to the part’s zero point. G50 does exactly that.

Correct Syntax

G50 X_ Z_

X = Distance from the tool nose to the part’s X-axis zero point (diameter value, in mm or inches)

Z = Distance from the tool nose to the part’s Z-axis zero point

Real-World Example

Common situation: You are machining a simple shaft. The finished part length is 100 mm, and the diameter is 50 mm. You set the part zero at the right-end face and the centerline.

After touching the tool to the part face, you record the machine coordinate. Suppose the machine shows X = 200.5 mm and Z = -150.0 mm at the zero point. You write:

G50 X0 Z0

Wait – that is incorrect in most older controls. Actually, the correct way: On most Fanuc lathes, G50 sets the coordinate system by assigning current tool position as a specific coordinate. The standard method is to move the tool to the programmed zero position manually, then command G50 to tell the control “the tool is now at X0 Z0.”

More accurate common practice:

1. Bring the tool to the part’s zero point (touch the face and the outer diameter).

2. In MDI mode, type G50 X0 Z0 and press cycle start.

3. Now the control recognizes that position as X0 Z0.

However, many modern programmers prefer using G50 to preset a coordinate shift. Here is the correct, widely accepted format:

Example (metric):

If you want the part zero to be at the face and centerline, and the tool is currently at X = 250 mm, Z = -130 mm in machine coordinates, you can set:

G50 X250.0 Z-130.0

This tells the control “the current tool position is X250 Z-130 in the workpiece coordinate system.” Then all subsequent moves are relative to that.

Better approach – using G50 to define maximum spindle speed while also setting coordinates:

Actually, for coordinate setting alone, most shops now use G54–G59 work offsets. But G50 remains common on older lathes and for simple programs.

Let me give a clear, working example:

Program snippet for a facing operation:

N10 G50 X200.0 Z150.0  (Set current tool position as X200 Z150 in part coordinates)
N20 G00 X100.0 Z5.0    (Rapid to X100 Z5 relative to that zero)
N30 G01 Z0 F0.2        (Face the part)
...

This works. But the most common real-world use of G50 is actually spindle speed limiting.

03Function 2: Setting Maximum Spindle Speed (G50 S_)

This is the primary reason operators search for “g50 cnc code”. When you use constant surface speed (G96), the spindle RPM increases as the tool moves toward the center (X becomes smaller). Without a limit, RPM could exceed safe values – damaging the chuck, workpiece,or operator.

Correct Syntax

G50 S_

S = Maximum spindle speed in RPM (integer value)

Real-World Example

Common situation: You are turning a 150 mm diameter aluminum part. You want to cut at 200 m/min constant surface speed. At the 150 mm diameter, RPM = (200 1000) / (π 150) ≈ 424 RPM. But as the tool faces to the center (X0), RPM would theoretically go to infinity. To prevent this:

N10 G50 S1500   (Limit max spindle speed to 1500 RPM)
N20 G96 S200 M03 (Constant surface speed 200 m/min, spindle on)
N30 G00 X160.0 Z2.0
N40 G01 X-1.0 F0.25 (Facing cut – spindle will not exceed 1500 RPM)

Another common case: Machining a small diameter (e.g., 10 mm) on a lathe with a chuck rated for 4000 RPM max. Set:

G50 S3500

This keeps the operation safe.

04Important Rules and Warnings

1. G50 is modal – Once set, the maximum speed limit remains active until changed by another G50 S_ or until program end/power cycle.

2. G50 S_ must be programmed before G96 – Otherwise, the control may ignore the limit or cause an alarm.

3. Do not confuse with G92 – G92 also sets coordinate systems on some controls, but G50 is the standard on Fanuc lathes.

4. On some controls (e.g., Haas), use G50 for coordinate scaling – That is a different function. This article focuses on the most common interpretation for turning centers (Fanuc-style).

5. Always confirm with your machine manual – Control manufacturers may implement slight variations.

05Common Mistakes and How to Avoid Them

MistakeConsequenceCorrection
Forgetting G50 S_ before G96Spindle overspeed, potential crashAlways program G50 S_ on the line immediately before G96
Using G50 X_Z_ and G50 S_ in same blockOnly one function executes (usually the last address read)Separate into two blocks: first G50 S_, then G50 X_Z_ if needed
Setting G50 S_ too lowInability to achieve required surface speed at large diametersCalculate minimum RPM needed at largest diameter: RPM = (VC 1000)/(π D) – then set limit 20-30% higher
Using G50 on a milling machine to set coordinatesMay trigger scaling mode insteadOn mills, use G54–G59 for work offsets; G50 often enables scaling

06Step-by-Step Action Plan for Safe G50 Usage

Follow this checklist every time you write a CNC program that uses constant surface speed:

1. Determine the maximum safe RPM of your chuck, workpiece holding, and tooling. Check the machine manual.

2. Calculate the required RPM at the largest cutting diameter using the formula:

RPM = (Surface Speed <strong> 1000) / (π </strong> Diameter) (for metric)

RPM = (Surface Speed <strong> 12) / (π </strong> Diameter) (for imperial)

3. Set G50 S_ to a value slightly above the calculated RPM at largest diameter, but never exceeding machine limits.

4. Place the G50 S_ block on a line by itself, before any G96 command.

5. Test the program in dry run or with spindle speed override set to 50% initially.

6. Verify that the spindle does not exceed the limit when the tool approaches center.

07Quick Reference Card

Purpose: Limit max spindle RPM during G96
Syntax:   G50 Sxxxx  (xxxx = max RPM)
Example:  G50 S2000
Purpose: Set workpiece coordinate system (older lathes)
Syntax:   G50 Xx Zz
Example:  G50 X250.0 Z150.0
Important: Never combine both in one block.
Always place G50 S_ before G96.

08Conclusion: Master the G50 Code for Safer Turning

The G50 code is not difficult, but its dual nature causes many programming errors. Remember these core points:

G50 S_ is your safety net for constant surface speed – always use it.

G50 X_Z_ is for coordinate setting on older or simple lathes – use work offsets (G54–G59) on modern controls instead.

One function per block – never mix S and X/Z addresses in the same G50 line.

Actionable advice for you:

Open your last turning program that used G96. Check if you included a G50 S_ before it. If not, add it now. Then verify the S value matches your chuck’s safe RPM. This single habit will prevent spindle overspeed crashes and extend machine life. For your next new part, write the G50 S_ line before writing any G96 move – make it a standard part of your programming template.

YPMFG

Factory CNC Machined Parts

Need high-precision parts for your project? Get instant pricing & DFM feedback

Ready for Your Project?

YP-MFG is a leading manufacturer specializing in high-precision metal parts and CNC machining services.

Contact

WhatsApp/Phone

+86 137 9493 0097

Address

Building A6, The Third Industrial Zone, Fenghuang Community, Fuyong Street, Bao’an District, Shenzhen

Copyright YP-MFG © 2025 All Rights Reserved

滚动至顶部

Is your design ready for CNC machining?​

Upload your CAD file and discuss it directly with an experienced engineer.
Get a professional DFM review and full project consultation.