Tutorial · Excel & Sheets

Distance between ZIP codes in Excel

Two ways to get ZIP code distances into a spreadsheet: a Haversine formula on coordinates, or a live API call from the cell.

Updated October 1, 2026 · 2 min read

Method 1: coordinates + Haversine formula

Step 1: get the coordinates. Paste your ZIP codes into the free bulk ZIP code lookup and download the CSV with latitude and longitude, then paste it into your sheet:

ABCDEF
1From ZIPLat 1Lon 1Lat 2Lon 2Miles
210001 → 9021040.7484-73.996734.0901-118.4065formula

Step 2: the formula in F2:

=3959*ACOS(COS(RADIANS(90-B2))*COS(RADIANS(90-D2))+SIN(RADIANS(90-B2))*SIN(RADIANS(90-D2))*COS(RADIANS(C2-E2)))

This is the spherical law of cosines, which gives the same result as the Haversine formula for these distances. Replace 3959 with 6371 for kilometres. For 10001 → 90210 the result is about 2,450 miles.

Method 2: fetch distances from the API

The zipcodestack API answers in JSON, which spreadsheet formulas cannot parse directly, so use Power Query in Excel or Apps Script in Google Sheets.

Excel (Power Query): Data → Get Data → From Web, paste

https://api.zipcodestack.com/v1/distance?apikey=YOUR-API-KEY&country=us&unit=miles&code=10001&compare=90210,60601

and expand the results record into rows. Refresh the query whenever your list changes.

Google Sheets (Apps Script): Extensions → Apps Script, paste this function and save:

function ZIPDISTANCE(from, to, country) {
  const url = "https://api.zipcodestack.com/v1/distance?apikey=YOUR-API-KEY&unit=miles"
    + "&code=" + from + "&compare=" + to + "&country=" + (country || "us");
  const data = JSON.parse(UrlFetchApp.fetch(url).getContentText());
  return data.results[to];
}

Then use =ZIPDISTANCE(A2, B2) in any cell. Each call uses one request of your quota (300 free per month).

Which method to use

Frequently asked questions

Can Excel calculate the distance between two ZIP codes on its own?

No. Excel has no ZIP code data. You need the latitude and longitude of each ZIP code first, then a Haversine formula calculates the distance.

What is the Excel formula for distance between coordinates?

=3959*ACOS(COS(RADIANS(90-B2))*COS(RADIANS(90-D2))+SIN(RADIANS(90-B2))*SIN(RADIANS(90-D2))*COS(RADIANS(C2-E2))) returns miles, with lat1/lon1 in B2/C2 and lat2/lon2 in D2/E2. Use 6371 instead of 3959 for kilometres.

Postal code API

Get this data in your app

zipcodestack looks up, validates and searches postal codes in 149 countries: city, state, coordinates, distances and radius search, as JSON.

/v1/search documentation International postal code API All documentation

300 free requests every month. No credit card required.

GET https://api.zipcodestack.com/v1/search?codes=10001&country=us

{
  "results": {
    "10001": [{
      "postal_code": "10001",
      "country_code": "US",
      "latitude": 40.7484,
      "longitude": -73.9967,
      "city": "New York",
      "state": "New York",
      "state_code": "NY",
      "province": "New York"
    }]
  }
}

Keep reading

Start using our ZIP Code API for free today!

Get 300 requests / month for free