Not every bankruptcy leads to home loss. During a Chapter 7 bankruptcy, the bankruptcy trustee may liquidate your nonexempt assets, including your home, to pay off your debts.
However, most jurisdictions provide exemptions that allow you to protect a certain amount of equity in your primary residence. If your equity is within the exemption limits, you may be able to keep your home.
A Chapter 13 bankruptcy, on the other hand, allows you to keep your assets while entering into a repayment plan to catch up on missed mortgage payments.