Pennsylvania lawmakers who redrew a congressional district map to advantage the Republican Party went too far, the state's Supreme Court ruled on Monday, delivering a blow against gerrymandering that signals limits to the practice across the country.

In a decision that could boost Democrats' odds of retaking the U.S. House of Representatives come November's mid-terms, Pennsylvania's Supreme Court ruled on Monday that the state's congressional map violates the state's constitution. It must be redrawn by Feb. 15.

The 5-2 court decision is expected to be appealed by Republicans.

The development came amid a pending ruling by the U.S. Supreme Court that could curb practices that have for centuries allowed politicians to choose their voters, rather than the other way around. 

That ruling, expected by June, could force the redrawing of wonky, unfair voting lines across the country. But regardless of the U.S. Supreme Court outcome, Monday's decision in Pennsylvania matters because it presents what the Brennan Center's Michael Li calls a "second front" for fighting gerrymandering — the state courts.

Pennsylvania's 7th congressional district is often cited as an example of partisan gerrymandering and made CNN's list of most obscenely gerrymandered congressional districts in America​. Its shape has been mockingly said to resemble Goofy kicking Donald Duck.

pennsylvania-district-7

Pennsylvania's 7th congressional district. (CBC)

Here's what to know about gerrymandering.

First things first: What the heck is gerrymandering?

Gerrymandering refers to the drawing of district lines — whether for Congress or for state legislatures — in order to give one party numeric advantage over the other. The technique is as old as the United States itself. In 1788, Founding Father Patrick Henry tried to gerrymander arch foe James Madison out of the first federal Congress. 

As the saying goes: It's not the voters choosing their representatives, it's the representatives choosing their voters.

Critics say gerrymandering harms democracy. By way of mathematical trickery, a party can lock out rivals from being able to achieve a majority. 

Mathematical trickery like what? 

Like "packing" and "cracking."

In packing, you're taking as many voters on the rival side as you can and cramming them into as few districts as possible.

Cracking refers to spreading voters as thinly as you can across as many districts as possible. Remember that margin of victory doesn't matter because winner takes all — 50 per cent plus one is enough.

packing and cracking

(Princeton Gerrymandering Project)

How skewed can things get?

Take these battleground states as examples:

Pennsylvania: In 2012, Republicans won less than half the statewide vote (49 per cent), and yet they took 13 out of 18 seats in the House of Representatives (72.2 per cent).

Ohio: In 2016, Republicans won just over half of the overall vote (51.3 per cent) but took 12 out of 16 House seats (75 per cent).

North Carolina: In 2016, Republicans won less than half (49.8 per cent) of the votes, but took control of 10 out of 13 House seats (76.9 per cent).

"Swing districts, even in our swing states, don't have any swing," says David Daley, a senior fellow at FairVote and the author of Ratf**ked: The True Story Behind the Secret Plan to Steal America's Democracy

Does this make that much of a difference nationally?

Democrats would say so.

The Brennan Center for Justice estimates extreme partisan bias gave Republicans at least 16 to 17 more seats in the 2016 election, and possibly as many as 29, according to one analysis. 

Democrats were 24 seats short of controlling the House of Representatives.

How does this happen?

In most states, the party in power during a redistricting year holds the redistricting pen. The last redistricting year was in 2010, when the last census happened. 

It just so happens that the Republicans won a wave election in the 2010 mid-terms — just in time to allow them to harness emerging mapping software and Big Data.

How precise are these computer programs?

Software like Maptitude crunches demographic details from the census as well as public records databases, voting records and even consumer preferences.

"Add into it social media — Facebook likes, Twitter activity — your magazine subscriptions, and it creates a perfect portrait of who all of us are in our houses," Daley says. "The programs can run down a street and you can have the houses on one side of a street in one district; and the other side of the street in another district altogether." 

How is this legal?

For the most part, courts have tended to leave it up to the states to engineer maps.

A few states (including California, Arizona and Montana) have independent commissions for redistricting, much like in Canada.

The Supreme Court justices have said that gerrymandering can, in theory, be so extreme as to be unconstitutional. The problem is how to tell when that line is crossed.

David Daley

David Daley of FairVote says the 'future of our democracy' rests on the way Supreme Court Justice Anthony Kennedy votes on this case. (David Daley/Twitter)

In recent years, mapping software has been the game-changer. The Wisconsin legislative map drawn up in 2010 targets voters with surgical precision, virtually locking out Democrats from controlling the House.

All of which brings us to the Supreme Court case.

Supreme Court test case: Gill v. Whitford

Plaintiffs say that in 2012, the new redistricting map for Wisconsin, a purple district, aggressively favoured Republicans. The party's candidates won a minority (47 per cent) of the vote but took 60 of the 99 legislative seats. Last year, Republicans won 53 per cent of the assembly vote but took 64 seats.

The Supreme Court is considering whether judges can throw out voting maps for being so lopsided they violate the constitution.

Which way is the court leaning?

The fact that conservative-leaning justice Anthony Kennedy grilled the defendants was seen as a possible sign that he's leaning towards the plaintiffs who oppose partisan gerrymandering. 

Kennedy is a swing vote, as Daley notes, "so it's not hyperbole to say that the future of our democracy rests on the way that this one justice rules on this one case."

Has the Supreme Court intervened before?

It has put discriminatory "racial gerrymandering" out of constitutional bounds. That's the kind of gerrymandering that was found in North Carolina, when the map diluted the power of black voters.

As a result, many states believed they could "go to town" on party-based gerrymandering, so long as they could prove it wasn't race-motivated, Li says.

"States defend maps disadvantageous to minorities, saying, 'We were just trying to hurt Democrats, and they just happen to be African-Americans and Latinos.'"

That opening could close as the Supreme Court tackles partisan gerrymandering.

One last thing: Why call it 'gerrymandering'?

gerrymander cartoon

This 1812 political cartoon satirizes the unusual shape of the district of South Essex, Mass., after it was drawn to favour candidates from Gov. Elbridge Gerry's Democratic-Republican Party over those from the Federalist Party. (Wikipedia/public domain)

Blame this 1812 political cartoon. When Massachusetts Gov. Elbridge Gerry signed off on a map designed to help the party in power, the Boston Gazette newspaper joked that it looked like a salamander, hence gerry-mander. 

Never mind that Gerry is actually pronounced "Gary."

When it comes to the 200-year-old practice of gerrymandering, there's plenty that still leaves critics scratching their heads.