Even as the Washington region’s stable economy has drawn record numbers of young adults, many older residents are leaving the area, an analysis of new census data shows.

In the past three years alone, the two conflicting migrations of young and old have pushed down the median age of the metropolitan area’s 5.6 million residents by six full months — to barely 36 years.

American Community Survey numbers for 2009 to 2011 measure how many people in various age groups leave a place compared with how many people arrive. In essence, they capture the ebb and flow of big cities as young adults move away after graduation and older people retire and relocate, replaced by newcomers starting their careers or settling down closer to family.

Few places illustrate the shift more than Washington. Over the three-year span marking the onset of the recession and the shaky recovery from it, the region averaged an annual net gain of more than 10,000 people aged 25 to 34, more than any metro region. It was ahead of Houston, Denver, Austin and Portland, Ore. So many young adults flocked to the area while the rest of the nation struggled with mounting job losses and foreclosures that Washington soared in the census rankings for that age group from 45th before the recession to No. 1.

During that period, almost 7,000 more people 55 and older left the area than moved in, a number surpassed only by New York, Los Angeles and Chicago.

Moving to and from the Washington area

“Washington is still a magnet for young people and college grads,” said William H. Frey, a Brookings Institution demographer who analyzed the data. “They find it’s a nice place to live, and as they get older, they may keep living here, at least until they’re 55.”

Despite the departure of many older residents, the total population age 55 and up rose by more than 50,000. That is largely because so many baby boomers have passed that birthday, joining a new age group. Virtually every city in the nation is also experiencing a jump in its 55-and-older population.

Despite persistent stereotypes of retirees moving to golf communities in warmer climes, surprisingly few people move far away after retiring.

Richard W. Johnson, director of the Urban Institute’s Program on Retirement Policy, said that only about 1.5 percent of retirees who are 55 to 65 — the age group most likely to move — relocate across state lines.

“Overall, most retirees stay put or stay in the same general location,” he said. “The movement to retirement locations is not nearly as concentrated as it once was.”

Surveys of AARP members, done most recently in 2010, show that nine out of 10 retirees want to remain in their own homes or at least stay in the communities in which they built they lives.

“If they do move, the number one reason is to be close to their families,” said Amy Levner, who specializes in home and family issues for AARP. “People 55 and older are not moving to Florida and Arizona in the numbers the Greatest Generation did. They’re moving in much smaller numbers, and usually to be closer to their kids.”

Bert Sperling, a resident of Portland who produces rankings of the best places to live, said the economy can explain both tides — of young adults moving to Washington and older adults moving away.

“Times are tight now, and D.C. is a job-creation engine,” he said. “Nobody’s really wealthy, but people are doing the best” around Washington.

Most of the cities attracting the biggest numbers of people 55 and up are ones that went through a collapse in housing prices and now are starting to rebound — Phoenix, Tampa and Atlanta, and Riverside, Calif.

“They’re affordable,” Sperling said.

Levner said many of the cities attracting lots of retirees or near-retirees still have a vestige of “small town” feeling to them — places like Austin, Denver, San Antonio and Portland.

One factor working to Washington’s detriment, she said, is its traffic.

“Our region is set up for commuters,” she said, noting that men tend to outlive their driving years by seven years and women by 10 years. “A lot of our neighborhoods aren’t set up yet to support walking.”

Although other cities are expected to move back up in the rankings once the economy improves, Frey said he expects Washington to retain a measure of cachet.

“Washington and a few other places, like Denver and Portland, have a lot going for them,” he said.

“It’s a combination of coolness, high tech and a place that probably has the prospect of staying economically above the water in the future.”

Candace Wheeler contributed to this report.