DIN 66025 Standard Scope and Subroutine Functions
DIN 66025 (the German Deutsche Industrie-Norm for numerically controlled machines) is the long-standing reference specification for the structure of NC programs, the format of preparatory functions (G-codes), miscellaneous functions (M-codes), axis addresses, and subroutine control. The standard is published in multiple parts:
- DIN 66025-1 – General structure of NC programs, word format, address characters, coordinate systems, and feed/spindle programming.
- DIN 66025-2 – Supplementary functions for machines with multiple slides, multiple spindles, and handling equipment (the so-called "class 6" functions that include M98 and M99).
- PAS 66025 / PAL – A pedagogical subset derived from DIN 66025, used in German vocational training programs (CNC milling/turning mechanic apprenticeships).
Bosch Rexroth documents its DIN 66025-compliant NC function set explicitly in the IndraMotion MTX programming manual, providing a working reference for class-6 functions and subroutine syntax. See the official Bosch Rexroth NC Functions per DIN 66025 manual (ID1866589).
Subroutine-Related M-Functions per DIN 66025-2
DIN 66025-2 defines miscellaneous (M) functions used for program-flow control on multi-slide, multi-spindle, and handling-equipped machines. The functions that govern subroutine calls and termination are listed below.
| M-Code | Function Class | Standard Definition |
|---|---|---|
| M17 | End of subroutine | Return to the calling program at the block following the call. |
| M30 | End of main program | Reset program; rewind to the first block of the main program. |
| M98 | Conditional subroutine call | Class-6 function. Available only on machines with multi-slide, multi-spindle, or handling equipment that license the feature. |
| M99 | Conditional end / return | Class-6 function. Acts as a conditional M17/M30 depending on calling context. |
Siemens SINUMERIK Implementation
Siemens distinguishes explicitly between main programs (Hauptprogramme) and subprograms (Unterprogramme) at the file-system level. The naming convention is encoded into the program file extension and prefix.
Program Naming
| Program Type | Modern SINUMERIK (840D sl / ONE) | Older SINUMERIK (810/820/840C) |
|---|---|---|
| Main program | MPF<number> (e.g., MPF1234.MPF) | %<number> (e.g., %1234) |
| Subprogram | SPF<number> (e.g., SPF56.SPF) | L<number> (e.g., L56) |
| Sub-subprogram | SPF<number> (nested depth controlled by parameter) | L<number> (nesting controlled by $MN_MM_NUM_LDA / similar) |
Subroutine Call Syntax
; Modern SINUMERIK
L45 P03 ; Call subprogram SPF45 three times
; Older SINUMERIK
L56 P01 ; Call subprogram L56 once
; Modern SINUMERIK with program-name call
CALL "DRILL_45" ; Symbolic call via NC program name
The P parameter specifies the repetition count. L45 P03 loads subprogram 45 and executes it three times before returning to the next block in the calling program.
Subroutine Termination
; Inside SPF45.SPF
...
M17 ; End of subprogram, return to caller (line after the L45 call)
; Or in main program
...
M30 ; End of main program, reset, rewind
Modal Subprogram Structure
SINUMERIK stores the calling block number and program pointer internally. M17 causes the controller to read these stored values and continue execution at the block immediately following the call. If the same SPF is called from multiple locations, the internal stack maintains up to 16 levels of nesting by default (parameter MD19250 / $MN_MM_MAX_SKB_DEPTH or similar, depending on SW version).
Fanuc Implementation
Fanuc does not distinguish between main programs and subprograms at the file-system level. All programs use the same prefix; the distinction is made by the M-function that terminates the program.
Program Naming
Fanuc uses the address O (the letter, not zero) for all program numbers, regardless of whether the program is a main program or a subroutine.
| Program Type | Naming Convention | Example |
|---|---|---|
| Main program | O<number> | O0001 |
| Subprogram | O<number> | O1234 |
Subroutine Call Syntax
; Fanuc subprogram call
M98 P1234 ; Call subprogram O1234 once
M98 P1234 L5 ; Call subprogram O1234 five times (L = repeat count on Fanuc)
On Fanuc, the P word addresses the subprogram number; the optional L word specifies the repeat count. This is the inverse convention of Siemens, where L addresses the program number and P addresses the repeat count.
Subroutine Termination
; Inside O1234
...
M99 ; End of subprogram, return to block after the M98 P1234 call
; In main program O0001
...
M30 ; End of main program, reset, rewind
M99 has dual semantics on Fanuc: when used inside a subprogram it returns to the caller; when used at the end of a main program it acts as a loop-back, causing the controller to rewind to the beginning of the program and re-execute it. This dual role has no direct equivalent in Siemens syntax.
Syntax Comparison Table
| Operation | Siemens (SINUMERIK 840D sl) | Fanuc (Series 0i / 30i) | Bosch Rexroth MTX (DIN 66025 strict) |
|---|---|---|---|
| Call subprogram once | L45 (or CALL "DRILL_45") | M98 P45 | L45 |
| Call subprogram N times | L45 P03 (3 iterations) | M98 P45 L3 (3 iterations) | L45 P03 |
| End of subprogram | M17 (or RET) | M99 | M17 |
| End of main program | M30 | M30 | M30 |
| Main program file prefix | MPF<n> | O<n> | MPF<n> |
| Subprogram file prefix | SPF<n> | O<n> | SPF<n> |
| Repeat-count word | P | L | P |
| Subprogram-number word | L (numeric) or name | P (numeric) | L (numeric) or name |
Program Number Conventions and Address Conflicts
The address letters L and P have opposite meanings between Siemens and Fanuc. This is the single most common conversion error when porting NC code between controllers.
-
Siemens: L = subprogram number, P = repeat count. Example:
L45 P03runs SPF45 three times. -
Fanuc: P = subprogram number, L = repeat count. Example:
M98 P1234 L3runs O1234 three times.
L45 P03 on a Fanuc controller is parsed as linear interpolation to coordinate L=45 (invalid axis address on most mills, treated as auxiliary word) and dwell P03 = 3 seconds. It will not call any subprogram and may trigger a syntax alarm. Always rewrite address roles when transferring programs.Program number ranges are also implementation-specific:
| Controller | Typical Allowed Program Numbers | Notes |
|---|---|---|
| Siemens 840D sl | 1 – 99999999 (8 digits max for numeric) | Symbolic names allowed via CALL "name" |
| Fanuc 0i-MF | 1 – 9999 (4 digits) | Symbolic names via macro variables not standard |
| Bosch Rexroth MTX | 1 – 99999999 | Symbolic names allowed |
Reset Behavior and Modal State
The reset behavior at the end of a program, after an M30, or after a manual reset, is a critical difference between the two architectures.
| Event | Siemens | Fanuc |
|---|---|---|
| M30 in main program | Rewind to first block of main program (MPF) | Rewind to first block of currently active program |
| Reset button pressed | Cursor jumps to first block of main program (MPF) | Cursor remains at first block of the program that was last being executed (which may be a subprogram) |
| M99 at end of subprogram | Returns to caller (one stack pop) | Returns to caller (one stack pop) |
| M99 at end of main program (no M98 context) | Not commonly used; behavior controller-dependent | Loops program back to first block and re-executes |
| Modal G-codes after M30 | Reset to defaults per $MC_GCODE_RESET_VALUES | Reset to defaults per parameter 3401–3430 series |
PAL vs DIN 66025
PAL (Programmablauf or Programmier-Arbeits-Lehre, depending on the era) is a training-oriented subset of DIN 66025 used in German vocational curricula for CNC machining apprenticeships. The relationship between the two standards is summarized below.
| Aspect | DIN 66025 | PAL |
|---|---|---|
| Status | Industry standard (Norm) | Training standard (Ausbildungsstandard) |
| Scope | Full NC programming language | Restricted subset suitable for classroom machines |
| M98 / M99 | Defined (class-6 functions) | Generally not included |
| M17 / M30 | Defined | Included |
| Subroutine call syntax | Manufacturer-specific (L / CALL / M98) | L<number> P<count> Siemens-style is taught |
The fact that the two are often cited together in classroom material leads to confusion when students encounter machines that implement only a subset of the standard. The class-6 functions (M98, M99) are explicitly not part of PAL and must be unblocked at the machine level before they can be programmed.
Bosch Rexroth MTX Implementation (DIN 66025-Strict)
The Bosch Rexroth IndraMotion MTX controller follows the Siemens convention but adds a clearly documented DIN 66025 mapping. Per the official programming manual, the following NC functions are exposed with DIN 66025 syntax.
| NC Function | DIN 66025 Syntax | Description |
|---|---|---|
| Linear interpolation | G0 / G1 | Rapid / linear feed |
| Circular interpolation | G2 / G3 | CW / CCW |
| Spindle CW / CCW / stop | M3 / M4 / M5 | Class-1 spindle functions |
| Coolant on / off | M8 / M9 | Class-1 auxiliary |
| End of program / subprogram | M30 / M17 | Per DIN 66025-1 |
| Subprogram call | L<num> P<count> | Siemens-compatible |
The full function catalog is documented in the Bosch Rexroth NC Functions per DIN 66025 manual. When porting programs between Bosch Rexroth MTX and Siemens controllers, the syntax is generally interchangeable, but verify custom M-codes against the target machine's option list.
Verification Procedure
After converting or commissioning a DIN 66025 subroutine-based program, perform the following checks before running production parts.
- Identify the controller platform. Read the HMI splash screen, the system-status page, or the machine-data screen to determine whether the control is Siemens (SINUMERIK 810/820/840C/840D sl/ONE), Fanuc (Series 0i/30i/31i/32i), Bosch Rexroth MTX, or Heidenhain. Do not assume compatibility based on the brand of the machine tool alone.
-
List the installed NC options. On Fanuc, press
SYSTEM→PARAMETER→ search for option-bitFSSBand macro-related parameters; confirm M98/M99 are enabled. On Siemens, checkMD10715/$MN_MM_LUD_VALUE_MEMand the option tree in the HMI for "subroutine expansion" or "class-6 M-functions." -
Verify file-system naming. On Siemens, confirm the program file is stored as
SPF<number>.SPFin the correct NC directory (typically/_N_CST_DIR/_N_SPF_DIR/on HMI-Advanced, or underNC/Programs/Subprograms/on SINUMERIK ONE). On Fanuc, verify the program is in the active program library under itsOnumber. -
Dry-run in single block. Set
SINGLE BLOCK = ON(SBL on Fanuc, EINCBL on Siemens) and step through the program line-by-line, observing modal G-codes and modal M-codes in the status display. -
Check call/return nesting. Set a higher single-block granularity (e.g.,
DEC1on Siemens,SBKon Fanuc) and confirm that eachM17orM99returns to the correct line in the calling program. Watch the block-counter and program-pointer displays. - Test reset behavior. While the subprogram is executing, press the Reset button and verify that the cursor returns to the expected position (main program on Siemens, last active program on Fanuc).
-
Repeat-count verification. Execute a call with a known repeat count (e.g.,
L10 P5) and verify that the subprogram runs exactly five times by counting a visible marker (e.g., a tool change or a probing event). -
Production dry run. Run the program on a scrap part with
DRY RUN(SiemensDRY, Fanuc parameter 1400 bit DRN) enabled at 50 % rapid feed to catch any modal-state issues.
Troubleshooting Matrix
| Symptom | Likely Cause | Controller-Specific Fix |
|---|---|---|
| Alarm "Subprogram not found" after L45 / M98 P45 | File not loaded in active program library or wrong extension | Siemens: ensure file is SPF45.SPF and in SPF_DIR. Fanuc: ensure O0045 is in the active library. |
| Program executes main loop but ignores repeat count | P/L word misinterpreted (address conflict) | Siemens: L45 P03 (P=count). Fanuc: M98 P45 L3 (L=count). Swap argument positions. |
| After Reset, wrong program is at cursor | Reset landed in last-executed subprogram | Fanuc-specific behavior; switch to main program via MDI → O<main> before reset, or press Reset from AUTO while in the main program. |
| M99 causes program to re-execute main loop | M99 placed at end of main program without M30 | Replace M99 with M30 in main programs. Keep M99 only inside subprograms. |
| Nested subprogram alarm at depth 8 | Stack depth exceeded | Siemens: increase $MN_MM_MAX_SKB_DEPTH (verify SW option). Fanuc: nesting limit is hardware-fixed at 4 on most Series 0i controllers; refactor to eliminate deep nesting. |
| M98/M99 not recognized, syntax alarm 007 | Class-6 option not enabled on machine | Enable the option in machine builder configuration. On Fanuc 0i, set parameter 1201.7 (M98 enable) and 1201.8 (M99 enable). |
| Modal G-codes carry over after M30 unexpectedly | Reset modal state not cleared | Siemens: review $MC_GCODE_RESET_VALUES. Fanuc: review parameter 3401–3430 series and 4001–4130. |
| Symbolic CALL "name" not found on Siemens | Symbol table not loaded or name case mismatch | Check program name string in NC/Programs, verify _N_MPF_DIR/_N_DRILL_45_MPF naming, and confirm name resolution is enabled in MD19400. |
Practical Field Notes
When retrofitting older machines or commissioning new installations, observe the following field-proven rules:
- Document the platform first. Place a header comment block in every program naming the controller type and software version. Siemens 840D sl behaves slightly differently across SW 4.x and 5.x regarding G-code reset values; Fanuc Series 0i-MF differs from 0i-TF in macro handling.
- Prefer M30 over M99 for main programs. M99-as-end-of-main is a common Fanuc pitfall; replacing it with M30 forces a clean rewind.
- Use absolute repeat counts. Avoid relying on modal repeat counts where the P/L argument is implied by a previous block. Always specify the count explicitly to make conversion easier.
- Keep nesting shallow. Restrict nesting to 3 levels or less to remain portable across controllers with hard limits.
- Test on the actual machine, not in the CAM simulator. CAM post-processors frequently emit "DIN 66025" syntax that is actually Siemens- or Fanuc-specific. The simulator may accept syntax the machine rejects (or vice versa).
FAQ
What is the difference between DIN 66025 and PAL?
DIN 66025 is the full industry standard for NC programming. PAL is a smaller training-oriented subset used in vocational curricula; it excludes class-6 functions such as M98 and M99. Always confirm which scope a given textbook or program follows before relying on a specific M-code.
Does Fanuc use M98 or L for subroutine calls?
Fanuc uses M98 P<program> to call a subprogram and M99 to return. The L word on Fanuc is the repeat count, the opposite of Siemens, where L is the subprogram number and P is the repeat count. A line L45 P03 on Fanuc is parsed as a linear move to coordinate L=45 with a 3-second dwell, not a subroutine call.
Why does Reset on a Fanuc machine leave the cursor in a subprogram?
Fanuc does not distinguish main and subprograms at the file-system level. After Reset, the controller returns the cursor to the first block of the program that was last active, which is often the subprogram rather than the main program. Siemens, by contrast, separates MPF and SPF files and always returns to the main program (MPF) on Reset.
Can M99 replace M30 at the end of a Fanuc main program?
Technically yes, but M99 will loop the program back to its first block and re-execute it indefinitely. Use M30 for a clean end-of-program rewind. Reserve M99 for subprogram termination.
How deep can subprograms be nested on Siemens and Fanuc?
Siemens 840D sl supports up to 16 nesting levels by default, adjustable via the machine data $MN_MM_MAX_SKB_DEPTH. Fanuc Series 0i supports 4 levels of nesting hardware-limited, and Series 30i/31i/32i typically supports up to 10 levels. Keep nesting shallow (3 levels or less) for maximum portability.