Facebook (NASDAQ:FB) stock gained 6.5% on Wednesday’s news that it’s testing a service to put ads on mobile apps other than its own. It closed at $23.29, some 33% above its all-time low of $17.55 on Sept. 4. The news regarding mobile ads, combined with Mark Zuckerberg’s comments eight days ago about Facebook’s future, has reinvigorated the stock.

That’s great news for existing shareholders, but especially Facebook itself, which will buy back 101 million of its own shares on Oct. 24. It’s an under-the-radar move that underscores why you shouldn’t count out the social media giant just yet.

First, let’s cover the details of the share repurchase, which technically isn’t really a buyback at all. On Sept. 4, the same day Zuckerberg first spoke publicly since the May IPO, Facebook released details about how it would handle the restricted stock units vesting on Oct. 25.

It’s required to withhold 45% for taxes. With a total of 225 million pre-2011 RSUs vesting on Oct. 25, Facebook will withhold 101 million shares and pay the IRS the value of those shares on Oct. 24. In Facebook’s 8-K, it calculated the estimated cost would be $1.9 billion based on the Aug. 30 trading price of $19.09 a share.

With the shares increasing by $4.20 since the beginning of September, the total cost to buy them has increased by $424 million, to $2.35 billion. Let’s assume the shares increase another 22% (the increase in September) in the next month to $28.41. The buyback would ultimately cost $2.87 billion, 49% higher than if the shares had vested at the end of August.

The increased cost represents approximately 9% of the $10.2 billion in cash and marketable securities Facebook had on the balance sheet as of the end of June.

The alternative would have been to sell 101 million shares immediately prior to the vesting date, using the proceeds to settle up with the tax man. But that approach has two problems: First, the issuing of shares is dilutive to existing shareholders. Second, it’s questionable how successful a secondary offering would be when the existing share price is lower than its IPO price.

Facebook definitely chose the better solution in this situation.

In an Aug. 22 appearance on CNBC, famed valuation expert Aswath Damodaran suggested the ultimate entry point for Facebook was $18 a share. The professor reasoned that although he values the stock at $24, the issues of corporate governance and lock-up expirations keep downward pressure on its stock, requiring a bigger margin of safety for the long-term investor.

When Facebook announced its plan on Sept. 4, its stock was indeed below Damodaran’s strike price. By announcing its plans, Facebook was signaling to investors that it believed the intrinsic value of its stock was worth more than $19.09 a share, the price on Aug. 30. In my opinion, that’s the only reason for a company to repurchase its shares.

In the end, some will suggest Facebook did this because it had no other choice for meeting its tax obligations. On the other hand, those able to broaden their thinking will realize this decision was made months before the IPO in May as part of Facebook’s overall planning, and it signifies the act of a management team far more in tune with its business than many give it credit.

If you think Mark Zuckerberg is in over his head, this simple act should lead you to reevaluate that opinion.

As of this writing, Will Ashworth did not own a position in any of the stocks named here.