Manhattan Distance Calculator
Add absolute coordinate differences to get the grid distance between two points.
What it does
Manhattan distance measures separation along a grid. Instead of drawing a straight line between two points, you add how far apart they are in each coordinate direction. The name comes from a city whose streets form a rectangular grid, where a taxi cannot cut diagonally through buildings.
This tool accepts points with one to six coordinates. Enter each point as comma separated numbers. Both points must have the same number of coordinates, and the result uses the same arbitrary unit as the inputs.
The default example uses the points (1, 2) and (7, 5). The horizontal gap is 6 and the vertical gap is 3, so the grid distance is 9. The straight line distance is the square root of 45, about 6.7082, which is always smaller or equal.
The absolute value matters. If a coordinate decreases from one point to the other, its contribution is still positive, because a taxi driving west covers just as much ground as one driving east.
This metric appears in city planning, image comparison, regression methods that penalize absolute error, and anywhere movement is constrained to axis aligned directions.
How to use
- Type the coordinates of point p separated by commas.
- Type the same number of coordinates for point q.
- Read the Manhattan distance as the main result.
- Check the individual absolute gaps in the components row.
- Compare with the straight line distance to see how much the grid adds.
- Try points that share a coordinate to see both distances coincide.
Formula
- p_i, q_i
- The i-th coordinates of the two points.
- |p_i - q_i|
- The absolute gap along that coordinate axis.
- d(p,q)
- The sum of all absolute gaps, also called the L1 distance.
For two dimensional points the formula is the horizontal gap plus the vertical gap. With Euclidean distance the gaps are squared, added and square rooted instead. The two distances are equal only when the points share at least one coordinate. The metric satisfies nonnegativity, symmetry and the triangle inequality.
Worked example
Example: from (1, 2) to (7, 5)
The page opens with p = (1, 2) and q = (7, 5).
- Take the horizontal gap: the absolute value of 1 minus 7 is 6.
- Take the vertical gap: the absolute value of 2 minus 5 is 3.
- Add the two gaps: 6 plus 3 is 9.
- The tool reports a Manhattan distance of 9 with components 6 and 3.
- For comparison, the straight line distance is the square root of 36 plus 9, about 6.7082.
- The grid distance is larger because the taxi must follow the axes.
Reference table
| Point p | Point q | Absolute gaps | Manhattan | Euclidean |
|---|---|---|---|---|
| (1, 2) | (7, 5) | 6, 3 | 9 | 6.7082 |
| (0, 0) | (3, 4) | 3, 4 | 7 | 5 |
| (2, 2) | (2, 9) | 0, 7 | 7 | 7 |
| (1, 2, 3) | (4, 6, 8) | 3, 4, 5 | 12 | 7.0711 |
Limits
- Accepts 1 to 6 coordinates per point.
- Coordinates must be numbers between minus 1,000,000 and 1,000,000.
- Both points must have the same dimension.
- The result uses the same length unit as the inputs.
Common mistakes
- Squaring the coordinate gaps and taking a square root.
- Adding signed differences so that opposite directions cancel.
- Using different numbers of coordinates for the two points.
- Assuming the grid distance can be smaller than the straight line distance.
- Treating the result as a travel time without knowing speed or traffic.
Try it yourself
Quick checks. Answers sit tucked under each question.
Manhattan distance from (0, 0) to (3, 4)?
7. The absolute gaps are 3 and 4, while the straight line distance is 5.
Distance from (2, 2) to (2, 9)?
7. The points share an x coordinate, so the Manhattan and Euclidean distances are both 7.
Distance from (1, 2, 3) to (4, 6, 8)?
12, from gaps of 3, 4 and 5.
Questions
What is Manhattan distance?
The sum of absolute coordinate differences, as if travel is limited to a rectangular grid.
Why is it called taxicab distance?
A taxi in a gridded city must travel along streets rather than straight across blocks.
Is it the same as Euclidean distance?
No. Euclidean distance squares and square roots the gaps, and it is never larger than the Manhattan distance.
When are the two distances equal?
When the points share a coordinate, so only one axis contributes to the gap.
What does L1 mean?
It is the name of the norm formed by summing absolute values of components.
Does the unit matter?
No. Any consistent length unit works and the result uses that unit.
Sources
- Emory University Math Center, the taxicab metric
- Taylor University, ACMS proceedings, ellipses in taxicab geometry
- Wikipedia, taxicab geometry