GEODETIC DATUM: WGS84 · CLIENT-SIDE PRECISION · NO SIGN-UP
Open Map Lab

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.

By ·Updated Runs in your browser
Tool Ready
Ready to Locate· Awaiting input

Ready to Build Distance Matrix

Add up to 10 cities, addresses, or landmarks to generate a full pairwise distance matrix table with CSV export.

New York
Chicago
Houston
Los Angeles
Origin \ DestinationNew YorkChicagoHoustonLos Angeles
New York—712.8 mi1,418.9 mi2,451 mi
Chicago712.8 mi—940.7 mi1,745.8 mi
Houston1,418.9 mi940.7 mi—1,373.4 mi
Los Angeles2,451 mi1,745.8 mi1,373.4 mi—
Total Matrix Pairs
6
Combinations
Closest Pair
712.8 mi
New York ↔ Chicago
Furthest Pair
2451 mi
New York ↔ Los Angeles
Geodetic Model
WGS84
Sub-mm Karney Solver

How to use the distance matrix calculator

  1. 1Enter your locations

    Add two or more places by address or coordinates.

  2. 2Compute every pair

    The straight-line distance between every pair of locations is calculated in your browser.

  3. 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:

GOVERNING MATHEMATICAL EQUATIONPairs = \frac{N(N - 1)}{2}
VARIABLE DEFINITIONS & CONSTANTS
N:Number of input nodes / waypoints (integer)
Pairs:Unique geodesic calculations required
Total Cells:Full matrix grid size (N × N)
WORKED BENCHMARK: COMBINATORIAL MATRIX SIZE FOR 6 REGIONAL DISTRIBUTION HUBS
Number of Locations (N) = 6Full Grid Dimensions = 6 × 6 = 36 cellsZero Diagonal Count = 6 cells (self-distance)
  1. Total off-diagonal matrix entries = N² - N = 36 - 6 = 30
  2. Due to symmetry d(A, B) = d(B, A), divide by 2: 30 / 2 = 15 unique pairs
  3. Formulation: Pairs = (6 × 5) / 2 = 15 calculations
  4. At N = 100, unique pairs = (100 × 99) / 2 = 4,950 geodesics
  5. At N = 1,000, unique pairs = (1,000 × 999) / 2 = 499,500 geodesics
Computed Result:15 Unique Vector Pairs Computed Instantly

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 / DestinationNew YorkLos AngelesChicagoHoustonPhoenix
New York (JFK)0 mi2,446 mi711 mi1,428 mi2,141 mi
Los Angeles (LAX)2,446 mi0 mi1,745 mi1,379 mi372 mi
Chicago (ORD)711 mi1,745 mi0 mi940 mi1,440 mi
Houston (IAH)1,428 mi1,379 mi940 mi0 mi1,010 mi
Phoenix (PHX)2,141 mi372 mi1,440 mi1,010 mi0 mi

Distance Matrix Size Limits and Performance

Keep these architectural and technical considerations in mind when generating large matrices:

Matrix Scale & Usage Considerations
  • 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

FactValueNotes
Matrix DimensionsUp to 10 × 10 GridComputes 45 unique pairwise distance vectors
Export FormatRFC 4180 CSV ExportReady for Excel, Google Sheets, or GIS software
Math EngineWGS84 Great-Circle HaversineZero server roundtrips; 100% in-browser
PRECISION & EXCEPTIONS

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.

FIELD APPLICATIONS

The distance matrix calculator: worked examples

1

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

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

Data & Cartographic Authority: WGS84 ellipsoid geodesics (GeographicLib/Karney) · OpenStreetMap contributors (ODbL) via Photon & Nominatim geocoding

Written and maintained by . Content updated October 30, 2026; data last verified September 19, 2026. See our editorial policy, methodology, or report an error.