You are not guaranteed to keep your home if you file for bankruptcy. If you file for Chapter 7, which involves sacrificing assets in order to eliminate debt, you probably have the option to either reaffirm your mortgage loan formally, or, in certain jurisdictions, simply continue to make payments. However, if your home equity is greater than the homestead exception in your state, filing for Chapter 7 will most likely result in losing your house. The other option is to file for Chapter 13, which probably is the better option if you have some equity in your home or have fallen behind in payments; it enables you to pay off the arrearages (mortgage) over a period of time, and consequently it reduces the risk of losing your house to the trustee. When considering Chapter 13, it is important to keep in mind that if your home loan is in default, you are going to need to pay larger mortgage payments (that is, the payments that you missed in addition to resuming your original payments.)
It should be noted that filing for Chapter 7 does not permanently end the right of the lender to foreclose; the relief or “stay” is only until the lender receives permission from the court to proceed, which is the result of filing and receiving a “relief from the automatic stay.” The court will probably grant this, unless you act quickly. You must be able to show that your account is current, that you are able (and likely) to make payments on time, and finally, that your home equity gives the lender enough of a “cushion,” that foreclosure is not necessary. Some jurisdictions additionally require the negotiation of an official “reaffirmation agreement” with the lender.
It should be perfectly clear that Chapter 7 cannot ever be more than a temporary stop to the foreclosure process, unless the creditor agrees AND the trustee is prohibited from selling the property by the homestead exemption laws of the state.