The Alibaba and Yahoo Japan stakes Yahoo got were selling half of Alibaba stake for $8B in 2012 and $40B remaining in 2019. They sold Yahoo Japan shares for $4B in 2019. Microsoft would have had no need to sell the 2012 stake at the time. They could have possibly doubled their money.
The market was not valuing Yahoo fairly for most of its life as Yahoo for the company name after this.
So when Yahoo’s remains changed to Altaba after selling that $4.5B Yahoo namesake and Yahoo Japan for $4B+ soon after, it was still a nearly $40B market cap company. Almost all of it being 16% of Alibaba.
Jack Ma refused to take Alibaba public until Yahoo sold half of its stake back to him (for peanuts).
Carol Bartz really screwed Yahoo over in its dealing with Alibaba. Yahoo had 2 seats on the 5-seat board of directors and Bartz couldn't be bothered to appoint directors to those. When she became CEO, Jack came to meet her and she dressed him down in front of his underlings: a big slap in the face to Jack. These two incidents made sure that he was as uncooperative as could be. He took Alipay out from under Yahoo and never informed Bartz.
Whatever you may say about Marissa Mayer, when she became CEO her first priority was to fix the broken relationship between Alibaba and Yahoo. She smoothed things over, and Jack let Yahoo keep the 15% stake, instead of asking for all of it back. She made Yahoo many billions with her moves.