Manhattan Distance Calculator

Manhattan distance7
Euclidean distance5.00
Horizontal leg |dx|3
Vertical leg |dy|4
How this was calculated
  1. On a grid you can only travel along the streets, so the Manhattan distance adds the two legs of the trip separately: |4 - 1| = 3 across and |6 - 2| = 4 up.
  2. Manhattan distance = 3 + 4 = 7 — any shortest route on the grid has exactly this length, whichever order you walk the legs in.
  3. The straight-line Euclidean distance is 5.00, always the shorter of the two: the Manhattan distance exceeds it whenever the trip is not along a single axis.
  4. The measure is named for the street grid of Manhattan and shows up in city-block routing, warehouse picking, chip layout and the L1 norm in statistics.

This Manhattan distance calculator measures the distance between two points by counting travel along a grid rather than cutting across it. The Manhattan distance between two points is |x2 − x1| + |y2 − y1| — the length of the shortest route that stays on a grid. Enter your coordinates and the calculator gives you that total. From (1, 2) to (4, 6), for example, the Manhattan distance is 3 + 4 = 7, while the straight-line Euclidean distance is 5.00. In three dimensions a third leg is added: from (0, 0, 0) to (1, 2, 2) the Manhattan distance is 5 against a Euclidean 3.00.

The method behind the calculator is the accepted standard for grid-based distance because it matches how movement actually works when you cannot travel diagonally, and it is the L1 norm used in statistics and machine learning. The measure is named for the street grid of Manhattan. A useful check on any result: the Manhattan distance always equals or exceeds the Euclidean distance, and the two agree only when the trip runs along a single axis. This page shows the formula, step-by-step workings, worked examples and sources so you can verify every number yourself.

Worked examples

A 3-4-5 style city trip

Primary result: 7. Full step-by-step working is shown with the result. (2D (x, y) · 1 · 2 · 0 · 4 · 6 · 0)

Manhattan distance7
Euclidean distance5.00
Horizontal leg |dx|3
Vertical leg |dy|4

A three-dimensional grid move

Primary result: 5. Try it with your own numbers in the calculator above. (3D (x, y, z) · 0 · 0 · 0 · 1 · 2 · 2)

Manhattan distance5
Euclidean distance3.00
Horizontal leg |dx|1
Vertical leg |dy|2
Depth leg |dz|2

Crossing the origin

Primary result: 11. Every intermediate value is printed in the worked steps. (2D (x, y) · -3 · 5 · 0 · 2 · -1 · 0)

Manhattan distance11
Euclidean distance7.81
Horizontal leg |dx|5
Vertical leg |dy|6

What Manhattan distance is

Picture yourself standing on a corner in Midtown Manhattan. To reach a point several blocks north and several blocks east, you cannot cut diagonally across the buildings — you walk up one avenue, then over on a cross street, or the other way around. The Manhattan distance between two points measures exactly that: the length of the shortest route that stays on a grid. Its formula is |x2 − x1| + |y2 − y1|, the horizontal gap plus the vertical gap, with each gap counted as a positive number no matter which direction you travel. A manhattan distance calculator simply applies this formula to the coordinates you enter, adding the two legs together for you.

Because the grid forbids diagonal shortcuts, the order of the legs does not matter. Going east first and then north covers the same total ground as going north first and then east. Every shortest route between the same two corners has the same length, so the answer is a single number rather than a range. Take two points, (1, 2) and (4, 6). The horizontal difference is 4 − 1 = 3 and the vertical difference is 6 − 2 = 4, giving a Manhattan distance of 3 + 4 = 7. The straight-line, or Euclidean, distance between those same points is 5.00 — shorter, because a straight line is allowed to cut across the blocks that the grid route must go around.

The same idea extends to three dimensions, where a third leg is added for depth. From the origin (0, 0, 0) to (1, 2, 2), the three gaps are 1, 2 and 2, so the Manhattan distance is 5, while the Euclidean distance is 3.00. The gap between the two measures grows as a trip spreads across more axes: the grid route must travel along each axis separately, while the straight line can combine them.

The measure takes its name from the street grid of Manhattan, and it also appears under the name L1 norm in statistics and machine learning, where the sum of absolute differences is a common way to compare values. One relationship is worth remembering: the Manhattan distance always equals or exceeds the Euclidean distance. The two agree only when the trip runs along a single axis — when one of the coordinate differences is zero and the path is a straight line along the grid. As soon as movement is required on two or more axes, the Manhattan figure pulls ahead.

Manhattan distance = |x2 − x1| + |y2 − y1|. It is never less than the Euclidean distance, and the two match only on a single-axis trip.

How to calculate it

To calculate Manhattan distance, you work one axis at a time. Take the difference between the x-coordinates and make it positive, then do the same for the y-coordinates, and add the two results together. The formula is |x2 − x1| + |y2 − y1|. That sum is the length of the shortest route that stays on a grid — no diagonal shortcuts allowed. A manhattan distance calculator simply applies this rule to whatever coordinates you enter, but the arithmetic is easy enough to follow by hand.

Walk through a 2D example. From (1, 2) to (4, 6), the x-difference is 4 − 1 = 3 and the y-difference is 6 − 2 = 4. Add them: 3 + 4 = 7. The straight-line Euclidean distance between the same two points is 5.00, so the grid route is longer — as it always is when a trip changes both coordinates. If you picture a city block layout, you would walk 3 blocks east and 4 blocks north, and the order does not matter: 4 north then 3 east covers the same 7 blocks.

A trip that crosses the origin works the same way, because the absolute value strips out the sign. Suppose one point sits at negative coordinates on either axis. The subtraction may give a negative number, but its absolute value is the distance along that axis, so the legs still add up to a positive total. The origin itself is just the point (0, 0); a route from there to (3, 4) gives 3 + 4 = 7, and a route from (−2, 1) to (1, 5) gives |1 − (−2)| + |5 − 1| = 3 + 4 = 7. Crossing zero adds no special step — only the size of each difference counts.

In three dimensions a third leg is added, so the formula becomes |x2 − x1| + |y2 − y1| + |z2 − z1|. From (0, 0, 0) to (1, 2, 2), the legs are 1, 2 and 2, which total 5. The Euclidean distance for the same pair of points is 3.00, noticeably shorter because the straight line cuts through the space rather than following the axes. This is the same L1 norm used in statistics and machine learning, and the name comes from the street grid of Manhattan, where travel follows the avenues and cross streets.

One relationship is worth remembering as a check on your work: the Manhattan distance always equals or exceeds the Euclidean distance. The two agree only when the trip runs along a single axis, so every other coordinate difference is zero and the grid route is already a straight line. If your Manhattan result ever comes out smaller than the straight-line distance, an absolute value or a sign has gone wrong somewhere.

  • 2D: from (1, 2) to (4, 6) → |4 − 1| + |6 − 2| = 3 + 4 = 7 (Euclidean: 5.00)
  • 3D: from (0, 0, 0) to (1, 2, 2) → 1 + 2 + 2 = 5 (Euclidean: 3.00)
  • Crossing the origin changes nothing: absolute values turn negative differences into positive legs
Manhattan distance always equals or exceeds Euclidean distance. They match only when the trip stays on one axis.

Manhattan vs Euclidean distance

The Manhattan distance between two points is |x2 − x1| + |y2 − y1| — the length of the shortest route that stays on a grid. The Euclidean distance is the straight line between the same two points. Both answer the question "how far apart are these points?", but they answer it for different worlds. Choosing the wrong one gives a number that is arithmetically correct and practically misleading, which is why a manhattan distance calculator is most useful when you already know which kind of distance your problem involves.

A worked pair of points makes the gap concrete. From (1, 2) to (4, 6) the Manhattan distance is 3 + 4 = 7, while the straight-line Euclidean distance is 5.00. The grid route has to cover the horizontal change and the vertical change separately, so it adds them; the straight line cuts the corner. Adding a dimension does not change the logic, it just adds a leg. From (0, 0, 0) to (1, 2, 2) the Manhattan distance is 5 against a Euclidean 3.00. The same pattern holds in any number of dimensions: sum the absolute differences along each axis for Manhattan, or take the square root of the sum of squared differences for Euclidean.

The L1/L2 norm framing is the general form of this comparison. The measure is named for the street grid of Manhattan and is the L1 norm used in statistics and machine learning; the Euclidean distance is the L2 norm. L1 adds the sizes of the steps along each axis, while L2 squares them, adds, and takes the square root. That difference in how each norm treats a large single step explains their behavior: L1 does not let one big axis difference dominate, while L2 penalizes it more heavily.

Use Manhattan when movement is genuinely constrained to a grid: city routing where streets run in two directions, warehouse and robot path planning, board games and other grid worlds, and many similarity or distance measures in statistics and machine learning. Use Euclidean when the straight line is the honest measure — physical separation in open space, geometry problems, and any setting where a diagonal shortcut is actually available. A useful sanity check comes from the relationship between the two: the Manhattan distance always equals or exceeds the Euclidean distance, and they agree only when the trip runs along a single axis. If a grid route and a straight line give you the same number, the points share a row or a column, and there is no corner to cut.

Rule of thumb: if the traveler must follow streets or grid steps, use Manhattan; if it can fly straight, use Euclidean. The Manhattan value is never smaller than the Euclidean value for the same two points.

Where it is used

The Manhattan distance between two points is |x2 − x1| + |y2 − y1| — the length of the shortest route that stays on a grid. That simple sum of horizontal and vertical gaps is why a manhattan distance calculator turns up in fields where movement is constrained to a grid or where a straight diagonal is not an option. The measure is named for the street grid of Manhattan and is the L1 norm used in statistics and machine learning.

In warehouse picking, travel follows aisles rather than open floor. A picker moving from one storage location to another must go along one aisle, then across, so the grid-based count matches the real walking distance far better than a straight-line figure. The same logic applies to chip layout, where wires run along orthogonal tracks and the cost of a connection is measured in horizontal plus vertical segments. Board games with orthogonal movement — pieces that step up, down, left, or right but never diagonally — use the same count to judge how many moves separate two squares.

Robust statistics is another home for the measure. Median-based methods rely on the L1 norm, and because the Manhattan distance weights each axis separately, a single large deviation in one coordinate does not dominate the result the way it can under a squared, Euclidean-style measure. That property is valuable when data contain outliers or when errors along each axis should be counted at face value.

A quick comparison shows how the two distances differ. From (1, 2) to (4, 6) the Manhattan distance is 3 + 4 = 7, while the straight-line Euclidean distance is 5.00. In three dimensions a third leg is added: from (0, 0, 0) to (1, 2, 2) the Manhattan distance is 5 against a Euclidean 3.00. The Manhattan distance always equals or exceeds the Euclidean distance; they agree only when the trip runs along a single axis.

That relationship is worth keeping in mind when you interpret a result. A larger Manhattan figure is not an error — it reflects the extra travel forced by staying on the grid. When the route is a single straight line along one axis, the two measures coincide, and the gap between them grows as the path becomes more diagonal.

  • Warehouse picking: travel follows aisles, so horizontal plus vertical steps match the real route.
  • Chip layout: wires run along orthogonal tracks, making the L1 count the natural cost measure.
  • Board games: pieces that move only up, down, left, or right are counted in grid steps.
  • Robust statistics: median-based methods use the L1 norm, which weights each axis separately.
Manhattan distance always equals or exceeds Euclidean distance; the two agree only when the trip runs along a single axis.

FAQs

What is Manhattan distance?

Manhattan distance is the sum of the absolute differences of the coordinates. It represents the shortest path between two points when movement is restricted to a grid, so you can only travel along horizontal and vertical lines rather than cutting diagonally across open space.

How do you calculate Manhattan distance in 2D?

In two dimensions, add the absolute difference in x to the absolute difference in y: |x2 − x1| + |y2 − y1|. For example, from (1, 2) to (4, 6) the x difference is 3 and the y difference is 4, so the Manhattan distance is 3 + 4 = 7.

Why is it called Manhattan distance?

The name comes from the street grid of Manhattan, New York. In that layout a taxi travels along avenues and streets rather than in a straight line, so the distance it covers follows the grid instead of the direct diagonal path between two points.

Is Manhattan distance always longer than Euclidean?

It is never shorter than Euclidean distance. In the worked example the Manhattan distance is 7 versus 5.00 for Euclidean. The two measures agree only for trips along one axis, where the path has no diagonal component and both give the same result.

How does it work in 3D?

In three dimensions you add the third leg to the sum: |x2 − x1| + |y2 − y1| + |z2 − z1|. For example, from (0, 0, 0) to (1, 2, 2) the differences are 1, 2 and 2, so the Manhattan distance is 1 + 2 + 2 = 5.

Where is Manhattan distance used in computing?

It appears as the L1 norm in statistics and machine learning, where it measures the size of a vector. It is also used in grid pathfinding, where movement is limited to a grid, and in error measures that resist outliers, since it does not square the individual differences.

Sources

Related calculators

Distance Formula Calculator
Distance between two points on the coordinate plane, with the midpoint and both axis changes — Pythagoras, done for you.
Endpoint Calculator
Find the missing endpoint of a line segment when you know the other endpoint and the midpoint.
Slope Calculator
Slope, angle, distance and midpoint between two points, plus the full equation of the line through them — the whole coordinate-geometry answer in one go.
Chebyshev Distance Calculator
Chebyshev (chessboard) distance between two points: the larger of the horizontal and vertical gaps - the number of moves a chess king needs.