Data Science & ML
Basic

Manhattan Distance

Distance measured along axes at right angles (taxicab geometry).

Formula

d=∑i=1n∣ai−bi∣d = \sum_{i=1}^{n}|a_i - b_i|

Variables

a_i,b_iCoordinates
nDimensions

Example

Between (0,0) and (3,4): d = 7

How it works

Manhattan distance adds up the absolute differences between matching coordinates, so it measures how far apart two points are if you can only move parallel to the axes. It comes from the idea of traveling on a grid of streets, where diagonal shortcuts are not allowed, so you must count each horizontal and vertical step separately. Taking absolute values ensures each coordinate contributes a nonnegative amount, no matter which point is larger in that dimension.

When to use it

Use Manhattan distance when movement is constrained to grid-like paths, such as city blocks, robotics on a rectangular map, or feature-space comparisons in data science. It is also useful when you want a distance measure that is less sensitive to large differences in one diagonal direction than straight-line distance.

Worked example, step by step

Find the Manhattan distance between points (2, -1) and (7, 3). Step 1: Write the coordinates by dimension: a = (2, -1), b = (7, 3) Step 2: Compute each absolute difference: |2 - 7| = 5 and |-1 - 3| = 4 Step 3: Add the results: d = 5 + 4 Step 4: Final answer: d = 9

Common mistakes to avoid

  • using ordinary straight-line distance instead of adding coordinate-by-coordinate absolute differences
  • forgetting the absolute value and letting negative differences cancel out
  • mixing up the coordinates or omitting a dimension when summing

Did You Know?

Named after the grid layout of Manhattan streets.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026