Those old bus stations on shabby downtown streets in many American cities have turned into gold mines for the nation's bus companies, just when they need it most.

When developer Mohamed Hadid bought the Greyhound Lines terminal on New York Avenue between 11th and 12th streets NW, he said the land alone was worth $21 million. Neither Hadid nor Greyhound would disclose the purchase price. But the bus company reported that its profit from the transaction is large enough to cover the severance pay of 1,900 employes being laid off at its operatons throughout the country, according to Carol Neves, a transportation analyst for Merrill Lynch.

An industry source said Greyhound Lines has sold at least four terminals this year and plans to sell another 11 next year. Greyhound recently sold its 40-year-old bus station in Boston for an estimated $10 million and its Indianapolis terminal for about $6 million. The company also expects to sell its Chicago terminal and land for about $30 million, according to Neves.

Trailways Lines Inc. also has sold downtown terminals for substantial sums in recent years, according to Roger P. Rydell, that company's vice president for public relations. He would not discuss what prices the privately held company received, but said one property, in Davenport, Iowa, "could well have doubled" in value by the time Trailways sold it this year. The firm's 30-year-old Cleveland terminal, which was sold in 1984, was in the heart of a downtown revitalization area, he said.

Washington developers acquired the old Trailways terminal at 1200 I St. NW, near the Greyhound station, three years ago in a deal that included a land swap and an additional cash payment to Trailways. The bus company sold the property because land values in the area had "skyrocketed" and because it wanted to relocate its station near Union Station, Rydell said.

Greyhound, which serves the 48 contiguous states, has a 60 percent share of the intercity bus market, while Trailways, which has stations in 43 states, gets 25 to 30 percent of the market. The two companies are the only national bus lines.

The commercial building boom in central business districts has meant big profits for the bus companies. Terminals built three or four decades ago now are surrounded by new office buildings, and real estate developers eager to build more offices are snapping up station property, often for many times more than the original purchase prices.

Greyhound Lines, which has been losing money for several years, has reported profits within the last year, according to industry analysts. Greyhound Corp., the parent company, does not report earnings for the bus line alone. But all of the corporation's transportation units, which include smaller bus companies and manufacturing, together earned $21 million last year, after a $9 million loss in 1983.

Greyhound's economic problems reflect the radical change in transportation systems in the last two decades. Low-cost airline fares have cut into intercity bus business, and more people drive their own cars than 20 years ago, according to industry observers. Greyhound buses carried 64 million passengers a year in the late 1960s, but the company expects to serve only 34 million this year.

The layoff of 16 percent of its 12,000-member work force is part of a restructuring, Greyhound officials said. The company has been "meticulously analyzing" its bus terminal properties for several years, but stepped up the program early this year, according to Armen Ervanian, Greyhound's vice president for real estate. "If we can reduce costs and improve services" by moving out of "underutilized terminals, it doesn't make economic sense not to do it," he said.

Trailways, which owns and operates about 75 stations in the country, also has experienced a drop in ridership over the past two decades, as travelers have turned to charter trips rather than regularly scheduled routes, Rydell said.

Neves said Greyhound estimates that the 127 terminals it owned at the beginning of this year are worth $400 million. She said the company expects to get between $100 million and $150 million from the properties it sells.

In some cities, particularly in the northern and northeastern sections of the country, the bus stations are in areas that went to seed years ago and now are being revitalized.

The D.C. terminal, is on New York Avenue between 11th and 12th streets in the old downtown area, where the city is vigorously promoting redevelopment. The station site, on which Hadid's company plans to build a $100 million, 13-story office building, is across the street from the Convention Center, close to Metro Center and near two new hotels under construction.

The neighborhood looks a little shabby, although it seems to be improving rapidly.

The same can be said of the area around Greyhound's three-story, 277,000-square-foot terminal building in the heart of Chicago's Loop, which the company has just announced plans to sell, according to Greyhound spokesman Herb Doherty. "It has turned into a bad neighborhood over the years," but city efforts to revitalize the area have attracted new office building construction, he said.

The big Chicago terminal, unlike most bus stations, houses offices and stores in addition to a passenger lounge and ticket facilities, he said.

Greyhound is looking for a site for a new 35,000-square-foot terminal, after residents of a northwest Chicago community protested plans to build a station nearby, Doherty said. The move will take about two years, he added.

Texas developer Trammell Crow recently bought Greyhound's small Austin terminal and the approximately 21,000 square feet of land it stands on, Ervanian said. The developer plans to construct offices on the site, he added.

In several cities, including Indianapolis, Salt Lake City and Washington D.C., Greyhound has sold terminals this year and then leased them back for varying periods, according to Ervanian.

If the location "still made sense" and the "rental rate is attractive enough, we can better re-use the money in our business," he said.

Even if Greyhound did not need the money it is gleaning from its inner-city properties, the company probably would move to new, and smaller, quarters in many cities. Along with the drop in the number of passengers traveling by bus have come changing patterns in how they get to the bus terminal, Doherty said.

Greyhound surveyed its riders recently and found that most of them get to bus stations by car, subway or city bus, he said. As a result, Greyhound looks for new sites near expressways and subway and bus lines.