(AP) – Whether you can afford a home depends — a lot — on the city you want to call home. A modest income can go a long way in Cumberland, Maryland, the metropolitan area with the nation’s most affordable houses. In contrast, the least affordable homes are in the San Jose, California, metropolitan area — the center of Silicon Valley.

In Cumberland, a median-priced house costs less than two years’ median household income. By contrast, the typical home in San Jose costs about 10 years of household income.

NerdWallet calculated affordability for 173 metropolitan areas by comparing the median annual household income and the monthly principal-and-interest payment for a median-priced single-family home. “Median” means half of the values or incomes are higher and half are lower. Those comparisons revealed the five most- and least-affordable markets for buying a home.

The lists were compiled using data from the National Association of Realtors, the Census Bureau and NerdWallet surveys.

MOST AFFORDABLE METRO AREAS

1. CUMBERLAND, MARYLAND-WEST VIRGINIA

Median home price: $84,600

Median household income: $45,808

Principal and interest payment: $326 (equals 8.5 percent of monthly income)

Despite their affordability, houses in the Cumberland metro area don’t sell quickly. In February, single-family home listings had been on the market for a median of 146 days, according to Realtor.com. The national median was 84 days.

2. YOUNGSTOWN-WARREN-BOARDMAN, OHIO-PENNSYLVANIA

Median home price: $90,200

Median household income: $44,981

Principal and interest payment: $348 (9.3 percent of monthly income)

Roughly midway between Pittsburgh and Cleveland, Youngstown was once a steel manufacturing powerhouse. Since then, it has embraced its diminished population and opted not to prioritize growth.

3. PEORIA, ILLINOIS

Median home price: $120,400

Median household income: $57,090

Principal and interest payment: $464 (9.8 percent of monthly income)

Among the five most-affordable metro areas, Peoria has the highest house prices. But it also has the highest median household income among the five, boosting affordability.

4. BINGHAMTON, NEW YORK

Median home price: $108,900

Median household income: $51,360

Principal and interest payment: $420 (9.8 percent of monthly income)

Nearby Binghamton University is considered one of the top public universities in the country.

5. DECATUR, ILLINOIS

Median home price: $100,000

Median household income: $46,198

Principal and interest payment: $386 (10 percent of monthly income)

Decatur is in the heart of corn country, and is home to an Archer Daniels Midland facility that processes hundreds of thousands of bushels of corn a day.

LEAST-AFFORDABLE METRO AREAS

1. SAN JOSE-SUNNYVALE-SANTA CLARA, CALIFORNIA

Median home price: $1.27 million

Median household income: $110,040

Principal and interest payment: $4,898 (53.4 percent of monthly income)

This is the only major metro area in this analysis with a six-figure median household income. But it’s also the only metro with a seven-figure median home price.

2. SAN FRANCISCO-OAKLAND-HAYWARD, CALIFORNIA

Median home price: $920,000

Median household income: $96,677

Principal and interest payment: $3,548 (44 percent of monthly income)

With a median home price of almost $1 million, homes in the Bay Area are hard to afford.

3. HONOLULU, HAWAII

Median home price: $760,600

Median household income: $80,513

Principal and interest payment: $2,933 (43.7 percent of monthly income)

Honolulu is one of the hottest housing markets for international buyers, with Canada, Australia, Germany, Japan and the United Kingdom leading the pack.

4. SAN DIEGO-CARLSBAD, CALIFORNIA

Median home price: $610,000

Median household income: $70,824

Principal and interest payment: $2,352 (39.9 percent of monthly income)

San Diego is also a top destination for foreign buyers, led by Canada, Mexico, the U.K., Japan and Germany.

5. BOULDER, COLORADO

Median home price: $546,400

Median household income: $74,615

Principal and interest payment: $2,107 (33.9% of monthly income)

The population of the Boulder metro area grew by almost 24,000 between 2010 and 2016, to 313,961. It’s home to the University of Colorado, where about 30,000 students are enrolled.

Data sources:

— Household income: U.S. Census Bureau’s American Community Survey from 2016 (the most recent available)

— Home prices: National Association of Realtors’ metropolitan median price index for the fourth quarter of 2017

— Mortgage payments: Principal and interest only on a 30-year, fixed-rate mortgage, assuming a 20 percent down payment, at 4.08 percent (the average rate for the fourth quarter in NerdWallet’s daily mortgage rates survey)

By HOLDEN LEWIS, NerdWallet (This article was provided to The Associated Press by the personal finance website NerdWallet.)

(© Copyright 2018 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.)