When is there deficiency or excess after foreclosure sale?

The Supreme Court has already ruled in several cases[1] that in extrajudicial foreclosure of mortgage, where the proceeds of the sale are insufficient to pay the debt, the mortgagee has the right to recover the deficiency from the debtor.[2] In ascertaining the deficit amount, Sec. 4, Rule 68 of the Rules of Court is elucidating, to wit:
Section 4. Disposition of proceeds of sale. — The amount realized from the foreclosure sale of the mortgaged property shall, after deducting the costs of the sale, be paid to the person foreclosing the mortgage, and when there shall be any balance or residue, after paying off the mortgage debt due, the same shall be paid to junior encumbrancers in the order of their priority, to be ascertained by the court, or if there be no such encumbrancers or there be a balance or residue after payment to them, then to the mortgagor or his duly authorized agent, or to the person entitled to it. (Emphasis added)
Verily, there can only be a deficit when the proceeds of the sale is not sufficient to cover (1) the costs of foreclosure proceedings; and (2) the amount due to the creditor, inclusive of interests and penalties, if any, at the time of foreclosure.

[1] See DBP v. Tomeldan, G.R. No. 51269, November 17, 1980, 101 SCRA 171; Development Bank of the Philippines v. Zaragoza, No. L-23493, August 23, 1978, 84 SCRA 668; Development Bank of the Philippines v. Murang, No. L-29130, August 8, 1975, 66 SCRA 141; Development Bank of the Philippines v. Vela, de Moll, No. L-25802, January 31, 1972, 43 SCRA 82; Philippine Bank of Commerce v. De Vera, No. L-18816, December 29, 1962, 6 SCRA 1026.

[2] Prudential Bank v. Martinez, No. L-51768, September 14, 1990, 189 SCRA 612.