In cell number 417 of the Gothic, century-old wing of the Maryland Penitentiary last week a second bunk was welded to the yellowish wall so prison officials could fit two men into the tiny cubicle. Up and down the rows of hundreds of 9-by-5 foot rooms, second bunks were being anchored to the walls of the very cells from which they had been removed just weeks ago.

What was happening here was in open defiance of a federal court order to eliminate double-celling, but prison officials said they had no other choice. For more than two years they had tried to ease overcrowding. Now, despite it all, the place was simply bursting at the seams.

"No one is happy with the decision [to return to double-celling]," said state corrections chief Gordon Kamka, who faces a possible contempt of court citation for his actions. "The realities of the situation forced us to do it."

The overcrowding in Maryland's prisons has been a politically explosive issue in the state for many years. Kamka and his boss, Gov. Harry Hughes, arrived on the scene two years ago, after the court order to ease overcrowding, and both men said they were committed to resolving the problem without building new prisons.

They soon discovered, however, that most state legislators were opposed to their deinstitutionalization concepts, and so they labored with a compromise that involved the construction of some new buildings and the granting of more early paroles. This approach has not worked as effectively as they had hoped, which, to the prison officials at least, explains why the bunks are being welded back on the cells.

Even with the renewed doublecelling, there still was not enough room for all those who were pouring into this, the reception center for the entire state prison system. Some new convicts were already living in the prison hospital -- healthy men sent to sleep and eat in rooms across from the sick or psychotic. Others were being sent to the area that once was "death row," to sleep within feet of the long unused gas chamber. Still other new inmates were shuttled to the "segregation tiers" -- a rat-and-roach infested area meant for incorrigible prisoners, a place that one official said houses "the worst of the worst."

More than 300 inmates who belong in state institutions cannot even get in the front door and were backed up last week in aged county jails where there are no rehabilitation programs.

Here at the reception center, where Assistant Superintendent Sebastian Valenti says that "every day has been a crisis day for months," today had been expected to be even more critical. The center, built to house 280 inmates, held nearly double that number last week.

Last Wednesday, with capacity strained to its outer limits, officials placed a "freeze" on inmates coming in from county jails. Valenti knew the freeze would end today, and he sweated out the weekend wondering how he would handle the overflow. Finally, he learned that 17 men had been ordered released in other parts of the system, and once again the numbers in the delicate balancing act prison officials perform worked out to open up the space he needed to survive for one more day.

The failure to end overcrowding, some officials say, is because of unavoidable delays in construction of new prisons. But the answers go much deeper. Public safety and corrections secretary Gordon Kamka believes there is still a lack of alternative community programs for those convicted of crimes who do not really need to be incarcerated in a state institution. He says that too many men sentenced to short terms are still being ordered into the state system because there are no alternatives.

Lawyers for the inmates who won the original overcrowding ruling in federal court argue that the efforts to comply have been "too little and too late." They assert that the state's parole commission is still failing to parole enough low-risk inmates. Prison officials, they say, are using the stop-gap measure of holiday commutations -- mass releases of prisoners by the governor -- often on the eve of a compliance deadline to deal with the situation.

But whatever the reasons behind overcrowding, the lawyers are now asking a federal judge to find officials in contempt of his order and to fine the state $1,000 a day until they comply. The lawyers have also asked the judge to appoint an individual outside the prison system to identify inmates eligible for release and oversee new parole procedures.

On Friday the lawyers will argue the case in Baltimore before U.S. District Court Judge Alexander Harvey.

It was in May 1978 that Harvey and another judge ruled that Maryland's two largest prisons were so overcrowed that conditions represented "cruel and unusual punishment." The judges declared that housing two inmates in cells of 40-to 44-square feet in the penitentiary and the Maryland House of Correction in Jessup offended "contemporary standards of human decency."

The judges first ordered the overcrowding ended by April 1979, but through appeals to higher courts and eleventh-hour pleas for more time, state officials won three separate extensions of the deadline.

Last Oct. 1, the most recent deadline, the state finally complied with the order, according to officials. There were no longer double bunks in the penitentiary, the state's century-old maximum security prison in Baltimore, and none at the House of Correction, an aging medium-security prison in Jessup.

Likewise, officials had torn out the top bunks from almost all of the cells in the reception center, memorializing the event by placing a wooden plaque in the superintendent's office with one of the huge metal bolts and chains that had previously anchored a bunk.

But Richard Seligman, an attorney for the inmates who originally brought the lawsuit, insists that officials were merely trying to appear in compliance by taking inmates out of double cells and packing them into the prison hospital and the old death-row area, trading "one set of deprivations for another."

At one point, officials began housing prisoners on the "flats," a sort of hallway outside the tiers of cells. But because of security problems, the fact that other inmates threw food down from the tiers and the extreme cold, officials stopped the practice.

On Oct. 24, reception center superintendent Patricia Quann ordered second bunks reinstalled in 87 cells. And as more inmates began to pour into the center, tier by tier the reinstallation continued with the final touch of welding the bunks in last week so they would be more stable.

Inmate Wright Wiggins says he was in a single cell for only a few days, when he was suddenly told he would have to double up. "To tell you the truth the cells aren't even big enough for one," said Wiggins, who noted that there can be a "lot of confusion, a lot of fights if cellmates don't get along."

Quann says the increase in prison population that caused the doublecelling was not surprising because each autumn there is a sharp jump in the number of sentencings, after a slow summer period.

"Ordinarily, the second week in December, it starts to drop. Our prayer is that that will happen. Our intake [of prisoners] now is exceptional. And we're scared that it won't turn down."

Officials got some good news today when they learned that there was a slight downturn in the total prison population for the first time since Oct. 1. The population now stands at 7,862 prisoners, in a system meant to hold just over 6,400.

Officials expect the opening of two new institutions -- a reception center in Baltimore and a 500-bed annex in Jessup -- to ease their problems. Both were scheduled to open this year, but because of construction delays the date has been moved back to April 1981.

Still, new prison beds, according to experts on both sides of the controversy, are not the real answer. "Until we have some real system changes, the addition of beds will not help in the long run," says the embattled public safety secretary. "At some time, we'd be back to where we are today except with added beds."

Kamka says the biggest change must come in the handling of short-term prisoners, those with sentences of less than three years. More than half of the current prison population has such sentences, and about one-fourth have terms of less than a year. In most states, such prisoners would never even see the inside of a state institution, but would remain instead in a county facility.

Since taking over as secretary in 1978, Kamka has pressed relentlessly for the construction of community rehabilitation centers in the counties, a program to which the legislature -- after a grueling battle -- agreed to allot $8 million last session. Though eight such centers are now in the works, it could be years before they are actually opened.

Meanwhile, the state is facing a Friday court hearing before a judge who warned months ago that if deadlines were not met, "the time will come for this court itself to take the drastic action of ordering the release of state prisoners to reduce the overcrowded conditions.