Think of it like inventory. If you have 100 cars in a lot, and you sell the first for 10,000. Is the stock worth $1m? For accounting purposes, yes. Are you going to get $1m if you sell all the cars - no, you're not. Either of two things is going to happen - only 50 people want the cars and you have to start discounting to move the rest, or, once alerted to the sale of the cars, 200 buyers turn up and the price goes higher. So the total value of the cars isn't really $1m, apart from on an accounting sheet. Same as market cap.
The other 98 people in the room haven't assigned a value to the item. You've only found a market for 2% of a company. The other 98 people may sell at a higher or lower amount, but for each one that did, there has to be a supply of buyers at that level.
Summarized : market cap is the total value as derived from the current opinions of the people trading shares. It's not the same as total market value, because you could never buy the entire company for that amount.
Yes, I know 2% turnover is a high value, chosen to make it a simple example.
Why not look at mergers and acquisitions? When companies attempt hostile takeovers, are they making bids that undercut the market's own valuations? Do people like to sell their shares at large discounts? No. Companies have to pay a hefty price premium over the existing market value.
Indeed an open-market acquisition is a good indicator of the value of the company - the value of anything being what someone is willing to pay for it.
Nitpick: this depends on your inventory method.
Perpetual or periodic? LIFO? FIFO? Weighted average?