Manhattan distance calculator
From (0, 0) to (3, 4) the Manhattan distance is 7, not the straight-line 5, because you only move along the grid: 3 across plus 4 up. Enter two points and get the taxicab distance with both gaps. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- X1
- 0
- Y1
- 0
- X2
- 3
- Y2
- 4
- Distance
- 7
- Dx
- 3
- Dy
- 4
- Abs dx
- 3
Given two points on the Cartesian plane, the Manhattan distance — also called the taxicab distance or L1 metric — is the sum of the absolute differences of their coordinates.
How the Manhattan (taxicab / L1) formula measures grid distance
Label the first point as (x1, y1) and the second as (x2, y2). The Manhattan distance is the length of the shortest path that travels only parallel to the coordinate axes: the absolute value of x2 minus x1, plus the absolute value of y2 minus y1. Classic classroom checks include the right-triangle legs of three and four units, which produce Manhattan distance seven rather than the Euclidean five, and the unit diagonal from (0, 0) to (1, 1), which produces two instead of the square root of two.
The name comes from the grid of city blocks where a taxi cannot cut diagonally through buildings; in mathematics the same quantity is the L1 norm of the difference vector. Because the formula uses only subtraction, absolute value, and addition, it is deterministic, O(1), and free of square roots or trigonometric libraries.
Where Manhattan distance shows up in real work
Secondary-school and college discrete geometry courses constantly ask students to find the taxicab distance between two plotted points on a city grid; a trusted calculator with a strict numeric check speeds homework grading and removes spreadsheet mistakes where someone forgets absolute values or confuses L1 with the Euclidean hypotenuse. Game, graphics, and pathfinding tutorials often store sprites and nodes as pairs of tile coordinates; the Manhattan answer feeds A-star heuristics, movement budgets, and range checks without building a full navigation mesh.
Logistics and warehouse layout tools that already model aisles as axis-aligned blocks need the block-length of a two-corner segment before reporting travel cost—having a shared numeric oracle keeps field notes and office scripts aligned on the same L1 path. If you later need Euclidean straight-line distance, Chebyshev distance, or great-circle distance on a globe, treat those as separate search intents rather than overloading this taxicab landing.
What you can do with it
Homework and exam checks
Compute the taxicab L1 distance between two plotted points and reject non-numeric coordinates with a clear error.
Grid pathfinding helpers
Turn two tile coordinate pairs into a Manhattan length for A-star heuristics, movement budgets, and range checks.
FAQ
What formula does this calculator use?
The Manhattan (taxicab / L1) formula: distance = |x2 − x1| + |y2 − y1|. The response includes method: "manhattan".
What happens if a coordinate is not a number?
Missing fields, empty strings, non-numeric text, NaN, and Infinity are all rejected.
How is this different from Euclidean distance?
Euclidean distance is the straight-line hypotenuse √((x2−x1)²+(y2−y1)²). Manhattan distance is the sum of absolute axis steps and is always greater than or equal to the Euclidean length for the same points.
What does it cost?
The browser tool is free and runs locally.
Where is Manhattan distance used?
On any grid where you cannot cut diagonally: city blocks, game tiles and warehouse aisles. It feeds A-star pathfinding estimates, movement budgets and range checks, and it is a classic exercise in discrete geometry courses.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/geom/manhattan-distance \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x1":0,"y1":0,"x2":3,"y2":4}'const res = await fetch("https://api.kit.forhosting.com/geom/manhattan-distance", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x1": 0,
"y1": 0,
"x2": 3,
"y2": 4
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/geom/manhattan-distance",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x1": 0,
"y1": 0,
"x2": 3,
"y2": 4
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/geom/manhattan-distance", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x1":0,"y1":0,"x2":3,"y2":4}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x1":0,"y1":0,"x2":3,"y2":4}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/geom/manhattan-distance", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"x1": 0,
"y1": 0,
"x2": 3,
"y2": 4
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "geom.manhattan_distance",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
This calculator accepts x1, y1, x2, and y2 as finite numbers, validates every coordinate, and returns the non-negative distance together with the normalized points, the signed deltas dx and dy, the absolute components abs_dx and abs_dy, and a method tag of manhattan. Missing fields, empty strings, non-numeric text, NaN, and Infinity are rejected with a clear invalid_input error instead of a silent NaN that looks like a successful solve. No network calls, no random sampling, and no floating-point surprises beyond ordinary IEEE-754 arithmetic on the four numbers you provide.
How the Manhattan (taxicab / L1) formula measures grid distance
That expression is always non-negative, is zero exactly when the two points coincide, and is symmetric under swapping the two endpoints. Large coordinates can still overflow IEEE-754 double range when differences grow extreme; when the sum is non-finite the request fails with a clear overflow message instead of returning Infinity in JSON. That closed path matches how discrete geometry, robotics on grids, and computational geometry primers present the taxicab metric, and it keeps automated graders and pipelines aligned with hand computation without unit conversion or map projections mixed into the same call.
What you send and what you get back
Provide four required finite numbers: x1 and y1 for the first point, x2 and y2 for the second. Example checks: zero, zero, three, four yields distance seven; zero, zero, one, one yields two; a non-numeric y2 fails naming that field. Wire the free browser tool for quick sanity checks, then call the identical contract from scripts when you need bulk evaluation of Manhattan distances without reimplementing the numeric gate in every language. Short aliases ax, ay, bx, by and x_a through y_b are accepted so form labels can stay compact without diverging handlers. Missing fields, empty strings, non-numeric text, NaN, and Infinity are rejected with invalid_input and are not charged. After parsing, the service computes dx equals x2 minus x1 and dy equals y2 minus y1, takes abs_dx and abs_dy, sums them into distance, and checks that the distance is a finite number. On success the JSON response returns distance rounded for stable serialization, echoes the four normalized coordinates, includes dx, dy, abs_dx, and abs_dy, and sets method to the string manhattan so logs and teaching UIs can document the metric. API pricing is the published base of $0.002 per successful item.
Where Manhattan distance shows up in real work
Because this capability is a pure parse engine, failed validation does not consume balance and successful runs stay at $0.002 per item.
Integration use cases
City-block logistics segments
From two axis-aligned endpoints, recover block-path length before reporting travel cost on a street grid.
Technical questions
Does point order matter?
No. Distance is symmetric: swapping the two points yields the same non-negative length (dx and dy flip sign; abs_dx and abs_dy stay the same).