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:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | From ZIP | Lat 1 | Lon 1 | Lat 2 | Lon 2 | Miles |
| 2 | 10001 → 90210 | 40.7484 | -73.9967 | 34.0901 | -118.4065 | formula |
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
- A few hundred rows, one-off analysis: Method 1, no API key needed.
- Recurring reports or many countries: Method 2 keeps the data current and handles non-US postal codes.
- Just need a quick answer: the ZIP code distance calculator.