G code is the standard programming language for CNC machines, and a basic cheat sheet gives you the essential commands to read and write simple programs. The most important codes are G00 (rapid move), G01 (linear feed move), G02/G03 (arc moves), G90/G91 (absolute/incremental positioning), and M03/M05 (spindle on/off). With these, you can run a safe first job and understand what most programs are doing.
Start Here: The Core G Codes You Will Use Daily
Every G code program is a list of instructions that tells the machine where to move and how fast. The machine reads them line by line, and each line is called a block. A block can contain several commands, but the most important ones are the motion codes.
- G00 – Rapid move: Moves the tool as fast as possible to a point. Use it for positioning, never for cutting.
- G01 – Linear feed move: Moves the tool in a straight line at a set feed rate (F). Use it for cutting.
- G02 – Arc clockwise: Moves the tool in a clockwise arc. You must specify the radius or the arc’s center (I, J, K).
- G03 – Arc counterclockwise: Same as G02 but counterclockwise.
- G90 – Absolute positioning: Coordinates are measured from the machine’s zero point (origin).
- G91 – Incremental positioning: Coordinates are measured from the current tool position.
- G20/G21 – Units: G20 sets inches, G21 sets millimeters. Always check this first.
These seven codes cover most of what you need for simple parts. The rest are for tool changes, spindle control, and program flow.
M Codes: Spindle, Coolant, and Program End
M codes control the machine’s auxiliary functions, not the motion. The most common are:
- M03 – Spindle on (clockwise): Starts the spindle rotating. You set the speed with S (e.g., S1200 for 1200 RPM).
- M04 – Spindle on (counterclockwise): Rarely used except for tapping or left-hand tools.
- M05 – Spindle stop: Stops the spindle.
- M06 – Tool change: Pauses the program so you can change the tool. Usually paired with a T number (e.g., T02).
- M08 – Coolant on: Turns on flood coolant.
- M09 – Coolant off: Turns off coolant.
- M30 – Program end and rewind: Ends the program and resets to the top. Use this at the end of every program.
Some machines use M02 (program end) instead of M30. M02 stops but does not rewind. Both work, but M30 is more common on modern controls.
How to Read a G Code Line: A Worked Example
Consider this line from a program:
N10 G90 G01 X10.0 Y5.0 F100.0
Here is what each part means:
- N10 – Line number (optional, used for reference).
- G90 – Use absolute coordinates.
- G01 – Linear feed move.
- X10.0 Y5.0 – Move to X=10, Y=5 (in inches or mm, depending on G20/G21).
- F100.0 – Feed rate of 100 units per minute (inches per minute or mm/min).
If the machine is in absolute mode (G90), it goes to that exact point from wherever it is. In incremental mode (G91), it would move 10 units in X and 5 units in Y from the current position.
Now, a full simple program to cut a 1-inch square (assuming a 0.25-inch end mill, starting at the corner):
G90 G21– Absolute, millimeters.G00 X0 Y0 Z5.0– Rapid to start point above the part.M03 S1200– Spindle on at 1200 RPM.G01 Z-1.0 F50.0– Plunge to depth at feed 50 mm/min.G01 X25.0 F100.0– Cut to X=25.G01 Y25.0– Cut to Y=25.G01 X0– Cut back to X=0.G01 Y0– Cut back to Y=0.G00 Z5.0– Rapid up to safe height.M05– Spindle off.M30– End program.
Notice that the feed rate stays at 100 unless you change it. The Z move uses a slower feed (50) to avoid breaking the tool.
Common Mistake: Forgetting to Cancel Modal Codes
A common beginner error is assuming that G00 or G01 cancels the other. They are both modal, meaning they stay active until another code from the same group is used. If you write G00, then later write a line with only X and Y, the machine will still be in rapid mode and may crash into the part. Always explicitly state G01 before a cutting move.
Similarly, G90 and G91 are modal. If you switch to G91 for a few moves, you must switch back to G90 if you want absolute coordinates again. A good habit is to put G90 and G21 at the top of every program.
Another mistake is using G00 to move down to the part. Always use G01 for any move that touches the material. G00 is for positioning only, and the rapid speed can break tools or damage the work.
Building Your Own Cheat Sheet: What to Add Next
Once you have the basics, you will need a few more codes for real jobs:
- G28 – Return to machine home: Moves to a fixed reference point. Useful at the end of a program.
- G43 – Tool length offset: Applies the tool length compensation (H number). Without it, your Z moves will be wrong.
- G49 – Cancel tool length offset.
- G54 – Work coordinate system 1: Selects the part zero. Most machines have several (G54–G59) for different fixtures.
- G80 – Cancel canned cycle: If you use drilling cycles (G81–G89), you must cancel them with G80.
For drilling, the most common canned cycle is G81 (simple drill) and G83 (peck drill). A line like G81 X10.0 Y10.0 Z-5.0 R1.0 F50.0 drills a hole at X10, Y10, to a depth of -5, with a retract plane at 1.0.
Write these on a card and keep it near the machine. As you learn, add your own notes for your specific control (Fanuc, Haas, LinuxCNC, etc.). The labels on your machine’s screen may differ slightly, but the codes are standard across most industrial controls.
Safety First: What to Check Before You Run Any Program
Before you press cycle start, do a dry run without the spindle on. Use the machine’s single-block mode to step through the program and watch the tool path on the display. Check that the tool does not hit clamps or the vise. Make sure the workpiece is securely clamped and the tool is tight in the holder.
If you are unsure about a code, look it up in your machine’s manual. A wrong G code can cause a crash, and crashes are expensive. When in doubt, lower the feed rate and spindle speed. It is better to cut slowly than to break a tool.
For breathing exercises, stop if you feel dizzy. For stretching, move slowly and skip anything that hurts. For herbal teas, some herbs interact with medicines and are not advised in pregnancy; ask your doctor or midwife. Never leave a burning candle unattended.
Related
- Chess for Beginners Cheat Sheet: Rules and Moves
- How to Start a Basic Journal (Step-by-Step Guide)
- How to Start Basic Yoga at Home for Beginners
General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more
Spotted an error? Tell us and we will correct it (corrections policy).