Mortgage calculators use this formula to calculate your monthly payment:
M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]


 Monthly Payment (M): The amount you owe each month.
 Principal (P): The balance of your loan.
 Interest (i): Your monthly interest rate, calculated by dividing your annual rate by 12.
 Term (n): The number of months in your loan term, calculated by multiplying your loan term in years by 12.

A mortgage calculator calculates the interest rate you pay each month, then that percentage rate is applied to your loan balance (which decreases each month as you make payments).
To see the best snapshot of how each monthly payment breaks down over time, you want to use an amortization calculator instead of a mortgage calculator. This calculator will also generate an amortization schedule of how your mortgage is paid off over its term.