The magic number is calculated by taking the number of games in a season, adding one to account for ties, and then subtracting the number of wins of the first place team and the number of losses by the second place team.
Every time a team in first place wins or the second place team loses, the magic number goes down by one. When the magic number gets to zero, it is mathematically impossible for the second place team to catch the first place team.
For the Cubs, their magic number for winning the NL Central Division currently sits at five. There are 162 games in a baseball season, then add one, then subtract 91 for the number of wins the Cubs have and also subtract 67 for the number of losses the second place Milwaukee Brewers have. Each Cubs win or Brewers loss lowers the magic number by one.
The Cubs have a separate magic number for simply clinching a spot in the National League Wild Card game. In both the National and American leagues, the top two teams that don't win their division play in a single-game playoff with the winner advancing to the Division Series alongside the division winners.
Currently, the Brewers and St. Louis Cardinals occupy the two spots in the National League, with the Colorado Rockies the first team out. The Cubs magic number to clinch a wild card playoff spot is two, calculated by taking 163, subtracting 91 for the number of Cubs wins and also subtracting 70 for the number of Colorado Rockies losses.