The public employe layoffs now occurring at all levels of government across the country are having this perverse effect: they are unraveling some of the nation's largest affirmative-action programs. And in the process they are raising this new question:

Should there be affirmative action in firing as well as hiring? Should minorities and women, often the last to have been hired, also be the last fired or may they be fired first, as they generally are now?

That question is not academic. It has prompted a spate of lawsuits across the country as layoffs have increased with the recession. And it has created a rift in an old alliance, pitting civil rights groups against organized labor.

The recession has hit minorities and women hardest, and for the first time in recent memory it has hit the public bureaucracies, traditionally among the most important sources of jobs for these groups.

In the federal bureaucracy, those blacks and women in the upper grade ranks and those in administrative jobs have been most affected. Woman managers are being laid off at a rate more than twice the average, minority-group members at a rate 3 1/2 times that of all administrators.

In Congress, and in city halls, statehouses and courts around the country, labor continues to insist on the rule of seniority. But others say it is time to amend the last hired-first fired rule to protect some of the women and minorities who only recently were hired.

Special publications of the Bureau of National Affairs comprehensively examining the problem have found the imbalance in layoffs to be a problem for state and local governments around the nation from Boston to Los Angeles and in Detroit and Kalamazoo.

Four of every five Maryland state employes receiving layoff notices last October were women or minorities. In Detroit, where three of every five members of the work force are black, four of every five of the nearly 3,000 city employes laid off over the last couple of years have been black.

In Springfield, Ill., a federal judge intervened last year to order the school board there to rescind layoff notices sent to minority teachers.

Following strict seniority procedures, the school board had sent notices not only to minority teachers who had been hired to comply with the court's affirmative-action plan but also to many teachers who were already working five years earlier when the judge had declared minority representation on the teaching staff to be unacceptably low.

The teachers' union in Springfield appealed the judge's order, which had the effect of bumping longer-tenured whites before minorities, and the issue is now before the federal Court of Appeals in Chicago.

Most affirmative-action plans were drawn up in the last decade during a period of growth, especially in state and local governments. One of the arguments for them was that women and minorities could be given jobs without whites being displaced. Only rarely did agreements address what was to be done in a period of layoffs and retrenchment.

"The civil rights and labor union leaderships were working very closely in that period," Thomas Atkins, general counsel of the NAACP, recalled. "It clearly would have been a very great strain on that coalition had the question of what do you do when the jobs have to be reduced was thought out.

"I think there was a kind of gentlemen's agreement not to deal with that, or to hope that by the time it developed, some creative solutions would have presented themselves," he said.

For unions, the seniority system is considered sacrosanct. "Seniority is a basic trade union principle," said Linda Lampkin, director of research for the American Federation of State, County and Municipal Employes (AFSCME).

"When you don't have a seniority system , you have employers who make decisions on an ad hoc basis on who to promote, who to lay off," said lawyer Michael Gottesman, who has argued the issue before the Supreme Court on behalf of steelworker union locals. "It can be made on the basis of favoritism, it can be made on the basis of payoffs or sexual favors. Seniority replaces management's unilateral control with an absolute, objective yardstick."

Atkins contends that exceptions ought to be made for minorities and women, especially when they involve employers who had been found by courts to have discriminated in the past.

"We argue that seniority benefits those who were able to get through the door at a time others were excluded from entering and therefore the white person who has been employed has been improperly aided by the fact of the prior racial discrimination," Atkins said.

But he and other civil rights lawyers face an arduous uphill battle in getting the Supreme Court to accept that argument. The federal Civil Rights Act of 1964 specifically exempted union seniority agreements and the court has ruled in a 1977 case that these systems are illegal only if it is proved that they were designed with the intent of discriminating.

The survey and analysis by the Bureau of National Affairs found state and local governments grappling with the problem in various ways. California has the most stringent law protecting women and minorities when layoffs occur.

Twenty-five other states had rules and regulations of varying strength and untested legality directing that consideration be given to affirmative-action plans when there are reductions in force.

In Atlanta, the black-run government has said it will lay off on the basis of merit, not seniority, drawing outcries from local unions. Unions and civil rights groups alike expect that the matter will ultimately be settled by the courts.

The Reagan administration has taken no action to mitigate the effects of layoffs on women and minorities in the federal government.

Officials at the Office of Personnel Management and the Office of Management and Budget have given lip service to the problem and passed the buck to the Equal Employment Opportunity Commission, an agency leaderless and immobilized for the last year as President Reagan has pared the size of the federal work force.

The EEOC has taken no action and other agencies in the government that might be expected to monitor the effects have themselves been cut back.

A survey of 40 federal agencies by a task force chaired by Rep. Michael D. Barnes (D-Md.) found that while there were twice as many whites as blacks among the 3,400 employes riffed last year, minorities were laid off or had their positions downgraded at a rate of 69 per 10,000 minority employes compared with a rate of 46 per 10,000 white employes. Overall, women were laid off or demoted at a rate of 47 per 10,000 employes.

The survey found that neither blacks nor women in low grade clerical jobs were disproportionately affected. The discrepancies grew as the grade level got higher, with women administrators being riffed at a rate 123 percent above the average for all employes and minority administrators at a rate 250 percent higher than the average.

There has been no comprehensive survey on the overall impact of layoffs on women and minorities in state and local governments, which grew rapidly over the last decade but began to contract in the last two years. There were 250,000 fewer state and local government employes this January than a year before, according to the Bureau of Labor Statistics.

This trend and the effects of the seniority system on the layoffs are being viewed with alarm by civil rights organizations. "The progress for blacks has been more in the government. As a result the middle class is overrepresented in government," said Robert Hill, former chief researcher for the National Urban League.

In the mid-1970s when the economy was producing hundreds of thousands of new jobs, two of three blacks moved into positions in government. Fewer than one in five whites did so.