M98

Machining center, Lathe

Subprogram call

Format and notes

M98 P_ (ISO dialect: the lower 4 digits of P are the program number and the upper digits are the repeat count. Example: M98 P30021 calls O0021 three times)

M00–M02, M30, M98 and M99 stop, end or call programs, and their meaning is almost the same in all the sources we checked (sources that differ are listed in the table below). M98 and M99 are handled inside the CNC (the Siemens ISO dialect manual treats M90–M99 as CNC-internal). Most other M codes are assigned by the machine builder.

Try it in the simulator (machining center)

M98 P2000 L3 calls subprogram O2000 three times and M99 returns. Inside it is incremental (G91), so each call moves 15 mm in X.

    X—
    Y—
    Z—
    T—
    S0
    F0
    —0:00

      Differences between controls and machines

      The same code can be written or assigned differently depending on the CNC control and the machine builder. Always check your machine’s manual.

      “One source / reference” rows were confirmed in only one source. “CAM post output / reference” rows show what a CAM post processor outputs and could not be confirmed in the control maker’s own public documents.

      SourceMachineItemDetail
      HaasMachining centerFormatM98 P_ (number) L_ (repeat count 1–99)Haas specifies the repeat count with L. A subprogram within the same program is M97
      Siemens (ISO dialect)LatheFormatWhen combining the repeat count into P, use a 4-digit count + 4-digit number (lathe manual). The count can also be written with L_ (1–9999), and L takes priority
      Siemens (ISO dialect)Machining centerFormatWhen combining the repeat count into P, use a 3-digit count + 4-digit number (milling manual)
      Mitsubishi Electric—FormatM98 P_ H_ L_ ,D_. P is the number (up to 8 digits), H is the sequence number in the called program (start from that line), L is the repeat count 1–9999 (L0 is not executed), and ,D is the device number. It can also be called with M98 <file name>. Nesting is 8 levels
      Siemens (native)—FormatCall a subprogram just by writing its name. P is the repeat count (1–9999), the opposite of P (number) in the ISO dialect
      LinuxCNC—FormatM98 P_ L_ can be used. L0 is not executed. Place the subprogram to be called after the call
      CAM post for Okuma (Autodesk)Machining centerFormatCall with CALL O_ (4-character name); the subprogram ends with RTS. How to write the repeat count is not confirmed in public documentsCAM post output / reference

      Frequently asked questions about M98

      What is M98 (Subprogram call) used for and how is it formatted in a CNC program?
      M98 commands "Subprogram call" on Machining center, Lathe. The standard program format is "M98 P_ (ISO dialect: the lower 4 digits of P are the program number and the upper digits are the repeat count. Example: M98 P30021 calls O0021 three times)". The subprogram ends with M99
      Is M98 a modal code or a one-shot (non-modal) code?
      Whether M98 acts modally or as a single-block command depends on the CNC control and the machine builder’s PLC ladder implementation. Check your machine’s active modal status screen and programming manual before running in auto mode.
      Does M98 work differently on machining centers (mills) versus CNC lathes?
      M98 is primarily used on Machining center, Lathe. Depending on the machine type and the lathe G-code system (System A, B, or C), this code may be unavailable or assigned to a different function, so verify against your machine tool manual.
      Are there differences in M98 across FANUC, Mitsubishi, Okuma, Haas, and Siemens controls?
      Yes. Control builders such as FANUC, Mitsubishi Electric (M80/M800), Okuma (OSP), Haas, Mazak, Siemens (SINUMERIK ISO dialect), and Heidenhain can differ in argument letters, decimal-point rules, and optional parameters for M98. Review the control comparison table above and verify the exact syntax in your machine’s programming manual before proving out the program.
      When should I use M98 (Subprogram Call) versus G65 (Custom Macro Call)?
      M98 Pxxxx simply branches to a subprogram (with optional L repeat count) without passing parameters. G65 Pxxxx lets you pass letter arguments (A, B, C, etc.) into local variables (#1–#33), making G65 ideal when the same routine needs different diameters, depths, or coordinates.

      Sources

      The meaning of this code agrees in two or more sources from different publishers. Explanations are written in our own words.

      1. Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Milling, 04.2007 Edition (6FC5398-7BP10-0BA0) cache.industry.siemens.com
      2. Haas Automation, Inc. — Mill Operator's Manual – 18 Mill M-Codes (online version) haascnc.com
      3. Haas Automation, Inc. — Lathe Operator's Manual – 17 Lathe M-Codes (online version) haascnc.com
      4. Haas Automation, Inc. — M98 Sub Program Call (machining center, per-code explanation page) haascnc.com
      5. Siemens AG — SINUMERIK 802D sl/840D/840D sl/840Di/840Di sl/810D Programming Manual ISO Turning, 04.2007 Edition cache.industry.siemens.com
      6. Mitsubishi Electric — MITSUBISHI CNC 700/70 Series Programming Manual (Lathe System) (IB-1500057) mitsubishielectric.com
      7. Siemens AG — SINUMERIK 840D sl/840D/840Di sl/810D Fundamentals, Programming Manual, Edition 08/2005 (6FC5398-1BP10-0BA0) cache.industry.siemens.com
      8. LinuxCNC project — O Codes (LinuxCNC Documentation) linuxcnc.org
      9. Autodesk — OKUMA milling post processor (okuma.cps, Fusion post library) cam.autodesk.com