Facebook chief executive Mark Zuckerberg saw his net worth decline by about $5 billion Monday, but it could have been worse.

Ahead of Facebook’s worst one-day decline since 2012, prompted by news that data affecting 51.3 million members was improperly shared with a political consulting firm, Zuckerberg had been busy selling stock. So far this year, he has sold nearly 5 million shares.

Disposing of those Facebook shares before Monday ended up saving about $40 million, according to Securities and Exchange Commission filings and some arithmetic by MarketWatch. At Monday’s close, the 4.9 million shares Zuckerberg has sold this year under a predetermined plan would be worth $855 million. Zuckerberg made about $900 million selling those shares, according to calculations using average weighted prices reported to the Securities and Exchange Commission.

Facebook spokeswoman Vanessa Chan said in an email that the stock sales are intended to fund the Chan-Zuckerberg Initiative, the philanthropic investment organization the Facebook founder set up with his wife in 2015. In an SEC filing in September, Zuckerberg said he plans to sell at least $6 billion in Facebook stock over the next 18 months to fund the organization’s efforts.

Last year, Facebook abandoned its plan to create a new class of nonvoting shares that was concocted to allow Zuckerberg to retain voting control of the company. Zuckerberg said at the time that the stock’s gains over the past couple of years would allow him to retain control of the enterprise and still sell enough stock to fund his philanthropy without the new stock structure.

“Over the past year and a half, Facebook’s business has performed well and the value of our stock has grown to the point that I can fully fund our philanthropy and retain voting control of Facebook for 20 years or more,” Zuckerberg wrote at the time. “As a result, I’ve asked our board to withdraw the proposal to reclassify our stock — and the board has agreed.”

Facebook spokeswoman Chan declined to comment when asked whether the lower stock price would again change Zuckerberg’s plans to retain control of the company while funding his initiative.

Facebook’s stock is down nearly 2 percent this year, having continued its move lower early Tuesday, as the S&P 500 index has gained 2.9 percent, and the Dow Jones Industrial Average has fallen 0.4 percent.