If I have 50 shares in company A (worth $20 a share) and company B (worth $400 a share) comes along and purchases Company A, what happens to my 50 shares?
If company B buys company A, then it buys your shares in company A. That's what it means to buy a company -- you buy all of its shares. If your shares are actually worth $20, then you get $1,000. But they may offer more or less than $20 per share. It's also very common for purchasers to offer their own shares instead of cash, or a mixture of cash and shares. It's generally all-or-nothing -- if more than a certain percentage (usually 50%) of shareholders vote to accept the offer, then the remaining shareholders must also sell their shares on the same terms, and if the offer gets less votes than are required than the potential purchaser doesn't buy any shares.