Sticker Shock: Check Out the 20 Priciest ZIP Codes in the U.S.

A general view of a party hosted by actress Emily Ratajkowski at The REVOLVE House on July 4, 2015 in Sagaponack, N.Y. Matthew Eisman / Getty Images

Breaking News Emails

Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

July 7, 2015, 2:04 PM GMT / Source: CNBC.com

By Robert Frank

If you think it's expensive living in Silicon Valley or Beverly Hills, try buying a place in Sagaponack, N.Y.

The median sales price for a home in the tony Hamptons village is more than $5.1 million, making it the most expensive ZIP code in the U.S. when it comes to real estate, according to PropertyShark.

The analysis, which looked at median prices for homes that sold between January 2014 and May 2015, found the Eastern Long Island town was followed by Atherton, California, in Silicon Valley, and then Beverly Hills.

In total, California claimed four of the top five spots, and 14 of the top 20. New York claimed all the other top ZIP codes, with the exception of Miami Beach, Florida, which came in ninth.

The median sales prices for the top 20 ZIP codes were all higher than $2 million, with each of the top 10 coming in at or above $2.6 million—about 10 times the national average median home price, according to the U.S. Census Bureau.