SAN FRANCISCO — With four games left in the regular season, a Giants team that set a San Francisco-era record for single-season wins with its 104th victory on Wednesday now has a magic number of three to clinch the National League West.

What is a magic number? How is it calculated? And most importantly, why does it matter?

Major League Baseball defines a “magic number” as the number representing the combination of wins needed by a team and losses by a team’s closest competitor to clinch a given goal.

After becoming the first MLB club to clinch a playoff berth earlier this month, the Giants’ new goal is clinching the NL West and ending the Dodgers’ run of eight consecutive division titles. San Francisco enters the final four days of the regular season schedule with a 2.0-game lead over Los Angeles, so the earliest possible date the Giants can celebrate a clinching is Friday, October 1.

“We understand the magnitude of what we’ve done to this point in having 104 wins and knowing how hard it is to win 100-plus games in a season,” starter Alex Wood said following a 1-0 Giants win on Wednesday. “But I think one of the coolest things about our group of guys is we’re so micro-focused. It’s show up the next day, give everything we’ve got and try to win a baseball game.”

Regardless of how the Dodgers fare over their next four games, the Giants can lower their magic number from three to zero and win the NL West by finishing the regular season with a 3-1 record. Three wins would eliminate the possibility for the Dodgers to catch the Giants, so even if the Dodgers win their last four regular season games, Gabe Kapler’s club has control of its own destiny.

If the Dodgers lose once over the next four games, then the Giants can finish 2-2 and still end the season atop the National League West. Any Dodgers loss lowers the Giants’ magic number by one, so in the unlikely scenario San Francisco finishes the season 0-4, Los Angeles would need to end the season 1-3 to lose the NL West race.

With the Giants ahead by 2.0 games, there’s also a realistic scenario of each team finishing the regular season with the same number of wins and losses. Posting identical records at the end of a 162-game season would force the Dodgers and Giants to play a Game 163 tiebreaker on Monday, October 4.

That tiebreaker would take place at Oracle Park because the Giants won the season series between the two clubs 10-9.

The Giants nearly saw their magic number fall from three to two following a 1-0 victory over the Diamondbacks on Wednesday night, but the Dodgers hit four eighth-inning home runs off the Padres including three against right-hander Emilio Pagan to overcome a 9-5 deficit and win 11-9.

With a chance to drop their magic number to two on Thursday, the Giants will face Diamondbacks left-hander Madison Bumgarner. Bumgarner is 7-10 with a 4.58 ERA this season, but he threw seven innings of one-run ball in a 3-1 Arizona win over San Francisco on August 3.

The Giants are 20-6 in September, but have been unable to create much separation in the standings from a Dodgers team that went 21-6 in August and is now 18-7 in September. The competition for the NL West crown has turned into one of the most dramatic division races in MLB history as both teams are motivated to avoid playing a one-game wild card playoff against a St. Louis Cardinals team that just had its 17-game win streak snapped on Wednesday.

“As long as we take care of business,” Giants outfielder Kris Bryant said Wednesday. “We control our own destiny.”