Skip to main content
Skip to calculator
Advertisement

Last updated: August 1, 2026

Manhattan Distance Calculator

Quick Answer

This calculator finds the Manhattan distance between two 2D points by adding the absolute horizontal and vertical travel. It is useful for city-grid movement, tile maps, and algorithms that do not allow diagonal shortcuts.

The Manhattan distance between the two points is {distance}.

Helpful
Not helpful
Save as image
Share
Embed
Cite
Write feedback

Formula

Manhattan distance = |x₂ - x₁| + |y₂ - y₁|

Where:

  • x₁=X-coordinate of the first point
  • y₁=Y-coordinate of the first point
  • x₂=X-coordinate of the second point
  • y₂=Y-coordinate of the second point
  • D=Manhattan distance
Manhattan Distance CalculatorInputsEnter the known valueswith consistent units.FormulaManhattan distance = |x₂ - x₁| + |y₂ - y₁|OutputsRead the computedmanhattan distance and checks.
Visual workflow for the manhattan distance calculator.

Worked Examples

From (1, 2) to (5, 7)

Move four units horizontally and five vertically.

  1. 1Horizontal travel = |5 - 1| = 4.
  2. 2Vertical travel = |7 - 2| = 5.
  3. 3Manhattan distance = 4 + 5 = 9.
Final Answer: Distance = 9

From (-3, 4) to (5, -2)

Absolute values keep the travel distance positive.

  1. 1Horizontal travel = |5 - (-3)| = 8.
  2. 2Vertical travel = |-2 - 4| = 6.
  3. 3Distance = 8 + 6 = 14.
Final Answer: Distance = 14

From (0, 0) to (0, 9)

Pure vertical travel is still Manhattan distance.

  1. 1Horizontal travel = 0.
  2. 2Vertical travel = 9.
  3. 3Distance = 9.
Final Answer: Distance = 9

From (2.5, -1.5) to (7.25, 3)

Decimals are handled exactly the same way.

  1. 1Horizontal travel = 4.75.
  2. 2Vertical travel = 4.5.
  3. 3Distance = 9.25.
Final Answer: Distance = 9.25

Introduction

Manhattan distance measures how far two points are apart when movement is restricted to horizontal and vertical paths, like driving along a city grid. This calculator adds the absolute x-change and y-change, which makes it different from straight-line Euclidean distance.

What Manhattan distance measures

Manhattan distance assumes you cannot travel diagonally. Instead, you move along grid lines, so the total distance is the sum of horizontal and vertical travel.

  • Also called taxicab distance.

  • Matches grid-based movement rules.

  • Useful when turns are allowed but diagonal shortcuts are not.

Formula breakdown

Take the absolute horizontal change and the absolute vertical change, then add them. Absolute values matter because distance should not depend on direction.

  • |x2 - x1| gives horizontal travel.

  • |y2 - y1| gives vertical travel.

  • Adding them gives the total grid distance.

How it differs from Euclidean distance

Euclidean distance measures the straight line between two points. Manhattan distance measures the shortest axis-aligned route. The Manhattan value is always at least as large as the Euclidean one.

  • Straight-line distance uses a square root.

  • Grid distance uses absolute values and addition.

  • They match only on purely horizontal or vertical movement.

Validation and precision

All inputs must be finite numbers. Because the formula uses only subtraction, absolute value, and addition, the result is stable and easy to verify.

  • Integers and decimals are valid.

  • Negative coordinates are valid.

  • Identical points return distance 0.

Common mistakes

The main error is using the distance formula with a square root when the problem really asks for taxicab distance. Another common mistake is forgetting the absolute values.

  • Do not square the differences.

  • Do not drop the absolute value bars.

  • Make sure the problem really describes grid-based travel.

Applications

Manhattan distance is used in city-block navigation, grid-based games, image processing, and algorithms where diagonal movement is not allowed or has different cost.

  • Warehouse and aisle routing.

  • Tile-based movement in games.

  • Heuristics for grid search algorithms.

FAQs

Why is it called Manhattan distance?

The name comes from the street-grid layout of Manhattan, where travel often follows horizontal and vertical blocks instead of diagonal shortcuts.

Can the Manhattan distance be smaller than Euclidean distance?

No. The grid route is always at least as long as the straight-line route between the same two points.

What if one coordinate stays the same?

Then one travel component is zero, so the Manhattan distance is just the other absolute difference.

Do negative coordinates cause problems?

No. Absolute values convert the directional differences into positive travel distances.

When would I choose Manhattan distance over straight-line distance?

Choose it when movement is constrained to axis-aligned paths, such as roads on a grid, warehouse aisles, or grid-based algorithms.

Can I verify the answer without a calculator?

Yes. Count the horizontal units between the x-values, count the vertical units between the y-values, and add them.