But both Republican and Democratic majorities in statehouses often remap districts to favor themselves, either by cramming opposition voters into a single district or by dividing them so they are the majority in fewer districts, tactics called “packing and cracking.”

Courts have generally agreed that some partisan advantage in redistricting is tolerable, in part because voters themselves are not spread equally across a state or district by party. But the plaintiffs in the case, 12 state Democrats represented by the Campaign Legal Center, had argued that the Wisconsin remapping was among the most sharply partisan in the nation.

Their lawsuit said that in the 2012 elections for the Assembly, Wisconsin Republicans won 48.6 percent of the two-party vote but took 61 percent of the Assembly’s 99 seats.

A key question in Monday’s ruling, as in past challenges to redistricting, was whether that division was unacceptably partisan, a question that previous courts have stumbled over.

“Nobody has come up with a standard to measure constitutionality — how to distinguish between malevolent, evil partisanship that’s manipulative, versus the natural advantage one party might have as a result of where voters happened to live,” said Edward Foley, the director of the Election Law Project at Ohio State University’s Moritz College of Law.

In Monday’s ruling, the court was swayed by a new and simple mathematical formula to measure the extent of partisan gerrymandering, called the efficiency gap. The formula divides the difference between the two parties’ “wasted votes” — votes beyond those needed by a winning side, and votes cast by a losing side — by the total number of votes cast. When both parties waste the same number of votes, the result is zero — an ideal solution. But as a winning party wastes fewer and fewer votes than its opponent, its score rises.

A truly efficient gerrymander spreads a winning party’s votes so evenly over districts that very few votes are wasted. A review of four decades of state redistricting plans concluded that any party with an efficiency gap of 7 percent or more was likely to keep its majority during the 10 years before new districts were drawn.