Middle linebacker Kwon Alexander and defensive end Arik Armstead combine on a sack. (Jayne Kamin-Oncea/Getty Images)

The San Francisco 49ers ended their disappointing 2018 season on a sour note, losing their final two games to finish 4-12, a fifth straight campaign without a playoff berth. Still, the team entered the 2019 season with optimism. Key starters, including quarterback Jimmy Garoppolo, returned from injury. Less noticed nationally, perhaps, the team also upgraded its defense, with reinforcements added via trade (Dee Ford), free agency (Kwon Alexander) and the draft (Nick Bosa). Even the oddsmakers in Las Vegas were impressed, and they set the team’s win total at nine back in April, despite last season’s poor mark.

Maybe they were on to something. Six weeks into the season, the 49ers’ record remains unblemished at 5-0, with the latest win coming over the Los Angeles Rams on Sunday to put San Francisco in the driver’s seat in the NFC West and possibly the conference as a whole. With the 1-5 Washington Redskins on deck, the 49ers’ flawless record may not be in danger any time soon.

“We’re 5-0, which is a great thing, but we’re not playing our best ball,” Coach Kyle Shanahan said, via the Mercury News. “We can do a lot of things better than that. We can continue to get better on offense. We can continue to get better on special teams. I also think our defense is just getting started, too.”

Just getting started? That reconstituted defense is allowing only one out of every four opponent trips to the red zone to end in a touchdown, tying the Niners with the New England Patriots as the league’s best red-zone defense. The defense is also limiting opponents to about a point per drive, the NFL’s third-best mark behind the Patriots and Buffalo Bills.

Defensive statistic San Francisco 49ers NFL average
Points per drive 1.0 (3rd) 1.9
Red-zone defense 25 percent (1st) 55 percent
Three-and-out rate 48 percent (1st) 31 percent
Expected points saved per 100 snaps 33 (2nd) 1.9

That’s not all. No team is forcing opponents to go three-and-out more often than San Francisco (48 percent). That, in turn, has given opponents less than 25 minutes of possession on average, the second-best mark in the NFL. Perhaps most impressively, San Francisco’s defense is allowing 33 fewer points per 100 snaps than expected given the down, distance and field position of each play against, per data from TruMedia. Since 2002, the year the league expanded to 32 teams, only this year’s Patriots have saved more points over the first six weeks of a season (45 per 100 snaps).

The Baltimore Ravens’ famous 2000 defense, by comparison, saved 19 points per 100 snaps during the first six weeks of that season, which ended with a Super Bowl win. That would be welcome news to the team’s most famous defensive star.

“We aspire every year to be compared to one of the great defenses of all time — the ’85 Bears, the 2000 Ravens, and the [1970s Pittsburgh Steelers] ‘Steel Curtain,’ ” cornerback Richard Sherman told the Mercury News.

So far, so good. And a lot of the credit is due to taking advantage of defensive coordinator Robert Saleh’s switch to a wide-nine alignment this season. According to Inside the Pylon, this defensive scheme “works to isolate the offensive tackles in space,” creating opportunities for edge rushers to beat blockers with speed on the outside and for interior linemen to win one-on-one battles inside.

The line has excelled. Bosa, tasked with winning a one-on-one battle with a blocking tight end or a right tackle pulled away from his primary gap, has flourished in his rookie year. The No. 2 pick out of Ohio State has four sacks, 14 hits and 18 hurries over 86 pass-rush plays, giving him the second-highest pressure rate (21 percent) among all defensive linemen. Defensive tackle DeForest Buckner has 16 total pressures and is the 11th-highest-rated interior lineman out of 61 qualified defenders, according to the game charters at Pro Football Focus.

Ford, the defensive end acquired from the Kansas City Chiefs in March, has been credited with 17 total pressures, while his ability to line up either as a defensive end or A-gap linebacker has given the team valuable flexibility.

And yet it’s Arik Armstead who ranks as the team’s most improved player. The fifth-year defensive lineman has 2½ sacks, a half-sack shy of his career high, and also forced his first fumble since 2016. In Week 1, Armstead, along with Bosa and Ford, pressured Tampa Bay quarterback Jameis Winston into throwing a game-deciding pick-six to cornerback Ahkello Witherspoon. A week later Armstead sacked Cincinnati quarterback Andy Dalton on the game’s first play. In a victory over the Pittsburgh Steelers in Week 3, he beat a double team to chase quarterback Mason Rudolph from the pocket; Rudolph then threw an interception into the waiting arms of cornerback K’Waun Williams. Armstread’s forced fumble later in the game set up game-winning touchdown drive. He would add eight total pressures and six stops at or behind the line of scrimmage over the next two games.

The improved pass rush has allowed Sherman to dominate again and Witherspoon, a third-round draft pick out of Colorado in 2017, to get off to a strong start, although he sprained his foot in Week 3 and hasn’t returned.

Sherman is allowing 0.7 yards per cover snap and holding opposing quarterbacks to a 46.4 passer rating when they target him in coverage. An incomplete pass, by comparison, earns a quarterback a 39.6 rating. Sherman hasn’t been this effective in pass coverage since 2014. Witherspoon was allowing a 59.5 passer rating in coverage before his injury, and he could be back by a Week 8 meeting with the Carolina Panthers. Opposing quarterbacks as a whole are only managing a 62.5 passer rating against the 49ers this season.

“We have the people. We can put the schemes together. We have the talent to do it and we have the people who work at that, no matter what type of game we are in,” Shanahan said. “I think we really do believe that we can win any game.”

Read more on the NFL from The Post:

Sam Darnold is back, and it’s time to add him to your fantasy football team

Officiating in Lions-Packers game sparks outrage as owners prepare to meet

NFL Week 7 power rankings: The 49ers are on the heels of the Patriots and Saints

Stefon Diggs’s big day for the Vikings might put trade rumors to rest

Teams have figured out how to beat Patrick Mahomes and the Chiefs

Forever tied together, Jameis Winston and Marcus Mariota come unraveled on the same day