President Trump seems pretty confident that his party will fare well in the 2018 midterm elections, a confidence that is not shared by most pundits, or by those considering recent congressional polling or by those familiar with the history of midterm elections after a new president is sworn into office.

Polling shows a strong advantage to the Democrats on what’s known as the generic ballot — how many Americans would rather vote for a Democrat vs. a Republican for Congress. Most presidents also see their parties lose seats during midterm elections, particularly after the president first takes office. (And pundits use these data points for their punditry.)

There is a big difference, though, between “faring poorly in a midterm” and “giving up control of the House or the Senate.” For Democrats eager to be able to halt Trump’s agenda, the former would be a moral win, but the latter actually would be immediately useful.

So, how likely is it that Democrats might retake one or both chambers in 2018? Let’s assess.

The Senate

We looked at this question last week while seeking to explain why a Democratic victory in Alabama was so important to the party. Now that we know the result of that election, the picture gets a bit sharper.

After Alabama, the split is 51-49 in favor of the Republicans (including the two independents who vote with the Democrats). In the abstract, this seems fairly easy for the Democrats to surmount.

But not every senator is up for reelection next year, so many of those seats will remain safely in Republican or Democratic hands. Specifically: Republican hands. Of the 32 seats held by a Democrat or a Republican that are on the ballot next year, 23 are held by a Democrat. So to retake the Senate, the Democrats must swing two Republican seats — while also holding all of their own.

The Cook Political Report rates congressional races based on a number of factors, including polling, the lean of the district and so on. It has ratings for the Senate contests next year, ranging from solid for the party that currently holds it to a toss-up — a race that could go either way. Those ratings are shown below at left.

At right is another calculation. Let’s say that the Democrats hold all of the seats that are rated as solidly Democratic, likely Democratic, leaning Democratic and Democratic toss-ups — that is, they win all of the seats that they hold now. Let’s assume, too, that the Republicans win the five seats they have that are rated as solid — seats in Nebraska, Utah and Wyoming, among others.

What’s left are three Republican toss-up seats, one of which is in a state that Democratic presidential nominee Hillary Clinton won in 2016 (Sen. Dean Heller’s in Nevada). The Democrats need to win two of those three to take a majority — plus hold all of theirs, including seats in Indiana, Missouri and West Virginia, all of which went for Trump last year by wide margins.

The House

It would seem as though the House, where the Republicans have a much bigger advantage at this point, would be a steeper climb for the Democrats. That may be misleading.

A key difference is that every single House seat is on the ballot. If the country were suddenly to vote solely for Democrats, the Senate would still be home to 44 Republicans in 2019. The House would be 435-0.

To evaluate House seats, Cook creates something called the Partisan Voting Index, or PVI, a measure of how the district voted in recent presidential elections. Here’s the distribution of the House as of the beginning of the current (115th) Congress, as sorted by PVI score.

In theory, seats with a PVI score that favors the Democrats would be more likely to be held by a Democrat. After all, the same people were more likely to vote for Democrats for president. In practice, that’s usually — but not always — the case.

The split in the House is as follows. At the beginning of this Congress, the Republicans had a 47-seat advantage. They held eight seats in districts with a PVI score that favored Democrats, and Democrats held nine in districts that favored Republicans. The Democrats would need to gain 24 seats from the Republicans to control the chamber. That’s the key number for what follows.

One advantage that the Republicans have in 2018 is that people tend to reelect incumbents. Because more Republicans are in the House, there are also more incumbents, who one would think would have an advantage.

But the Republicans have also have had a spate of people announce their retirements. That means that a lot of Republican-held seats — 25 so far — will no longer have the advantage of incumbency, including nine in districts that lean Republican by fewer than 10 points, according to the PVI.

Of course, it’s not the case that the Democrats will simply win all of those seats just because there’s no incumbent. Tennessee districts that lean Republican by 20 points probably aren’t about to elect Democrats (unless, say, Roy Moore moves to Tennessee and wins the nomination).

As we did with the Senate, we can use Cook’s ratings to estimate how the election might play out. These seats are in play, according to Cook.

Taking out the seats that are safe, the distribution looks like this.

Cook estimates that there are 17 Republican and four Democratic seats that are toss-ups or likely to switch parties. Assuming that the Democrats held all of their seats and took all of the Republican seats in play, that’s a gain of … 17.

If they further win all of the seats that lean Republican (and hold their own), the total Democratic gain shifts to 39 — enough to swing the chamber.

That includes winning a lot of very Republican districts, though. But Democrats don’t need that many; if they hold their own seats, win the toss-ups and take every Republican-leaning district that has a PVI score of R+2 or less, they will have the majority.

All of this is using a snapshot of the races at the moment. One thing we noted last month is that a year out, the signs of a flood are a bit hard to see in Cook’s ratings. Here are the ratings a year before the big elections of 2006 and 2010 and then the final ratings.

In 2006, 34 more Republican seats were in play at the time of the election than a year prior. The Democrats took control of the chamber.

In 2010, there were 32 more Democratic seats in play by the time of the election than the year prior. The Republicans took over.

The point, simply put, is that there are a lot more paths to the majority for Democrats in the House than in the Senate, and it’s hard, at this point, to estimate precisely just how many there will be.

Which isn’t to say that the Senate can’t surprise us. Next year, there will be a Democratic senator from Alabama. Is it really that hard to imagine, right now, a Democratic senator from, say, Texas? Trump won Ohio, where Democratic incumbent Sherrod Brown is expected to be reelected next year, by eight points — and Texas by just under nine.

It’s numbers like those that have Democrats salivating.