The 2017 elections went quite well for Democrats. The party won the Virginia and New Jersey governor’s races, far outperformed expectations by picking up at least 15 seats in Virginia’s state house, and won a special election that gave them control of Washington’s state Senate.

All this, however, was effectively an appetizer when compared to the real main event: the 2018 midterms.

Next year’s midterms will offer the first nationwide referendum on Donald Trump’s presidency. The whole House of Representatives, a third of the Senate, and most governorships will be at stake, along with hundreds of state legislative seats and local offices around the country. The better Democratic candidates perform, the more strength they’ll have to block legislation or nominees they don’t like in Trump’s third and fourth years.

Furthermore, the results of the 2018 midterms will have an enormous impact on the course of US politics for the next decade — because the once-a-decade redistricting process is coming up. In most states, the governors and state senators who win in 2018 will serve four-year terms and still be in office when the redistricting process takes place in 2021 and 2022. The maps they draw for US House and state legislative districts will be in place through 2030.

So the stakes are quite high. But especially after Tuesday’s sweep, Democrats feel that they have the wind at their backs, for a few reasons:

1) The historical pattern strongly suggests that the president’s party is predisposed to face midterm difficulties.

2) Trump’s approval is remarkably low for a new president, and low approval is associated with poor midterm performance.

3) Democrats think their base is energized, which can contribute to recruitment of strong candidates, fundraising, and turnout.

Still, Democrats also face some very serious challenges — particularly in their effort to retake Congress.

The Senate map is so mind-bogglingly awful for them that retaking the chamber in 2018 seems like a major stretch. The House map is also slanted in Republicans’ favor, due in part to gerrymandering and in part to geography — as are many state legislative districts.

Of course, all this is still a year away, and much can change in that time. But here’s how to think about the party’s challenges and opportunities for 2018 midterms at this point.

The incumbent president’s party has historically been disadvantaged in the midterms

One starting point for understanding how midterms usually work — and why we should expect Trump to have a hard time — is that it’s been tough for the president’s party to do well.

Historically, this is how the House midterms have gone for presidents:

The mean result for a president’s party in postwar midterms is a loss of 25 House seats. The median result is a loss of 22 seats. (Next year, Republicans need to lose at least 24 seats to lose the House.)

In 16 out of those 18 midterms, the president’s party has lost House seats.

In those two midterms where the president’s party actually gained seats in the House — 1998 and 2002 — they gained a relatively small number: five and seven seats, respectively.

Meanwhile, the upper bound for midterm losses for the president’s party in the House has been massive — Democrats lost 63 seats in 2010 and 54 in 1994, while Republicans lost 49 seats in 1974. There are far more examples of double-digit House losses than there are of single-digit ones.

The most recent three midterm elections — 2006, 2010, and 2014 — have all been “wave” elections in which there was a backlash against the president’s party.

Due to partisanship and the prevalence of straight-ticket voting, Senate and governor results tend to go in the same direction as House races. There’s more variation there, though, because not all of those seats are up in every midterm.

Yet while the overall trend is unmistakable, the exact reasons for it aren’t entirely clear.

It’s not as simple as people becoming disillusioned with the new president once he’s in office, since most presidents do go on to get reelected. Perhaps a president’s supporters naturally become more complacent about the state of things when he’s not on the ballot and certain to spend another two years in office, while his critics naturally become energized and eager to express their displeasure with the administration in whatever way they can.

In any case, the history suggests an uphill battle for Trump and Republicans in 2018. There are some years in which the president’s party has effectively managed to fight to a draw or close to it in House races, but those years have tended to be rare.

Presidents with bad approval ratings usually do badly in the midterms. And Trump’s approval rating is bad.

Now, in looking for what separates mediocre midterm years for a president from disastrous ones, one big factor jumps out: presidential approval.

The historical trend is for presidents with high approval around midterm time to either keep their party’s House losses relatively small or (in two cases) even gain a few seats, per Gallup’s historical data.

Those two lonely postwar occasions in which the president’s party gained midterm seats were 1998, when Bill Clinton had 66 percent approval, and 2002, when George W. Bush had 63 percent approval.

The three occasions when the president’s party only lost a single-digit number of House seats — John F. Kennedy in 1962, Ronald Reagan in 1986, and George H.W. Bush in 1990 — also involved presidents with high approval ratings (58 percent or above for each).

One exception here is Dwight Eisenhower in 1954, who had remarkably high approval (75 percent) but lost 19 seats in the House anyway.

Meanwhile, every postwar president with a sub-50 percent approval rating around midterm time has lost a double-digit number of House seats, with truly massive landslides being common.

Some presidents’ approval ratings weren’t even all that low when they lost so big. In 1974, the newly sworn-in President Gerald Ford was at 47 percent approval in the post-Watergate midterms, and his party lost 49 seats.

In 1994, Bill Clinton was at 46 percent approval and his party lost 54 seats.

In 2010, Obama was at 45 percent approval and his party lost 63 seats.

Trump’s approval — currently about 38 percent on average — is already below those presidents who lost over 40 House seats. So if it stays around there, we should expect a very rough result for him in the midterms.

Importantly, though, these comparisons are to presidential approval ratings at midterm times, while we obviously only currently know Trump’s approval rating 12 months before the midterm. So there’s still ample time for things to change — either for the better or for the worse.

For instance, George W. Bush’s early 2001 approval ratings turned out to mean little — the 9/11 attacks sent his approval skyrocketing, and it was still strong by the 2002 elections. Meanwhile, Barack Obama was still quite popular in early May 2009 with a strong 66 percent approval rating, but by the time the 2010 midterms rolled around, it had deteriorated to a weak 45 percent.

Much could hinge, then, on the question of whether Trump’s approval is already close to its floor, or whether even more of his supporters start turning against him in the next year.

Democrats think their base is energized

Third, the Democratic base appears to be energized and enthusiastic, with strong or potentially strong candidates being moved to run for office in many races the party has barely contested of late.

Part of this base enthusiasm has played out in strong fundraising numbers for House challengers — “Democrats’ early money haul stuns GOP,” one Politico headline in October read.

But the recruitment matter may prove even more consequential. Both experienced local Democratic officeholders and fresh face candidates with attractive bios have calculated that 2018 is likely to be a favorable year for them to run for office.

The most convincing demonstration of this yet was in Virginia, when several little-known candidates won shocking upsets against longtime Republican incumbents in House of Delegates races that hadn’t even been contested in the Obama years.

And there’s a feedback effect to strong recruitment — the promise of a strong challenge could spur more Republican incumbents wary of a tough race to retire instead.

Yet there are some serious challenges for Democrats

But all is not roses for the Democratic Party. They face two very real challenges in their effort to retake Congress next year, and it’s unclear whether anti-Trump energy will be sufficient to overcome them.

1) The Senate is probably out of reach: There’s an obvious reason Democrats are focusing so much on the House of Representatives this year — the Senate map is horrifically bad for the party.

Republicans hold 52 seats in the Senate, and in theory, Democrats only need a net gain of three seats to take back the chamber. Their problem, though, is that the group of Senate seats up in 2018 is overwhelmingly their own members. The party will be defending a massive 25 seats, compared with just eight for Republicans.

Even more frighteningly for Democrats, 10 of their seats at risk are in states Trump won, and five of those are in states Trump won by 18 points or more. In comparison, only one Republican senator in a state Clinton won (Dean Heller in Nevada) is on the ballot. Check out this map (which, for simplicity, portrays Maine and Vermont among the Democratic-held seats, since independent Sens. Angus King and Bernie Sanders do caucus with Democrats):

Overall, Democrats would need an extraordinary amount of good political fortune to retake the Senate. But it’s worth noting that in recent months, they have gotten a few breaks in their favor, making the still unlikely possibility at least a bit more imaginable.

The most likely path for Democrats to retake the Senate involves some combination of the following:

Holding onto all or almost all of their seats in states Trump won

Picking off Dean Heller in Nevada

Winning Jeff Flake’s open seat in Arizona, or Bob Corker’s open seat in Tennessee, or defeating Ted Cruz in Texas

Health problems for Republican senators could conceivably put another one or two more seats on the ballot in special elections

Divisive Republican primaries could lead to weak GOP nominees in a few states

Still, all of that remains a big if. Considering how dismal the map is, the party would likely be thrilled to even maintain their current number of 48 seats. (Democrats will have a better shot at the Senate in 2020, when mostly Republican seats will be on the ballot.)

2) The House map is also tough for Democrats: In the House, all 435 seats will be up, as they are every two years. Democrats’ magic number there is 24 seats — that’s the net gain they need to retake control of the House.

Still, Democrats have a pretty big problem here with the map as well. Partly due to gerrymandering — the GOP’s 2010 midterm landslide let the party draw the lines for House districts in many states — and partly just due to where voters of different demographics have chosen to live, the House map is overall tilted in favor of Republicans.

Hillary Clinton won the national popular vote by 2.1 percentage points. However, she lost the median House district by 3.4 percentage points.

Overall, 230 House districts voted for Trump, and just 205 for Clinton.

There are 23 House Republicans representing districts Clinton won, which provide solid pickup opportunities. However, there are also 12 Democrats representing districts Trump won who would have to play defense.

So yes — to retake the House, Democrats wouldn’t have to just slightly improve on Hillary Clinton’s performance. They’d likely have to have their own supporters come out in force, Republican turnout be depressed, and a significant number of voters newly converted to the Democratic cause. Something like that happened in Virginia in 2017, but it remains to be seen whether it will happen nationwide next year.

The 2018 midterms are also hugely important for redistricting

But the stakes for the 2018 midterms extend beyond Trump — they’ll help define the battlegrounds of political combat for the next decade because of the impact they’ll have on the next round of redistricting.

The US Census is conducted every 10 years, with the next census schedule to take place in 2020. New districts for US House and state legislative races will be based on the results and take effect ahead of the 2022 elections.

States’ redistricting processes vary somewhat, and Justin Levitt of Loyola Law School has a good breakdown of how they work. But in most, the state legislature runs the process, with the governor usually getting veto power.

Last time around, that meant the GOP landslide of the 2010 midterms took place during a census year. The election installed all those new Republicans in state legislatures and governors’ mansions just in time for redistricting, giving them far greater opportunities to gerrymander.

The next redistricting won’t start until after the 2020 election. But crucially, many of the state politicians who will be in office for that redistricting will have been elected to four-year terms in 2018.

Indeed, in 34 states, the governor who will be in office for the next redistricting will be elected in 2018. (Two more were just elected in 2017). And in 30 states, half or more of state senators whose terms extend through the next redistricting will be elected in 2018. (Most state House members, meanwhile, serve two-year terms and will be elected in 2020.)

The upshot is that if Democrats want to reverse GOP gerrymanders — and get the opportunity to do some gerrymandering of their own — they can’t afford to sit around and wait for 2020. They need to make big gains in state races in the 2018 midterms.