CNC Simulator
G-code · Lathe · Mill

G-code and M-code reference: Fanuc lathe and mill, Haas

What each G and M code does on each control, as CNC Simulator runs it. The same explanations appear in the app’s learning mode when you hover a code in the program.

Try the codes in the free simulator

Fanuc 0i-TF lathe (G-code system B, Romi GL)

G codes

CodeWhat it does
G00Rapid positioning at the machine's top speed, not cutting. Use it only in free air: a rapid into the stock is a crash.
G01Straight cut at feed F to the programmed point.
G02Clockwise arc to the end point, seen from the plane's positive axis. Center with I/J/K (from the start point) or radius R.
G03Counterclockwise arc to the end point. Center with I/J/K (from the start point) or radius R.
G04Dwell: waits P (milliseconds, no decimal point) or X/U (seconds) without moving.
G07.1Cylindrical interpolation. Cylindrical interpolation: C is unrolled on the diameter, for slots around a shaft.
G10Programmable data input (work offsets L2/L20). Writes offsets from the program: L2/L20 work offsets, L10–L13 tool offsets (lathe: P n wear, P 10000+n geometry).
G12.1Polar coordinate interpolation X/C. Polar interpolation on: X (diameter) and C become a flat XC plane, for milling the face of a part with a live tool.
G13.1Polar interpolation off.
G17Plane XY for arcs and cutter compensation (machining centers).
G18Plane ZX for arcs and compensation (the turning plane on lathes).
G19Plane YZ for arcs and compensation.
G20Units in inches.
G21Units in millimeters.
G28Return to the machine reference point through the programmed point (G91 G28 Z0 goes straight up from where it is).
G32Thread cutting. Thread cutting move: a straight cut synchronized with the spindle, F = lead.
G40Cancels cutter (or nose) radius compensation. Cancel with a move away from the part.
G41Cutter radius compensation to the left of the path (climb milling on outside contours). Radius from D (lathe: nose radius of the T offset). Start it with a straight move.
G42Cutter radius compensation to the right of the path. Radius from D (lathe: nose radius). Start it with a straight move.
G53Move in machine coordinates for this block only, ignoring work offsets and tool length.
G54Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G55Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G56Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G57Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G58Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G59Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G65Macro call (G65 P n): runs program O n once, with the letters as arguments (A → #1, B → #2, …).
G66Modal macro call: the macro runs after every move until it is cancelled.
G67Cancels the modal macro call.
G70Finishing cycle (G70 P Q): runs the shape between blocks N P and N Q once, with the finishing feed, after G71/G72/G73.
G71Longitudinal roughing. Stock removal in turning (G71). First block: U depth of cut (radius) and R retract. Second block: P and Q are the N numbers of the first and last block of the finished shape, U/W the finishing allowance in X (diameter) and Z, F the roughing feed.
G72Face roughing. Stock removal in facing (G72): like G71, but the passes run along X, stepping in Z (W depth).
G73Pattern repeating. Pattern repeating (G73): the finished shape is followed several times, closer each time; for forged or cast parts. U/W relief, R number of passes.
G74Face peck drilling / turning with peck. Peck cycle along Z (face grooving or deep drilling on the axis).
G75Grooving / facing. Peck grooving along X.
G76Multiple threading (G76). First block: P (passes of finish, chamfer, angle, as 6 digits), Q minimum depth, R finishing allowance. Second block: X Z thread root at the end, P thread height, Q first depth (microns), F lead.
G77Single turning cycle: rapid in, cut to X Z, out and back, in one block. R makes a taper. Repeat with only the next X.
G78Single threading cycle: one pass per block, F = lead. Program the next diameter for each pass.
G79Single facing cycle: like the turning cycle, but cutting along X. R makes a taper in Z.
G80Cancels the active drilling cycle: the next X/Y no longer drills.
G83Face drilling. Drilling cycle: rapid to R, feed to Z, rapid out (G82 with a dwell P at the bottom). Repeats at each X/Y until G80.
G84Face tapping. Tapping cycle: feed F must be the pitch × rpm (or the pitch with feed per revolution); the spindle reverses at the bottom.
G85Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G87Radial drilling with a live tool, along X toward the axis.
G88Radial tapping with a live tool.
G90Absolute coordinates: every value is a position from the work zero.
G91Incremental coordinates: every value is a distance from where the tool is.
G92Set origin or max spindle speed. Sets the current position as the given coordinates (G92 on mills, G50 on system A lathes); on lathes it also limits the spindle speed with S.
G94Feed F in mm/min.
G95Feed F in mm per spindle revolution (the usual on lathes).
G96Constant cutting speed: S is in m/min and the rpm rises as the diameter gets smaller. Limit it with G50/G92 S.
G97Constant spindle speed: S in rpm.
G98After each hole the tool returns to the initial level (where the cycle started): safe over clamps.
G99After each hole the tool returns to the R level: faster, for a flat part without obstacles.

M codes

CodeWhat it does
M00Program stop: the machine stops until cycle start (to measure, clean chips, turn the part).
M01Optional stop: stops only with the M01 key on.
M02End of program.
M03Spindle, or live tool when S2= is given, clockwise. Spindle on, clockwise (S sets the speed).
M04Spindle on, counterclockwise.
M05Also releases the M85 brake. Spindle stop.
M08Coolant on.
M09Coolant off.
M15Reverse coupling shaft rotation (counter-clockwise). Machine function with no effect on the path.
M16Reverse coupling shaft rotation (clockwise). Machine function with no effect on the path.
M19Spindle orientation / enable C axis. C axis mode: the spindle becomes a positioning axis.
M26Retract the servo tailstock to its set position (Romi GL manual 11.3.4). Backs the tailstock center off the part.
M27Advance the servo tailstock to the part (Romi GL manual 11.3.4). Advances the tailstock center to the part. Do not face to the axis or back off along it while it is there.
M30End of program and back to the start.
M31Retract the servo tailstock to its machine reference. Backs the tailstock center off the part.
M85High-torque brake; G0 C or M5 release it. Clamps the axis (brake) to cut without it turning.
M98Calls subprogram P (O number); L or the leading digits of P repeat it.
M99End of subprogram: returns to the block after the call.

Fanuc 0i-MF machining center

G codes

CodeWhat it does
G00Rapid positioning at the machine's top speed, not cutting. Use it only in free air: a rapid into the stock is a crash.
G01Straight cut at feed F to the programmed point.
G02Clockwise arc to the end point, seen from the plane's positive axis. Center with I/J/K (from the start point) or radius R.
G03Counterclockwise arc to the end point. Center with I/J/K (from the start point) or radius R.
G04Dwell: waits P (milliseconds, no decimal point) or X/U (seconds) without moving.
G10Programmable data input (work offsets L2/L20). Writes offsets from the program: L2/L20 work offsets, L10–L13 tool offsets (lathe: P n wear, P 10000+n geometry).
G17Plane XY for arcs and cutter compensation (machining centers).
G18Plane ZX for arcs and compensation (the turning plane on lathes).
G19Plane YZ for arcs and compensation.
G20Units in inches.
G21Units in millimeters.
G28Return to the machine reference point through the programmed point (G91 G28 Z0 goes straight up from where it is).
G40Cancels cutter (or nose) radius compensation. Cancel with a move away from the part.
G41Cutter radius compensation to the left of the path (climb milling on outside contours). Radius from D (lathe: nose radius of the T offset). Start it with a straight move.
G42Cutter radius compensation to the right of the path. Radius from D (lathe: nose radius). Start it with a straight move.
G43Tool length compensation with offset H: Z positions are measured at the tool tip. A wrong H puts the tip too high or into the part.
G49Cancels tool length compensation.
G53Move in machine coordinates for this block only, ignoring work offsets and tool length.
G54Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G54.1Additional work offset (P1–P48). Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G55Work offset 2. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G56Work offset 3. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G57Work offset 4. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G58Work offset 5. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G59Work offset 6. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G65Macro call (G65 P n): runs program O n once, with the letters as arguments (A → #1, B → #2, …).
G80Cancels the active drilling cycle: the next X/Y no longer drills.
G81Drilling cycle: rapid to R, feed to Z, rapid out (G82 with a dwell P at the bottom). Repeats at each X/Y until G80.
G83Peck drilling: drills Q at a time and backs out to break or clear the chip, down to Z.
G84Tapping cycle: feed F must be the pitch × rpm (or the pitch with feed per revolution); the spindle reverses at the bottom.
G85Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G90Absolute coordinates: every value is a position from the work zero.
G91Incremental coordinates: every value is a distance from where the tool is.
G94Feed F in mm/min.
G95Feed F in mm per spindle revolution (the usual on lathes).
G98After each hole the tool returns to the initial level (where the cycle started): safe over clamps.
G99After each hole the tool returns to the R level: faster, for a flat part without obstacles.

M codes

CodeWhat it does
M00Program stop: the machine stops until cycle start (to measure, clean chips, turn the part).
M01Optional stop: stops only with the M01 key on.
M02End of program.
M03Spindle on, clockwise (S sets the speed).
M04Spindle on, counterclockwise.
M05Spindle stop.
M06Tool change to the tool T. Go to a safe place first (G28 or the change position).
M08Coolant on.
M09Coolant off.
M30End of program and back to the start.
M98Calls subprogram P (O number); L or the leading digits of P repeat it.
M99End of subprogram: returns to the block after the call.

Haas NGC mill

G codes

CodeWhat it does
G00Rapid positioning at the machine's top speed, not cutting. Use it only in free air: a rapid into the stock is a crash.
G01Straight cut at feed F to the programmed point.
G02Clockwise arc to the end point, seen from the plane's positive axis. Center with I/J/K (from the start point) or radius R.
G03Counterclockwise arc to the end point. Center with I/J/K (from the start point) or radius R.
G04Dwell: waits P (milliseconds, no decimal point) or X/U (seconds) without moving.
G09Exact stop. Control function with no effect on the path.
G10Set offsets (L2/L20 work, L10–L13 tool). Writes offsets from the program: L2/L20 work offsets, L10–L13 tool offsets (lathe: P n wear, P 10000+n geometry).
G12Circular pocket CW. Circle or pocket milling cycle (not drawn by the simulator yet).
G13Circular pocket CCW. Circle or pocket milling cycle (not drawn by the simulator yet).
G17Plane XY for arcs and cutter compensation (machining centers).
G18Plane ZX for arcs and compensation (the turning plane on lathes).
G19Plane YZ for arcs and compensation.
G20Units in inches.
G21Units in millimeters.
G28Return to the machine reference point through the programmed point (G91 G28 Z0 goes straight up from where it is).
G29Return from reference. Control function with no effect on the path.
G31Skip function. Control function with no effect on the path.
G35Tool diameter measure. Control function with no effect on the path.
G36Work offset probing. Control function with no effect on the path.
G37Tool length measure. Control function with no effect on the path.
G40Cancels cutter (or nose) radius compensation. Cancel with a move away from the part.
G41Cutter radius compensation to the left of the path (climb milling on outside contours). Radius from D (lathe: nose radius of the T offset). Start it with a straight move.
G42Cutter radius compensation to the right of the path. Radius from D (lathe: nose radius). Start it with a straight move.
G43Tool length compensation with offset H: Z positions are measured at the tool tip. A wrong H puts the tip too high or into the part.
G44Tool length compensation with offset H: Z positions are measured at the tool tip. A wrong H puts the tip too high or into the part.
G47Text engraving. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G49Cancels tool length compensation.
G50Scaling cancel. Control function with no effect on the path.
G51Scaling. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G52Local coordinate system shifted from the work offset (not drawn by the simulator yet).
G53Move in machine coordinates for this block only, ignoring work offsets and tool length.
G54Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G54.1Additional work offset P1–P99. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G55Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G56Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G57Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G58Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G59Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G61Exact stop modal. Control function with no effect on the path.
G64Exact stop cancel. Control function with no effect on the path.
G65Macro call (G65 P n): runs program O n once, with the letters as arguments (A → #1, B → #2, …).
G68Coordinate rotation by R degrees around the given point (not drawn by the simulator yet).
G69Coordinate rotation off.
G70Bolt hole circle. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G71Bolt hole arc. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G72Bolt holes along an angle. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G73High-speed peck drilling. Peck drilling: drills Q at a time and backs out to break or clear the chip, down to Z.
G74Reverse tapping. Tapping cycle: feed F must be the pitch × rpm (or the pitch with feed per revolution); the spindle reverses at the bottom.
G76Fine boring. Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G77Back boring. Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G80Cancels the active drilling cycle: the next X/Y no longer drills.
G81Drilling cycle: rapid to R, feed to Z, rapid out (G82 with a dwell P at the bottom). Repeats at each X/Y until G80.
G82Spot drill with dwell. Drilling cycle: rapid to R, feed to Z, rapid out (G82 with a dwell P at the bottom). Repeats at each X/Y until G80.
G83Peck drilling: drills Q at a time and backs out to break or clear the chip, down to Z.
G84Tapping cycle: feed F must be the pitch × rpm (or the pitch with feed per revolution); the spindle reverses at the bottom.
G85Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G86Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G87Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G88Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G89Boring cycle: feed in to Z and out (how it comes out, feed or rapid, stopped or turning, depends on the code).
G90Absolute coordinates: every value is a position from the work zero.
G91Incremental coordinates: every value is a distance from where the tool is.
G92Sets the current position as the given coordinates (G92 on mills, G50 on system A lathes); on lathes it also limits the spindle speed with S.
G93Inverse time feed. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G94Feed F in mm/min.
G95Feed F in mm per spindle revolution (the usual on lathes).
G98After each hole the tool returns to the initial level (where the cycle started): safe over clamps.
G99After each hole the tool returns to the R level: faster, for a flat part without obstacles.
G100Mirror image off.
G101Mirror image (not drawn by the simulator yet).
G103Block lookahead. Control function with no effect on the path.
G107Cylindrical interpolation: C is unrolled on the diameter, for slots around a shaft.
G110Work offset = G154 P1. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G111Work offset = G154 P2. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G112Work offset = G154 P3. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G113Work offset = G154 P4. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G114Work offset = G154 P5. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G115Work offset = G154 P6. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G116Work offset = G154 P7. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G117Work offset = G154 P8. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G118Work offset = G154 P9. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G119Work offset = G154 P10. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G120Work offset = G154 P11. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G121Work offset = G154 P12. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G122Work offset = G154 P13. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G123Work offset = G154 P14. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G124Work offset = G154 P15. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G125Work offset = G154 P16. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G126Work offset = G154 P17. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G127Work offset = G154 P18. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G128Work offset = G154 P19. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G129Work offset = G154 P20. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G1413D cutter compensation. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G150General purpose pocketing. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G154Additional work offset P1–P99. Selects a work offset (part zero) from the OFFSET table: G54–G59, G54.1 P n (Haas G154 P n).
G187Smoothness / accuracy. Control function with no effect on the path.
G234Tool center point control (TCPC). Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G254Dynamic work offset (DWO). Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G255DWO cancel. Control function with no effect on the path.
G268Feature coordinates. Accepted by the control, but the simulator does not draw it yet: the path after it may differ from the machine.
G269Feature coordinates cancel. Control function with no effect on the path.

M codes

CodeWhat it does
M00Program stop: the machine stops until cycle start (to measure, clean chips, turn the part).
M01Optional stop: stops only with the M01 key on.
M02End of program.
M03Spindle on, clockwise (S sets the speed).
M04Spindle on, counterclockwise.
M05Spindle stop.
M06Tool change to the tool T. Go to a safe place first (G28 or the change position).
M07Shower coolant. Coolant on.
M08Coolant on.
M09Coolant off.
M104th axis brake. Clamps the axis (brake) to cut without it turning.
M114th axis brake release. Releases the axis brake.
M125th axis brake. Clamps the axis (brake) to cut without it turning.
M135th axis brake release. Releases the axis brake.
M19Spindle orient. Machine function with no effect on the path.
M30End of program and back to the start.
M31Chip conveyor forward. Machine function with no effect on the path.
M33Chip conveyor stop. Machine function with no effect on the path.
M34Coolant spigot down. Machine function with no effect on the path.
M35Coolant spigot up. Machine function with no effect on the path.
M41Low gear. Machine function with no effect on the path.
M42High gear. Machine function with no effect on the path.
M73Tool air blast on. Machine function with no effect on the path.
M74Tool air blast off. Machine function with no effect on the path.
M83Auto air jet on. Machine function with no effect on the path.
M84Auto air jet off. Machine function with no effect on the path.
M88Through-spindle coolant. Coolant on.
M89Through-spindle coolant off. Coolant off.
M95Sleep mode. Machine function with no effect on the path.
M96Jump if no input. Machine function with no effect on the path.
M97Local subprogram call (P = N number). Haas local subprogram: jumps to block N P of this same program and comes back at M99; L repeats.
M98Calls subprogram P (O number); L or the leading digits of P repeat it.
M99End of subprogram: returns to the block after the call.
M109Interactive user input. Machine function with no effect on the path.