Coordinate Systems#

A simple CNC machine has 3 axes of movement

  • X runs from left to right
  • Y runs from front to back
  • Z runs from top to bottom

A CNC machine can utilize multiple coordinate systems, however every single one of them uses the same orientation for its X, Y and Z axes. They only differ by their origin point.

Machine coordinate system#

Every machine has a machine coordinate system (called MCS for short here). It is sometimes called “G53”. The origin point of the MCS is also called “machine origin” or “machine zero”.

When you power on the machine, the origin of MCS is arbitrary. Grbl doesn’t know how far along each axis the spindle is initially located. Before MCS can be useful, you need to run a homing operation. This moves each axis until it encounters a limit switch. The location of the limit switch is used to set the origin for that axis.

The classic Grbl firmware always sets the origin to the top/rear/right corner of the machine. This means the valid coordinates inside the work area are always negative.

It is important to understand that the homing location and the MCS origin are not one and the same. For example it is common to use a homing location in the front/left corner of the machine. The origin will still be in the rear/right corner. How does the firmware know the distance between the two corners? It uses the maximum travel distance from the settings.

Read about changing the homing corner and the work area size: Homing corner setting, Work area setting

Note: The GrblHAL firmware has an option for placing the MCS origin at the homing location. This way you can have it in any corner you wish.

Here’s a typical scenario (showing only X and Y for clarity)

The MCS origin is lost when the machine is powered off. There are few other situations when that can happen

  • The e-stop is pressed

  • A stepper motor loses steps if overloaded

  • If a movement is aborted suddenly, either because a program is interrupted, or a limit switch is tripped, the motor may have moved slightly less or slightly more than requested due to the sudden deceleration

  • A power glitch or a software bug may cause the motion controller to reset. It will lose its origin similarly to a power cycle

You should run the homing process again if you suspect the MCS origin is incorrect.

CNC features that rely on the MCS origin#

You can absolutely use a CNC without homing. In fact many DIY machines lack limit switches, and thus can’t perform the homing operation. You will just be limited to the functionality that doesn’t depend on the accurate location of the MCS origin.

  1. Soft limits: The soft limits will detect when a move beyond the valid work area is requested. The machine will enter Alarm state and stop the current program. The soft limits assume that the valid coordinates correspond to what is physically possible. This is only true of the MCS origin matches the corner of the machine.

  2. Restoring work coordinates: The work coodinate systems (explained in the next section) are saved by the firmware so you can restore them between sessions. However they are saved as offsets from the MCS origin. If the MCS origin is not restored correctly, then the origin of the work coordinate systems will not be correct as well.

  3. G28 and G30 locations: Grbl has 2 saved positions, which you can reference using the G28 and G30 G-code commands. The locations are saved as machine coordinates, so you need the MCS origin to be correct before using them.
    Read more about them here: Saved positions

  4. Referencing physical objects in space: Maybe you have a tool sensor at specific coordinates. Or a fence that is permanently attached to the base. You need the machine to be homed before you can reliably send it to those locations.

Why am I getting weird machine coordinates right after homing?#

You may expect that after a successful homing, the machine coordinates to be 0, 0, 0. This is not unreasonable. However in practice Grbl doesn’t work that way.

Let’s first examine the Z axis because it is often easier to understand.

During homing, the spindle will move up until it hits the top limit switch. This will be the zero for the Z axis. Then the spindle will move down a preset distance to clear the limit switch. Let’s say 3 mm. As a result, the Z after homing will be -3.

For X and Y things get even more complicated.

Let’s say the machine size is 400 x 400 and the homing location is in the front left corner. The zero for X will be 400 mm to the right of the switch. Therefore the switch coordinate is going to be -400. After moving away from the switch 3 mm, the final location will be -397.

Note: What is described here is the behavior of the base Grbl firmware. More modern variants like GrblHAL have options to set the zero to match the homing location.

Work coordinate systems#

A work coordinate system (WCS for short) is always required for running a G-code program. It represents the location of the material that will be cut.

Most often you use the first coordinate system, called “G54”. Grbl has a few more - “G55”, “G56”, “G57”, “G58”, “G59”. More on them later.

All work coordinate systems use the same directions for X, Y and Z. They only differ by the location of their origin point.

The origin point of each system is saved as an offset in the machine coordinate system (MCS). It is preserved across power cycles.

The WCS determines the reference point, from where the G-code will be executed. The G-code has expectation where in relation to the material the origin point is located. If you do not set the origin point according to the expecations, the G-code will cut in the wrong place.

For example the G-code may expect the origin to be at the front/left corner on the top surface of the material. If you set the origin to be at the base of the material, the program will start carving deep into the table itself.

Vertically, common options are either the top or the bottom of the material.

Horizontally, you have many options. You can pick one of the 4 corners, or you can use the center for carving something at the center of the workpiece.

Bottom line, the work coordinate system and the G-code need to agree about the location of the origin with regard to the material.

Warning: You should not run any G-code, for which you don’t know what origin it expects for its work coordinates.

Setting the WCS origin#

Usually you set the WCS origin with the help of the sender software.

The most straight-forward way is to jog the machine to a particular location, and then use the X0, Y0 and Z0 buttons to set the origin for each axis to the current position.

A more accurate way is to use a touch probe. There are different types of probes, but the most common ones are metal plates of known thickness that you place on the work piece. Then the sender software slowly advances the tool towards the probe until it makes electrical contact.
Read more about Z probing here: Z Probing

Every sender software supports the touch probe method at least for the Z axis. Many also can use a probe for finding X and Y, but the actual procedure differs from one to another and depends on the actual geometry of the probe. You will need to read the instructions.

The WCS origin can also be set using G-code. You can set it as an exact offset from the MCS origin, or as an offset from the current location. This is helpful when writing G-code macros for complex use cases.
Take a look at Set work offset

Advanced Topics#

Spindle height vs tool height#

Mathematically speaking, each of the X, Y and Z axes of the work coordinate systems work the same way. They are just the offset between the work origin and the machine origin.

There is however one important mental distinction that is specific for the Z axis. The MCS Z coordinate represents how far the spindle is located below the top limit. But the WCS Z coordinate represents the height of the tip of the cutting tool.

When you set the WCS origin along Z you use the tip of the tool as reference. If you later replace the tool with a shorter one, the work Z offset will not automatically update to account for the difference in the length.

Imagine you have a program that needs two separate tools. The first operation uses a tool that is 2 inches long. You mount the tool, then use the Z probe to set the work Z offset. Later in the program you mount the second tool that is only 1 inch long. If you don’t do anything to compensate, the tool will cut 1 inch higher than the first one for the same spindle location.

There are 2 ways to deal with this situation.

The manual way is to run the Z probe after every tool change. For this to work, you need to have a common reference point. This can be tricky, because the top surface of the material that you used for the first probing may have been milled away. You can solve this by using the machine bed as your origin height. The G-code will need to be generated with that in mind.

A more automated way is to use a tool sensor. It is a probe that is mounted permanently to the machine at a fixed height. You touch it with the first tool and record the current machine Z coordinate. Then you touch it with the second tool and compute the difference. The longer tool will need the spindle to be higher (with a larger machine Z coordinate) than the shorter tool when it touches the probe. The difference between the two heights is added to the work offset.

This is best done with the assistance of the sender software. Some programs may have a tool sensor feature built in, while others will require some custom setup and a special G-code macro.

Professional CNC machines have automatic tool changers where all the tools needed for the program are pre-loaded in the magazine and their heights are measured in advance. They recalculate the Z offsets automatically on each tool change.

Secondary coordinate systems#

Most commonly you use the primary work coordinate system G54. The additional ones are from G55 to G59. There are some cases when they can be useful.

For example you may have permanently mounted fixtures like a fence or a vise. You can measure their position once and store them each in a dedicated coordinate system. Then you can select the coordinate system to be the current one using the sender software. The G-code will then reference the correct origin.

This however only works if the G-code program doesn’t explicitly select a coordinate system. It is not uncommon for the command G54 to be included at the start of a program. Read the manual for the CAM software you use to generate the programs. Examine the generated code to make sure it has the correct settings.

Another use for the extra coordinate systems is to simply use them as additional saved locations like G28 and G30. You temporarily switch to the other coordinate system, go to its origin, then switch back to G54.

Discussion#

Comment Form is loading comments...

  © 2026 Ivo Beltchev cnc@ibeltchev.com