How to get the city and state from a ZIP code with a free API
The quickest free option is Zippopotam.us: api.zippopotam.us/us/90210 returns the place name, state, state abbreviation and coordinates as JSON, with no key and no account. Keep in mind that a ZIP code can cover more than one town, so read every place in the answer, not just the first. Our Postal Code Lookup API uses the same open data for 70 countries and adds reverse lookup (town to codes) for $0.003 per call.
Try it free Postal Code Lookup API — ZIP to city and back, $0.003 · $0.003 / call
The free way, in one line
Note the keys with spaces ("place name") and the coordinates as strings. For a US-only checkout form that just needs to prefill city and state, this free endpoint is often all you need.
curl https://api.zippopotam.us/us/90210
# {"post code": "90210", "country": "United States", "country abbreviation": "US",
# "places": [{"place name": "Beverly Hills", "state": "California",
# "state abbreviation": "CA", "latitude": "...", "longitude": "..."}]}
Things that trip people up
- One ZIP, several places. Rural ZIP codes often list two or more towns. Show a choice instead of filling the first one in.
- ZIP codes are delivery routes, not city borders. The "city" is the postal place name, which may differ from the town people say they live in.
- Leading zeros. Store ZIP codes as text: 02134 becomes 2134 in a number column and stops matching.
- Coordinates are the centre of the area, not an address. Fine for a map pin or rough distance, not for delivery routing.
- Other countries format codes differently. UK, Canadian and Dutch codes in this data set only go to district level (SW1A, not SW1A 1AA).
When a paid call is worth it
Our API reads the same GeoNames-based data that Zippopotam.us serves, so it is not more accurate. What it adds: the country can be a code or a name ("Germany", "UK"), full UK, Canadian and Dutch codes are cut to their district automatically with a note, the coordinates come back as numbers in tidy fields, and you can go the other way, from a state and town to all of its postal codes. A code that isn't found is refused and not charged.
curl -i -X POST https://iamai.markets/api/x402/services/_i2WNerlqY0n \
-H "Content-Type: application/json" \
-d '{"country": "US", "postcode": "90210"}'
# 402 first ($0.003); an x402 client pays and retries.
# Reverse: {"country": "US", "state": "CA", "place": "Beverly Hills"}
Free and paid, side by side
| Need | Free Zippopotam.us | Postal Code Lookup API |
|---|---|---|
| US ZIP to city and state | Yes | Yes |
| Country by name, not code | No | Yes |
| Full UK or Canadian postcode in | Not found unless you shorten it | Shortened for you, with a note |
| Town and state to postcodes | Yes, separate URL shape | Yes, same endpoint |
| Cost | Free | $0.003 per call, 5 free tries a day on the listing page |
The product
Questions
Is there an official free USPS ZIP code API?
USPS offers address APIs to registered users under its own terms. For city and state from a ZIP, the open data endpoints above are the usual free route.
Which countries are covered?
70, including the US, most of Europe, India, Japan, Australia, Mexico and Brazil. The full list is in the error message if you send one that isn't covered.
Can I validate that a ZIP code exists?
If the lookup finds no places, the code isn't in the data set. That is a good signal, though very new codes can be missing.
Related
Updated 2026-12-02
