Distance Matrix Calculator (Pairwise Distance Table)
Generate a comprehensive pairwise distance table between multiple geographic points. Calculates all N × (N - 1) / 2 unique pairings with instant mileage, metric conversions, and one-click CSV spreadsheet export.
Ready to Build Distance Matrix
Add up to 10 cities, addresses, or landmarks to generate a full pairwise distance matrix table with CSV export.
| Origin \ Destination | New York | Chicago | Houston | Los Angeles |
|---|---|---|---|---|
| New York | — | 712.8 mi | 1,418.9 mi | 2,451 mi |
| Chicago | 712.8 mi | — | 940.7 mi | 1,745.8 mi |
| Houston | 1,418.9 mi | 940.7 mi | — | 1,373.4 mi |
| Los Angeles | 2,451 mi | 1,745.8 mi | 1,373.4 mi | — |
How to use the distance matrix calculator
- 1Enter your locations
Add two or more places by address or coordinates.
- 2Compute every pair
The straight-line distance between every pair of locations is calculated in your browser.
- 3Download the table
Read the matrix in miles or km and export it as CSV for Excel or Google Sheets.
What Is a Distance Matrix?
A distance matrix (also known as an origin-destination or OD cost matrix) is a two-dimensional mathematical array containing the pairwise distances between a set of geographic points. Given an input set of N locations, a complete distance matrix consists of N × N elements representing every possible transit combination.
In geographic information science (GIS) and spatial operations research, distance matrices form the foundational dataset required for solving complex optimization challenges, such as vehicle routing problems (VRP), facility location selection, territory rebalancing, and supply-chain logistics.
Why Straight-Line Matrices Are Symmetric and Road Matrices Are Not
A crucial distinction between mathematical distance calculations and real-world road networks lies in the property of symmetry:
- Symmetric Geodesic Matrices: In pure geodesy across an ellipsoid like WGS84, the distance from Point A to Point B is identical to the distance from Point B to Point A:
d(A, B) = d(B, A). Consequently, the main diagonal is always zero, and the upper-right triangle mirrors the lower-left triangle. Only N(N - 1) / 2 calculations are required. - Asymmetric Road Networks: Real-world driving matrices are frequently asymmetric:
d(A, B) ≠ d(B, A). One-way streets, divided highways requiring u-turns, left-turn restrictions, ramp configurations, and prevailing directional traffic congestion mean driving from A to B often differs in both mileage and duration from driving from B to A.
Who Uses a Distance Matrix? Common Uses
Beyond simple mileage measurement, distance matrices allow analysts to perform sophisticated spatial operations:
Facility Location
Identifies the optimal warehouse or distribution center that minimizes cumulative transport mileage to all retail satellite locations.
Territory Balancing
Partitions customer accounts equally among sales or service representatives by clustering proximities derived from the matrix.
Dispatch Optimization
Rapidly filters candidate emergency vehicles, service technicians, or delivery drivers to allocate the nearest active unit to an incident.
How Many Distances Are Calculated?
Calculating the number of unique distances required to build an un-directional N-point matrix:
Pairs = \frac{N(N - 1)}{2}- Total off-diagonal matrix entries = N² - N = 36 - 6 = 30
- Due to symmetry d(A, B) = d(B, A), divide by 2: 30 / 2 = 15 unique pairs
- Formulation: Pairs = (6 × 5) / 2 = 15 calculations
- At N = 100, unique pairs = (100 × 99) / 2 = 4,950 geodesics
- At N = 1,000, unique pairs = (1,000 × 999) / 2 = 499,500 geodesics
Our browser-based engine evaluates these calculations in parallel using WebAssembly, eliminating the need for expensive API calls to commercial mapping vendors.
Example: Distance Matrix for 5 U.S. Cities
Reference table illustrating a symmetrical pairwise matrix across America's five largest metropolitan regions (in statute miles):
Sample 5x5 Intercity Distance Matrix
Distances computed using WGS84 geodesic Great-Circle formulas. All values in statute miles.
| Origin / Destination | New York | Los Angeles | Chicago | Houston | Phoenix |
|---|---|---|---|---|---|
| New York (JFK) | 0 mi | 2,446 mi | 711 mi | 1,428 mi | 2,141 mi |
| Los Angeles (LAX) | 2,446 mi | 0 mi | 1,745 mi | 1,379 mi | 372 mi |
| Chicago (ORD) | 711 mi | 1,745 mi | 0 mi | 940 mi | 1,440 mi |
| Houston (IAH) | 1,428 mi | 1,379 mi | 940 mi | 0 mi | 1,010 mi |
| Phoenix (PHX) | 2,141 mi | 372 mi | 1,440 mi | 1,010 mi | 0 mi |
Distance Matrix Size Limits and Performance
Keep these architectural and technical considerations in mind when generating large matrices:
- O(N²) Scalability: Doubling your waypoint count quadruples the total matrix cells. While 10 points requires 45 evaluations, 100 points demands 4,950 calculations.
- As-the-Crow-Flies vs. Driving Matrix: This tool provides straight-line distances. For real-world trucking itineraries, road-routing factors must be incorporated.
- Zero Distance Diagonal: Any origin compared against itself yields zero distance. If non-zero values appear, check for duplicate coordinate entries with slightly different decimal precision.
- Export Formats: Exported CSV data can be directly ingested by Python (NumPy/Pandas), R, Excel, or QGIS for network graph analysis.
Related Network Analysis Tools
Plot multiple destinations sequentially with the Multi-Stop Route Calculator or visualize travel contours using our Drive Time Map.
Quick facts about the distance matrix calculator
| Fact | Value | Notes |
|---|---|---|
| Matrix Dimensions | Up to 10 × 10 Grid | Computes 45 unique pairwise distance vectors |
| Export Format | RFC 4180 CSV Export | Ready for Excel, Google Sheets, or GIS software |
| Math Engine | WGS84 Great-Circle Haversine | Zero server roundtrips; 100% in-browser |
Edge cases and exceptions
Symmetric Distance Property
Because geodesics on the reference sphere are bidirectional, Distance(A, B) equals Distance(B, A). The diagonal of the matrix is always 0.0.
The distance matrix calculator: worked examples
Regional Distribution Logistics
Scenario: Evaluating logistics distances between Dallas, Houston, Austin, and San Antonio.
Outcome: Produces a 4x4 matrix revealing Houston-to-Dallas as the longest corridor (225 miles) and Austin-to-San Antonio as the shortest (74 miles).
Frequently asked questions about the distance matrix calculator
What is a distance matrix used for?
Distance matrices are fundamental in logistics, supply chain routing, traveling salesperson algorithms, sales territory planning, and fleet dispatch.
Can I download the matrix to Excel?
Yes. Click "Export CSV" to immediately download a standard spreadsheet table with row and column headers.
How many pairs does a distance matrix contain?
For N points there are N × (N − 1) / 2 unique pairs. Ten points give 45 pairs; fifty give 1,225.
Is the matrix symmetric?
Yes. Straight-line distance from A to B equals B to A. Road distances can differ because of one-way streets and turn restrictions.
Can I import a list of addresses?
You can enter or paste locations. To plot a list from a spreadsheet, use the CSV to map tool with latitude and longitude columns.
What units does the matrix show?
Miles and kilometers, and you can download the result as CSV for Excel or Google Sheets.
How do I find the central point of my locations?
Use the geographic center finder to calculate the spherical mean of all points.
Is straight-line distance good enough for fleet planning?
It is a fast first pass for clustering and sorting. Final routes need a road network engine.
How do I find the nearest location to each point?
Read the smallest value in each row of the matrix. Sorting the CSV by distance makes this easy.
How accurate are the distances in the matrix?
Each cell is a WGS84 geodesic distance between the two points, accurate to meters. Real road distance will be longer, usually by 15 to 30 percent in the US.
Keep exploring
What to do with this result
- Multi-Stop Route Distance CalculatorUse this to total a multi-stop route.
- CSV to Map VisualizerUse this to plot a CSV file on a map.
- Distance Between Cities (Flight Distance)Use this to get the flight distance between cities.
- Find Cities in a RadiusUse this to list cities within a radius.
- Geographic Center Finder (Centroid & Center of Mass)Use this to find a geographic center.