The P code doesn’t do just one thing in CNC. It does four different things depending on what code it’s paired with.
That’s what makes it confusing for beginners — and why it’s worth taking a few minutes to understand each use.
Key Takeaways
- P is most often used to call a subprogram with M97 or M98
- P also sets dwell time when used with G04, G82, or G89 With G10,
- P selects which fixture offset to change
- With G51, P sets a scale factor for the entire program
- Always check your machine manual — P reads differently on different controls (seconds vs. milliseconds)
| P Code – At A Glance | |
|---|---|
| Primary use | Subprogram selection (M97/M98) |
| Also used with | G04, G82, G89, G10, G51 |
| Type | Non-modal |
| Control variations | Yes — check your machine manual |
What Does the P Code Do?
The P code is an address word — it passes a value to another code that needs it. On its own, P does nothing. It only has meaning when combined with a G or M code.
The four main uses are:
- Calling a subprogram (with M97 or M98)
- Setting a dwell time (with G04, G82, or G89)
- Selecting a fixture offset (with G10)
- Setting a scale factor (with G51)
The most common use by far is subprograms.
P Code with M97 and M98 (Subprogram Calls)
Subprograms are separate blocks of CNC code that you can call from within a main program. They’re used for repeating operations — like drilling a hole pattern, or running the same chamfer at multiple locations.
The P code tells the machine where to find the subprogram.
P Code with M97 (Call by Line Number)
M97 calls a subprogram inside the current program. The P value is the line number (N number) where the subprogram starts.
M97 P1000 L3
This tells the machine: jump to line N1000 in the current program and run it 3 times. The L code sets the number of repetitions. If you leave L out, the subprogram runs once.

The subprogram sits below the main program end command (M30) and finishes with M99, which sends the machine back to the next line after the M97 call.
P Code with M98 (Call by Program Number)
M98 calls a completely separate program stored on the control. The P value is the program number.
M98 P5678 L2
This tells the machine: run program O5678 two times. Like M97, leaving out L means it runs once.

Program O5678 ends with M99 instead of M30. M99 returns control to the main program.
A quick note: some controls use K instead of L for the number of repetitions. Check your machine’s manual if L isn’t working.
P Code with G04 (Dwell Time)
G04 pauses machine movement for a set amount of time. The P code sets how long.
G04 P500
This looks straightforward, but there’s a real catch.
COMMON MISTAKE – Seconds vs Milliseconds
Some CNC controls read the P value after G04 as seconds. Others read it as milliseconds. P500 could mean 500 seconds (over 8 minutes) on one machine, or 0.5 seconds on another. Always check your control’s manual before using G04 with P for the first time. Some machines also use F, X, or U instead of P for dwell time.
Not all machines use P for dwell. If G04 P isn’t working, try G04 F or G04 X — common alternatives on older or Fanuc-based controls.
P Code with G82 and G89 (Canned Cycle Dwell)
G82 is the spot drill cycle with dwell. G89 is the boring cycle with dwell. Both use P to set how long the tool pauses at the bottom of the hole.
G82 X1.0 Y1.0 Z-0.5 R0.1 P300 F10.0
The pause at the bottom lets the tool dwell briefly, which cleans up the hole bottom and improves surface finish.
As with G04, the P value is usually in milliseconds on most modern controls — but confirm this for your specific machine. P300 is typically 0.3 seconds, not 5 minutes.
P Code with G10 (Fixture Offset Selection)
G10 is used to set work offsets programmatically — directly in the G-code, without going to the offset screen. The P code tells the machine which fixture offset you’re changing.
Here’s how the P numbers map to work coordinate systems:
Code | Fixture Offset |
G10 P1 | G54 |
G10 P2 | G55 |
G10 P3 | G56 |
G10 P4 | G57 |
G10 P5 | G58 |
G10 P6 | G59 |
Example:
G10 L2 P1 X5.0 Y3.0 Z0.0
This sets the G54 offset X to 5.0, Y to 3.0, and Z to 0. The L2 tells the machine you’re setting a work coordinate offset (as opposed to a tool offset).
G10 is handy in automated setups where offsets change between parts or pallets.
P Code with G51 (Scaling)
G51 scales a CNC program up or down. The P code sets the scale factor.
G51 X0. Y0. P2.0
A P value of 2.0 doubles the size of everything in the program. A P value of 0.5 cuts everything in half.
This is used mainly in special applications — mirroring, family-of-parts programming, or teaching scenarios. It’s not commonly used in everyday production machining.
Cancel scaling with G50 when you’re done.
Conclusion
The P code is a multi-use address word. Its meaning depends entirely on what it’s paired with.
Subprogram calls with M97 and M98 are the most common use, and those are fairly consistent across controls. The other uses — especially dwell time with G04 — can behave differently from machine to machine.
When in doubt, check the manual for your specific control before running a new program with P.
FAQS
What does P mean in CNC programming?
P is an address word used to pass a value to another code. Its meaning changes depending on what G or M code it’s combined with. The most common use is selecting a subprogram number with M97 or M98.
Does G04 P read in seconds or milliseconds?
It depends on your CNC control. Some read P as milliseconds (P1000 = 1 second), others as full seconds (P1 = 1 second). Always check your machine manual before using G04 P for the first time.
What’s the difference between M97 P and M98 P?
M97 P jumps to a line number (N number) within the current program. M98 P calls a completely separate program stored on the control by program number. Both return to the main program when M99 is reached.
Can I use P without any other code?
No. P doesn’t do anything on its own. It only has meaning when combined with another code like M97, M98, G04, G10, or G51.