About 5,000 present and former Montgomery County residents are owed a total of $2.7 million because of a court ruling that the County Council acted improperly two years ago by imposing a special tax on profits from real estate sales.

Those who paid the tax -- mostly persons who sold their houses or apartments -- are due refunds averaging $540. But the county isn't going to go too far out of its way in providing the refunds.

Deputy County Attorney Robert G. Tobin said persons who paid the tax must apply to the county Division of Revenue for their refunds. Although the county will take newspaper advertisements listing names of those due the money, it will not notify each one personally, he said.

"There are probably people who moved to Florida who won't know they can get their money back," Tobin said.

The levy, called the real property recapture tax, was enacted in 1977 because council members felt that tax assessments had not been keeping pace with escalating real estate prices.

The Maryland Court of Appeals ruled last week that the county's attempt to tax the windfall profits that sometimes result from real estate sales was illegal. The decision overturned a Montgomery County Circuit Court ruling that upheld the tax.

The council exceeded its authority by seeking "to second-guess the state's expert appraisers . . . and thus to make a retroactive assessment," the court said.

The tax was figured by using a complicated formula that charged $3.70 for each $100 of the sum that resulted from subtracting four amounts from the selling price of a piece of property: 45 percent of the selling price, the property's assessed valuation (which is supposedly 50 percent of what the assessor thinks the property is worth), the cost of improvements to the property and an $8,000 exemption.

The seller of a $90,000 home would probably have paid up to $200 in recapture tax, depending on the size of the assessment on the property and improvements made on the home, according to a spokesman for the Montgomery County Board of Realtors, which filed the suit.