The initial reaction was: "Wow!"

When Gaithersburg was recently ranked the 17th best place to live in the country by the online magazine CNN/Money, Gaithersburg Mayor Sidney A. Katz was "very surprised."

According to the magazine, Gaithersburg excelled in real estate appreciation, housing affordability, economy, education, environment, crime, leisure, population growth and weather, among the magazine's major ranking criteria.

"We are flattered and honored," said Katz, who first heard about the ranking from local television news. "It was not something we had applied for or that they had really contacted us about. It was done strictly on numbers."

Other criteria included unemployment, income growth and arts resources.

Of the 100 places ranked in the magazine's Aug. 1 issue, Vienna in Northern Virginia was named the fourth best place to live, and Ellicott City in Howard County came in 20th. Moorestown, N.J., topped the list.

With the help of OnBoard LLC, a real estate information company, the magazine started with a list of 40,000 places. That list was culled by considering only places with populations exceeding 14,000, within 60 miles of a major airport and within 30 miles of a major teaching hospital.

Many affluent suburbs didn't make the cut because they couldn't meet housing affordability criteria. And many big cities fell off the list because of poor crime statistics.

The magazine's editors decided to define "place" by Zip codes, rather than by census designations or incorporated areas, because those designations are often "a small part of what most people would consider a place," the editors wrote in the accompanying article.

Thus, while Gaithersburg's population is 58,091 in the 2004 Census estimate, the magazine lists the population of Gaithersburg as 132,508.

Patricia Andersen, a librarian at the Montgomery County Historical Society, also was surprised by the ranking.

She said Gaithersburg has changed dramatically in the last 30 years, from being a rural town to becoming a busy, ethnically diverse city, with a growing population of Hispanics.

"The biggest change is how much Gaithersburg has expanded," she said, pointing out communities along Muddy Branch Road or new communities such as Kentlands, as well as an expanding community of retirees.

In the midst of booming home prices in Montgomery County, Gaithersburg met the magazine's affordability criteria with a median home price of $347,339.

This came as a surprise to Andersen, who said she recently saw townhouses selling for upward of $500,000. "I don't know how long it's going to stay affordable," she said.

Gaithersburg's leisure statistics also fared well, with the magazine reporting 2,642 restaurants within 15 miles and 89 public golf courses within 30 miles, along with many bars, movie theaters, libraries and museums.

Gaithersburg's median household income is listed as $80,103.

Though the honor went to Gaithersburg, Katz said it is recognition of a prosperous region, pointing out the roles that the state, county and nonprofit organizations have had in building the community.

"They looked at things like education . . . but Montgomery County Public Schools does the schools," he said, adding that many of the leisure activities available are not necessarily Gaithersburg's doing.

"We did not win this award on our own," he said. "It's a regional award."

The Kentlands community is an example of modern Gaithersburg.