Machining an internal keyway (slot for a key) directly on a CNC lathe is a massive time saver. It eliminates the need to transfer the workpiece to a slotting machine, while maintaining perfect coaxiality.
Process Kinematics on a Lathe
Slotting on a CNC lathe is most commonly performed with a locked spindle (C-axis or M19 code). The cutting (working) movement is executed by the Z-axis, while the X-axis is responsible for the radial feed of subsequent material layers and the tool retract distance before the return stroke. Unfortunately, manufacturers do not implement appropriate functions for this in their software. Fortunately, every lathe supports low-level control via G-codes. With a basic knowledge of this language, you can quickly write a program to control the tool movement accordingly. Here is an example:
M200
M1 T0909
G97 G98
M8
G0 X28.0000 Z10.0000
G0 C0.0000
F4000
G1 X30.5000
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X30.9857
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X31.4571
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X31.9143
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X32.3571
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X32.7857
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X33.2000
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X33.6000
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X33.9857
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X34.3571
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X34.7143
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X35.0571
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X35.3857
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X35.7000
G0 Z-100.0
G1 X28.00
G0 Z10.0
G1 X36.0000
G0 Z-100.0
G1 X28.00
G0 Z10.0
G0 X28.0000 Z10.0000
G0 C0.0000
F4000
G1 X36.0000
G0 Z-100.0
G1 X28.00
G0 Z10.0
M9
G53 X0.0
G53 Z-100.0
M30
As you can see, the code is very simple, yet long. It can be simplified with a loop, allowing the machine to increase the depth automatically:
M200
M1 T0909
G97 G98
M8
G0 X28.0000 Z10.0000
G0 C0.0000
F4000
#101=0.2 (GŁĘBOKOŚĆ SKRAWANIA ŚREDNICOWA)
#102=30. (ŚREDNICA OTWORU)
#103=36. (ŚREDNICA DNA WRĘBU)
WHILE [#102 LT #103] DO
#102=#102+#101
G0 X#102
G1 Z-100.0
G0 X28.0
G0 Z10.0
END
G53 X0 Z0
M30
In this program, a simple WHILE loop forces the execution of 4 lines of G-code until variable #102 equals variable #103. The program can be further expanded by adding an extra loop for subsequent teeth, etc. However, I recommend a tool that you simply install on your PC to quickly generate safe machine code by entering the required keyway parameters.

Regardless of how you control the machine, there are certain factors to keep in mind:
- Each lathe has a different rigidity and maximum axis thrust.
- Slotting can induce vibrations and faster axis wear.
- Excessively fast and short movements can cause the Z-axis to operate for too long under ultimate load caused by speed changes (axis acceleration and deceleration), which can lead to servo overheating.
However, responsible slotting does not harm the machine, and the benefits are truly immense:
- Turning and keyway/spline machining in a single setup.
- When positioning with the C-axis, the division between keyways is highly precise.
- Tool retraction is always full – in many traditional slotting machines, tool retraction is symbolic, causing the tool to slightly rub during the return stroke anyway.
- Time savings.


