Flint, Michigan, ranked as the nation's most affordable real estate market in WalletHub's latest housing analysis. Detroit placed second among the 300 cities evaluated.

WalletHub based its analysis on 10 factors, putting the heaviest weight on the ratio of median home prices to household income and the cost per square foot. Each city was scored on a 100-point scale, with higher scores reflecting greater affordability.

The median home price in Flint is about $66,000, according to Zillow, while the median home price in Detroit is about $76,500. At the opposite end of the ranking, Santa Barbara, California, was identified as the most unaffordable U.S. city for buying a home, with a median home price of around $1.85 million, according to Zillow.

The affordability gap, defined as the income needed to afford the median-priced U.S. home, has widened since 2020 as mortgage rates and home prices have climbed. A buyer now needs an annual income of about $120,000 to afford a typical home in the United States, according to the Federal Reserve Bank of Atlanta, which also reported that the median sale price for homes nationwide is about $400,000. In January 2020, a buyer needed an annual income of about $63,000 to afford a typical home, according to the same source.

An April analysis of IRS tax data from the Tax Foundation found that millions of Americans are moving from higher-tax states such as California and New York to lower-tax states including Texas, Florida and North Carolina. None of those three destination states have cities among WalletHub's 10 most affordable housing markets.

Older Americans are more likely to be motivated by tax considerations when deciding where to move compared with younger people, Virginia Tech assistant professor of real estate Hainan Sheng said. Younger workers are driven by issues such as affordability, job opportunities and urban lifestyle, he said.