M98 and M99 are how you stop writing the same moves over and over. If a part has the same feature in four places, you write the routine once as a subprogram and call it four times. The pair is common on Fanuc-style controls, including many that follow the same conventions.

How the pair works

  • M98 calls a subprogram by its program number. The control jumps to that subprogram, runs it, and comes back.
  • M99, placed at the end of the subprogram, returns control to the line right after the M98 call.

You can also repeat the call. A common form looks like M98 P1000 L3, meaning run subprogram O1000 three times. The exact way the program number and repeat count are written differs between controls, so this is the place to check your machine manual rather than assume.

A simple example

O0001 (MAIN PROGRAM)
...
M98 P1000 L3   (call subprogram O1000, repeat 3 times)
...
M30            (end main program)

O1000 (SUBPROGRAM)
...            (the reused routine)
M99            (return to the main program)

The main program calls O1000 three times, and each time M99 sends control back so the main program continues.

M99 vs M30

CodeWhat it doesWhere it lives
M99Returns from a subprogramEnd of a subprogram
M30Ends and rewinds the programEnd of the main program
M98Calls a subprogramIn the main program

Beginners sometimes confuse M99 (return) with M30 (end). The breakdown of program-end codes is in common M-codes for CNC beginners.

Where this fits

M98 and M99 are a step past the common M-codes, the kind of topic a journeyman machinist test expects. Make the basics automatic first with beginner CNC code practice, then layer on subprograms. On LinuxCNC, the same job is done with O-word subroutines instead of M98/M99. A free tool like G-Code Sprint drills the foundational codes. This is an educational overview; confirm exact syntax and behavior against your control’s manual.

Bottom line

M98 calls a subprogram, M99 returns from it, and together they let you reuse code. Repeats are added to the call, with syntax that varies by control. Do not confuse M99 (return) with M30 (program end).

Sources

Frequently asked questions

What do M98 and M99 do?

M98 calls a subprogram by its program number, so the control runs that separate routine and then comes back. M99, placed at the end of the subprogram, returns control to the line right after the M98 call. They let you reuse a block of code instead of repeating it.

How do you repeat a subprogram with M98?

You add a repeat count to the call, commonly written like M98 P1000 L3 to run subprogram 1000 three times. The exact way repeats are specified differs between controls, so check your machine’s manual.

What is the difference between M99 and M30?

M99 returns from a subprogram back to the calling program. M30 ends the main program entirely and rewinds it. M99 hands control back; M30 stops the show.

G-Code Sprint is a study and practice tool only. It is not a CNC simulator, machine controller, or safety authority. Always follow your instructor, employer, machine manual, and shop safety procedures.