After the sale price, the mortgage payout is usually the biggest number in this calculation, and it isn't simply the balance on your last statement. The figure your lawyer or notary works from is the payout amount your lender quotes for your specific completion date. Ask your lender for a payout statement once you have a likely completion date, and update the calculator with it.
If your mortgage is closed and you sell before the term ends, plan for a prepayment penalty. The Financial Consumer Agency of Canada says it's usually the higher of three months' interest on what you still owe or the interest rate differential (IRD), and it names selling your home as one of the situations that triggers it. The IRD can apply when your mortgage rate is higher than the lender's current rate, so two sellers with the same balance can face very different penalties depending on when they signed and how rates have moved since. FCAC also lists other charges that can apply when you break a mortgage: administration fees, appraisal fees, reinvestment fees and a mortgage discharge fee. Ask your lender which apply to you, and get the total in writing.
If you're buying again, ask about porting. FCAC describes it as taking your existing interest rate, terms and conditions with you to the new home, and it's the first question I'd raise with your lender before we set completion dates on a sale and a purchase. Timing matters too: if your term ends soon, compare the penalty today with the cost of a later completion.
On completion day your lawyer or notary pays out the lender from the sale proceeds, makes sure the old mortgage is discharged from title, and delivers the balance to you. If any other loan is registered against your home's title, tell them early so it's included in the payout figures rather than discovered late.