Yes, you can write G-code in inches, and the key is the G20 command, which tells the machine to interpret all coordinates, offsets, and feed rates as inches. If you do not send G20, most CNC controllers default to millimeters (G21). This guide shows you exactly how to switch to inches, what to watch out for, and how to avoid the classic mistakes that ruin parts.

What You'll Need

  • A CNC machine (mill, router, lathe, or 3D printer) with a G-code interpreter that supports G20 and G21 — virtually all do, including GRBL, Marlin, LinuxCNC, Mach3/4, and Fanuc-style controls.
  • A text editor or CAM software that lets you write or post-process G-code (e.g., Notepad++, VS Code, Fusion 360, Carbide Create).
  • The machine's manual or controller documentation to confirm the exact syntax for your control (though G20 is nearly universal).

Step-by-Step

  1. Start every program with G20 on its own line. Place it near the top, before any movement commands. For example:
    G20
    G90
    G0 X1.0 Y0.5
    This tells the machine: “from here on, all coordinates are in inches.” If you also use absolute positioning (G90), do that after G20.
  2. Check your CAM software's post-processor settings. If you generate G-code from a CAM program, look for a “units” or “output units” option. Choose “inches” before posting. If the post-processor is set to millimeters, it will output G21 and coordinates in mm, even if you add G20 manually — the machine will read the numbers as inches, which is a disaster. Always verify the posted file.
  3. Verify the machine's current mode before running. Many controllers remember the last unit mode from the previous job. If you turn on the machine and it is still in G21 (millimeters), a file that starts with G20 will switch it correctly. But if your file does not include G20, it will run in whatever mode the machine was left in. So always include G20 — do not rely on the default.
  4. Set your work offset in inches. When you zero your machine (e.g., G54 or G92), the values you enter must be in inches. For example, if your part origin is at the lower-left corner, and you want the tool to start 0.1 inches above the surface, move the tool to that point and set the Z offset to 0.1 (not 2.54).
  5. Convert all feed rates and spindle speeds correctly. Feed rate in G-code is usually in units per minute (or per revolution, depending on the G93/G94 mode). In inch mode, F20.0 means 20 inches per minute. If you previously used mm/min, divide by 25.4 to get the equivalent inch value. Spindle speed (S) is always in RPM, so it does not need conversion.
  6. Use decimal points consistently. In inch mode, write X1.0 or X1. — not X1 (some controllers treat that as 1 micron, but most treat it as 1 inch; however, to avoid ambiguity, always include a decimal). For fractional inches, write X0.125 or X0.5 — never use fractions like X1/8.
  7. Test with a dry run or air cut. Before cutting material, run the program with the tool raised above the part (or with no tool) to verify that the tool moves the expected distances. Measure the travel with a ruler or dial indicator. For example, if you command G0 X2.0, the tool should move exactly 2 inches from the current position.
  8. If your machine uses a different unit command, check the manual. While G20 is standard, some older or proprietary controls might use G70 (Fanuc and some others) for inches. If your machine does not respond to G20, try G70 — but only after confirming in the manual. Also, some controls require G20 to be on a line by itself, not combined with other G-codes like G20 G90.

Common Mistakes

  • Forgetting to include G20 in the program. If the machine is in mm mode, your inch coordinates will be interpreted as mm — a 1-inch move becomes 1 mm, which is 25.4 times too small. Always put G20 at the top.
  • Mixing units in the same program. If you manually edit a file and change some coordinates to inches but leave others in mm, the machine will not know — it will read all numbers as the current unit. Use a consistent unit throughout.
  • Post-processing from CAM with the wrong unit setting. This is the most common cause of “my part is tiny” or “my part is huge.” Always check the generated G-code for G20 or G21 before running.
  • Assuming feed rate is in inches per minute when it is per revolution. If your controller is in G95 (feed per revolution) mode, F0.02 means 0.02 inches per revolution — not per minute. Make sure you know which mode you are in.
  • Using G20 on a machine that only supports metric. Some hobby 3D printers (e.g., certain Marlin builds) may ignore G20 or not implement it. Check the controller's documentation. If unsupported, you must convert all coordinates to mm.

Tips

  • Put G20 in your post-processor template. If you use CAM software, edit the post-processor to always output G20 at the start. This prevents accidental metric output.
  • Use a unit check in your workflow. Before running any program, open the file and search for G20 or G21. If neither appears, add G20 at the top (after verifying the machine's current mode).
  • When editing manually, write all numbers with a decimal point. For example, X1.0 instead of X1. This avoids ambiguity and is a good habit for all G-code.
  • If you switch between inch and metric jobs frequently, set a startup routine. Many controllers let you define a start-up G-code file that runs on boot. Include G20 or G21 there so you always start in a known state.
  • For lathes, remember that X is often diameter. In inch mode, an X value of 1.0 on a lathe usually means 1 inch diameter, not radius. Check your machine's programming manual — this is a common source of confusion.

Troubleshooting

If the machine moves too far or too little: First, check if the program actually contains G20. If not, the machine is likely in mm mode. Add G20 at the top. If it does contain G20, verify the machine's current mode by sending G20 manually via the console (e.g., in GRBL, send G20 and then ? to see the current mode — it will show “in” or “mm”).

If the machine ignores G20: Some controllers (e.g., certain 3D printer firmwares) do not support inch mode. Check the documentation. If unsupported, you must convert all coordinates to millimeters (multiply by 25.4). Alternatively, use a CAM post-processor that outputs metric.

If the feed rate seems wrong: Verify that you are in G94 (units per minute) mode, not G95 (units per revolution). Send G94 to set it. Also, check if your controller interprets F as inches per minute or inches per second (some do). Most use per minute, but confirm.

If the part comes out scaled incorrectly but the toolpath looks right on screen: The problem is almost certainly a unit mismatch between your CAM software and the machine. Re-post with the correct unit setting. Also, check the machine's “steps per unit” calibration — if it is set for mm but you are commanding inches, the motor will move 25.4 times too far. Recalibrate the machine for inches, or keep everything in metric.

If the machine alarms out when you send G20: Some controls require G20 to be in a specific block format. Try putting it on a line by itself, with no other G-codes. If that fails, check the manual for the exact syntax — it might be G70 instead.

Frequently Asked Questions

Do I need to use G20 if my machine already defaults to inches?

No, but it is good practice to include it anyway. Machines can be left in a different mode from a previous job, so starting with G20 ensures you are in inches regardless of the default.

Can I mix inches and millimeters in the same G-code file?

No. The unit mode applies to the entire program until changed. You can switch mid-program with G20 or G21, but doing so is risky and rarely needed. Keep one unit for the whole job.

What does G20 and G21 mean?

G20 sets the machine to inch units. G21 sets it to millimeter units. They are modal, meaning they stay in effect until another unit command is given.

How do I convert a metric G-code file to inches?

Change G21 to G20 at the top, and divide all coordinate values and feed rates by 25.4. For example, X25.4 becomes X1.0, and F254 becomes F10. Do this in a text editor or use a post-processor.

Why does my 3D printer ignore G20?

Many 3D printer firmwares (like Marlin) are designed for metric only and may not implement G20. Check the firmware documentation. If unsupported, you must use millimeters.

Does G20 affect spindle speed or tool offsets?

Spindle speed (S) is always in RPM, so it is unaffected. Tool offsets (G10 L2 or G43 H) are in the current unit mode, so if you are using inch mode, all offset values must be in inches.