The costs of the sale and the debt owed to the foreclosing mortgagee are paid first.
The mortgagee’s only interest in the property is to be fully repaid, however, so if any money is left over, the mortgagee doesn’t get to keep it.
The surplus is distributed to owners of junior interests in order of priority (which is generally the order in which the interests were created).
The sale extinguishes junior interests in the property, so these parties have a claim against the proceeds to compensate them for their loss.
Look at dummies dot com to read complete answer
The mortgagor gets to keep any money that’s left after paying the junior interests.