G81 is the simplest canned cycle for drilling holes on a CNC machine. It drills a hole in one straight plunge and retracts the tool. There is no pecking, no dwell at the bottom, and no chip clearing. Use G81 for standard holes where the depth is shallow enough to clear chips in a single pass.
Canned cycles are one of the most powerful features of CNC programming. They turn multiple lines of G-code into a single command. Without G81 you would need three lines of code for every hole: a G00 to position above the hole, a G01 to feed to depth, and a G00 to retract. With G81 you write one line per hole and the control handles the positioning, feeding, and retracting automatically.
This guide covers the G81 format, how to program multiple holes, the difference between G98 and G99 retract modes, and the common mistakes to avoid.
G81 Format
| Category | Example | Purpose |
|---|---|---|
| Type A | Example 1 | Purpose 1 |
| Type B | Example 2 | Purpose 2 |
| Type C | Example 3 | Purpose 3 |
The standard G81 format is G81 X Y Z R F. Each parameter serves a specific purpose. X and Y are the hole position coordinates. Z is the final depth of the hole measured from the current Z zero position. R is the retract plane which is the Z position where the tool rapids down to before switching to feed rate. F is the feed rate in inches per minute for the drilling plunge.
For a 1-inch deep hole at position X1 Y1 with a retract plane of Z0.1 and a feed rate of 5 inches per minute the code is: G81 X1 Y1 Z-1 R0.1 F5.
The sequence of events when the control executes this line is as follows. The tool rapids to X1 Y1 at whatever Z height it is currently at. The tool then rapids down to Z0.1 which is the R plane. From Z0.1 the tool feeds at 5 IPM straight down to Z-1 which is the final depth. At Z-1 the tool immediately rapids back up to Z0.1 ready for the next hole.
The R plane is one of the most important safety parameters in drilling. It must be set high enough to clear any obstacles like clamps or the top of the workpiece. But it should also be as low as practical to minimize cycle time. A good starting point for R is 0.05 to 0.1 inch above the highest point of the workpiece.
Programming Multiple Holes with G81
The real power of G81 is drilling multiple holes with minimal code. After the initial G81 line which contains all the parameters you only need to specify the X and Y positions for subsequent holes. All other parameters including Z depth, R plane, and feed rate remain the same.
Here is an example of drilling four holes in a row:
G81 X1 Y1 Z-0.5 R0.1 F10 (first hole with full parameters) X2 Y1 (second hole at X2) X3 Y1 (third hole at X3) X4 Y1 (fourth hole at X4) G80 (cancel the canned cycle)
The G80 command cancels the canned cycle. This is essential. Without G80 the machine treats every subsequent X and Y move as a drilling operation. This is especially dangerous after a tool change because the machine drills at the new tool position unexpectedly.
For a grid of holes you can mix positive and negative X and Y values. The pattern can be any shape. You can also drill holes in any order. The control tracks the current position and moves to each new X Y location before drilling.
G98 vs G99 Retract Mode
G98 and G99 control where the tool retracts to after each hole. G98 retracts to the initial Z height that was active before the G81 command was first called. G99 retracts only to the R plane.
Use G98 when you need to clear clamps, fixtures, or other obstacles between holes. The tool retracts all the way to the safe starting height after every hole. This eliminates the risk of collision but increases cycle time because the tool travels further.
Use G99 when clearance is not an issue. The tool retracts only to the R plane which is typically just above the workpiece surface. This reduces cycle time significantly on parts with many holes. But if there are clamps or other obstacles between the R plane and the next hole position the tool will crash into them.
The default retract mode is G98. Most controls start in G98 mode when powered on. Switch to G99 only when you are certain that the tool clears all obstacles at the R plane height. When in doubt use G98.
Complete Drilling Program
Here is a complete program that drills four holes at the corners of a 2-inch square. This shows how G81 fits into a full program with tool selection, coolant, and program end.
O1000 G90 G54 G00 X0 Y0 G43 H1 Z1 M08 G81 X1 Y1 Z-0.5 R0.1 F10 X-1 Y1 X-1 Y-1 X1 Y-1 G80 G00 Z1 G28 G91 Z0 M30
This program sets absolute mode with G90, selects work offset G54, and rapids to X0 Y0. It calls tool length offset H1 with G43 and turns on coolant with M08. The G81 cycle drills four holes at the corners of the square. G80 cancels the cycle. The tool retracts to Z1 and the program ends with M30.
When to Use G81
G81 is appropriate for holes where the depth is no more than about three times the drill diameter. Deeper holes need peck drilling with G83 to clear chips periodically. Hard materials that need a dwell at the bottom of the hole require G82 which adds a pause at the bottom.
G81 is also appropriate for spot drilling where you only need a shallow chamfer to start a drill. For spot drilling set Z to a depth just below the surface typically 0.02 to 0.05 inch. This creates a chamfer that guides the drill and prevents it from walking.
Do not use G81 for blind holes in materials that produce stringy chips like aluminum. The long chips can pack into the hole and cause the drill to break. Use G83 peck drilling instead which retracts periodically to break and clear chips.
Common G81 Mistakes
The most common mistake is forgetting G80 at the end of the cycle. Without G80 the first X Y move after the drilling pattern drills another hole at that location. This is dangerous after a tool change because a new tool at an unexpected drilling position can break or crash.
Another common mistake is setting the R plane too low. If R is below the top surface of the workpiece the tool rapids into the material instead of feeding into it. This can break the tool or damage the part. Always set R at least 0.05 to 0.1 inch above the highest point on the workpiece.
The third mistake is using G99 retract mode when obstacles are present. If a clamp or fixture is between the R plane and the next hole position the tool crashes into it during the rapid move between holes. When in doubt use G98.
Drilling Feeds and Speeds
Drilling requires different feeds and speeds than milling because the cutting action happens at the tip of the tool rather than along the side. The feed rate for drilling is typically lower than for milling because the drill must clear chips through its flutes.
For HSS twist drills the recommended SFM depends on the material. Aluminum runs at 200 to 300 SFM for drilling. Mild steel runs at 80 to 110 SFM. Stainless steel runs at 30 to 50 SFM. Cast iron runs at 60 to 90 SFM. For carbide drills multiply these values by 2 to 3 times.
The feed rate for drilling is specified in inches per revolution rather than inches per tooth. For a quarter-inch drill in aluminum use 0.005 to 0.010 IPR. For a half-inch drill use 0.008 to 0.015 IPR. For steel use approximately half the aluminum values. Smaller drills need lighter feeds and larger drills can handle heavier feeds.
To convert IPR to IPM multiply by the spindle RPM. If you are running a quarter-inch drill at 3,000 RPM with a feed of 0.008 IPR the feed rate is 24 IPM. Most CAM software calculates this automatically but understanding the relationship helps you troubleshoot feed rate problems at the machine.
Center drilling is a separate operation that uses a specialized center drill. Center drills have a thick web that resists bending. They create a tapered starting hole that guides the twist drill and prevents it from walking. Use a center drill at about the same RPM as your twist drill but with a lower feed rate.
G81 with Subprograms
For complex hole patterns you can combine G81 with subprograms using M97 or M98. A subprogram contains the hole positions and the main program calls the subprogram multiple times at different locations. This is useful for drilling identical patterns at multiple positions on the same part.
Example main program:
G54 G00 X0 Y0 M98 P1000 (drill pattern at first position) G55 G00 X0 Y0 M98 P1000 (drill same pattern at second position)
Subprogram O1000:
G81 X0.5 Y0.5 Z-0.5 R0.1 F10 X1.5 Y0.5 X1.5 Y1.5 X0.5 Y1.5 G80 M99 (return to main program)
This approach minimizes code duplication and makes programs easier to edit. When hole positions change you only edit the subprogram not every instance of the pattern.
Deep Hole Drilling Strategy
For holes deeper than about 3 times the drill diameter G81 is not appropriate because chips cannot clear from the deep hole. The chips pack into the flutes and cause the drill to bind and break. For deep holes use G83 peck drilling cycle which retracts the drill periodically to clear chips.
The peck depth in G83 is typically 2 to 3 times the drill diameter. Each peck advances the drill by this amount then retracts to clear chips. The retract height can be set to the R plane or to a specified clearance height.
For very deep holes over 10 times the diameter use a pecking strategy with decreasing peck depths. The first peck might be 0.2 inch, the second 0.15 inch, and so on. This prevents the drill from loading up as the hole gets deeper and chip evacuation becomes more difficult. When peck drilling always use G99 retract mode to minimize cycle time because the tool returns to the R plane after each peck anyway.
Drilling is one of the most common CNC operations and mastering G81 saves significant programming time compared to writing individual G00 and G01 moves for every hole. The canned cycle approach also reduces the chance of programming errors because the control handles the retract and positioning automatically. Practice with simple hole patterns first then move on to subprograms and complex grid patterns.
For more G-code programming guides see our [G-Code for Beginners](
G90 G54 G00 X0 Y0
G01 Z-0.1 F10
G01 X1.0 F20
M30
/posts/g-code-for-beginners/) and our Common G-Code Mistakes guides.

G02 and G03: Circular Interpolation for CNC ProgrammingJune 26, 2026 · Tutorials
CNC Conversational Programming Guide: A Beginner's IntroductionJune 27, 2026 · Tutorials