Q: I own shares of Company X and it isn't doing too well. What happens if it ends up going bankrupt?
There's no one-size-fits-all answer to this. It depends on the amount of assets the company has, how much it owes to creditors and senior investors, and what the company's post-bankruptcy plans are.
When a company files for bankruptcy, its creditors have the first claim to any of its assets. In other words, when inventories are liquidated or a company's real estate is sold off, the creditors (such as bondholders) get to recoup their investment first. Preferred stockholders, if any, are subordinate to bondholders, but are ahead of common stockholders. Only if there's anything left after all of the company's creditors and preferred stockholders are made whole will common stockholders receive anything.
As you might guess, common stockholders are usually wiped out completely. Most companies that go bankrupt don't have enough assets to cover their obligations. In the vast majority of cases, common stockholders are left with nothing.
However, there are exceptions. One notable example is mall operator General Growth Properties, which filed for bankruptcy in the wake of the financial crisis. During the bankruptcy restructuring process, the company's creditors were paid in full and equity investors actually received a substantial recovery consisting of a pro-rated allocation of shares of the "new GGP," as well as shares of the yet-to-be spun off Howard Hughes Corporation.
So while it's possible to come out of a bankruptcy with something as a common shareholder, situations like this one are the exception, not the rule.