Portland is a middle-class city that could find itself without a middle class.

Time for some math: According to the U.S. Census, the city’s median household income is $44,000 a year, which, according to the real estate industry, is enough to qualify for a $173,000 house. The median home price in Portland is $241,700.

Already pinched, middle-income families could get squeezed right out of town.

Because it has most of the region’s rental units, Portland will probably continue to have most of the region’s low-income residents. And because it’s an attractive seaside city with a lively restaurant and arts scene, it will have more than its share of active, young retirees and empty nesters who can afford to pay a lot for a little space.

But unless Portland does something about middle-class housing, it’s going to lose its attraction to young people who are looking for a place to raise a family and start a career.

Portland has a huge advantage in the competition for economic growth: People want to be here.

It’s not just Portland. We are in the middle of a national trend of people choosing cities over suburbia as the best places to live. It is the undoing of a half-century development pattern that the urbanist Alan Ehrenhalt talks about in his book “The Great Inversion.”

The biggest American cities are already starting to resemble the capitals of old Europe, where the wealthy live in city centers and the poor and immigrants are pushed to the outer suburbs.

If Ehrenhalt is right, the older people buying and renovating battered houses on Munjoy Hill are just the start of a wave.

He cites a 2009 poll conducted by The New York Times in which 45 percent of people between the ages of 16 and 35 said that they would want to live in New York City someday. Since that works out to more than 20 million people, almost all of them will carry the regret through life that they never moved there.

Portland is not New York, but it has some of the things that people want in urban life, and even if a tiny fraction of the young people who imagined themselves in New York find this city a good enough alternative, it could be poised for dramatic growth.

The new economy calls for a nimble workforce. Suburban living is well-suited to stable employment with a single company, but it doesn’t work so well for people who expect to change jobs many times during their careers and don’t want to sell their houses every time.

Portland has been able to attract creative young people who are just starting out, but a lack of affordable housing means that many don’t stick around.

Portland already has good examples of what happens when you have a shrinking middle class.

According to the state’s flawed school-grading system, Portland has one failing elementary school and one with an A.

The A went to Longfellow in Deering Center, which is surrounded by a stable neighborhood of single-family homes.

The failing grade went to East End Community School, which is adjacent to Kennedy Park, a low-income housing project.

It’s not that Longfellow has all the good teachers or is using some advanced curriculum. It’s not that low-income students are intrinsically bad at reading or math. The difference is the combination of the stress and uncertainty of living in poverty, and the expectations of middle-class families for their children and their children’s schools.

Some people argue that Portland has to improve its schools to “keep” the middle class, but it really works the other way. If it keeps its middle class with the right kind of housing, the schools would improve, not just for the middle-class kids, but for the poor ones too.

There is no one solution to this problem, but the city and local nonprofits are working on it.

City Councilor Kevin Donoghue has worked for years to rewrite the city’s zoning code to allow for more residential density on the East End and West End. Donoghue’s idea is to create opportunities to build on “stranded” lots that currently don’t meet building setback and other requirements. As an added benefit, denser neighborhoods create demand for public transportation, which would make Portland more affordable for people who want to get around without a car.

Another idea is “inclusionary zoning,” in which developers of multi-unit housing would be required to keep some fraction of the new units affordable.

Habitat for Humanity builds sustainably affordable housing in the city, and there is a group forming that would buy and hold housing lots in a land trust to lower costs.

All of these approaches recognize that we have a shortage of housing for middle-income families already. If we don’t do something about it now, it’s easy to see where this is headed.

Greg Kesich is the editorial page editor. He can be contacted at 791-6481 or at gkesich@pressherald.com