New York City may be one of the most popular places to live in New York state, but that doesn't make it the best place in the state to buy a home. It's not even close — literally.

The No. 1 place to buy a home in the Empire State is Bethlehem, a town of roughly 35,000 in Albany County that's about three hours away from, and 150 miles north of, New York City, according to financial website GOBankingRates, which conducted a study to find "the best place to buy a home in every state based on the quality of the area and what sort of value you can expect based on the local housing market."

The study used data from real-estate websites Zillow and AreaVibes and focused on five metrics: livability (measuring factors such as amenities, employment and education); median home listing price; median home value; home value forecast (gauging the "return you can expect on your money"); and buyer-seller index (a score that determines "whether the current market favors people looking for housing or looking to sell" relative to other towns in the same metro).

Here's how Bethlehem ranks:

Livability score: 63

Home value forecast: 9.6 percent

Buyer-seller index: 0.27

Based on the most recent data from Zillow, here's what buyers can expect to pay:

Median listing price: $309,900

Median home value: $267,100

"Buying in Bethlehem is projected to give you one of the best one-year returns on your money at 9.6 percent," says GOBankingRates.

"And if you're younger and looking in the Empire State, you might need alternatives to the Big Apple, one of the worst cities for millennials looking to buy homes."

The median listing price for a home in New York City is $829,000 and the median home value is $681,500. Meanwhile, only 5 percent of millennials looking to buy a home this year said they plan to spend $500,000 or more, according to a survey from Clever Real Estate.