Foreclosure is what happens when a homeowner fails to pay the mortgage.

More specifically, it’s a legal process by which the owner forfeits all rights to the property. If the owner can’t pay off the outstanding debt, or sell the property via short sale, the property then goes to a foreclosure auction. If the property doesn’t sell there, the lending institution takes possession of it.

To understand foreclosure, it helps to keep in mind that the word “homeowner” in this case is actually a misnomer. “Borrower” is a more apt term. That’s what a mortgage, or deed of trust, is: a loan agreement for the purchase price of the home, minus the down payment. This document puts a lien on the purchased property, making the loan a “secured loan.”

When a lender loans you money without any collateral (credit card debt, for instance), it can take you to court for failure to pay, but it can be very hard to collect money from you. Lenders often sell this sort of debt to outside collection agencies for pennies on the dollar and write off the loss. This is considered an “unsecured loan.”

A secured loan is different because, although the lender may take a loss on the loan if you default, it will recover a larger portion of the debt by seizing and selling your property.

So what happens in a foreclosure? The specifics can vary according to state law, but we can break it down into five stages.

Stage 1: Missed payments

It all starts when the homeowner — the borrower — fails to make timely mortgage payments. Usually, it’s because they can’t, due to hardships such as unemployment, divorce, death or medical challenges.

If you’re in this tough situation, it’s essential that you talk to your lender as soon as possible. There are several options to help keep you in your home. The foreclosure process costs the lender a lot of money, and they want to avoid it just as much as you do.

Sometimes, a borrower may intentionally stop paying the mortgage because the property might be underwater (in other words, the amount of the mortgage exceeds the value of the home) or because he’s tired of managing the property.

Whatever the reason, the bottom line is that the borrower can’t or won’t meet the terms of the loan.

Stage 2: Public notice

After three to six months of missed payments, the lender records a public notice with the County Recorder’s Office, indicating the borrower has defaulted on the mortgage. In some states, this is called a Notice of Default (NOD); in others, it’s a lis pendens — Latin for “suit pending.”

Depending on state law, the lender might be required to post the notice on the front door of the property. This official notice is intended to make borrowers aware they are in danger of losing all rights to the property and may be evicted from the premises. In other words, they’re in danger of foreclosure.

Stage 3: Pre-foreclosure

After receiving a NOD from the lender, the borrower enters a grace period known as pre-foreclosure. During this time — anywhere from 30 to 120 days, depending on local regulations — the borrower can work out an arrangement with the lender via a short sale or pay the outstanding amount owed.

If the borrower pays off the default during this phase, foreclosure ends and the borrower avoids home eviction and sale. If the default is not paid off, foreclosure continues.

Stage 4: Auction

If the default is not remedied by the prescribed deadline, the lender or its representative (referred to as the trustee) sets a date for the home to be sold at a foreclosure auction (sometimes referred to as a Trustee Sale). The Notice of Trustee’s Sale (NTS) is recorded with the County Recorder’s Office with notifications delivered to the borrower, posted on the property and printed in the newspaper. Auctions can be held on the steps of the county courthouse, in the trustee’s office, at a convention center across the country, and even at the property in foreclosure.

In many states, the borrower has the right of redemption (he can come up with the outstanding cash and stop the foreclosure process) up to the moment the home will be auctioned off.

At the auction, the home is sold to the highest bidder for cash payment. Because the pool of buyers who can afford to pay cash on the spot for a house is limited, many lenders make an agreement with the borrower (called a deed in lieu of foreclosure) to take the property back. Or, the bank buys it back at the auction.

Stage 5: Post-foreclosure

If a third party does not purchase the property at the foreclosure auction, the lender takes ownership of it and it becomes what is known as a bank-owned property or REO (real estate owned).

Bank-owned properties are sold in one of two ways. Most often, they are listed by a local real estate agent for sale on the open market. Zillow lists bank-owned properties for sale. Also, some lenders prefer to sell their bank-owned properties at a liquidation auction, often held in auction houses or at convention centers.