Subject. In the article, we calculate the period of a borrowing, in which the interest burden and monthly payments are minimal. Objectives. The aim is to create an algorithm to optimize the term of the mortgage loan, taking into account the amount of debt and interest rate of the loan. Methods. The study employs methods to analyze the formula of annuity payments of a mortgage loan, and to model the final optimization algorithm. Results. We developed an algorithm, to determine the optimal term of the loan, using the certain loan amount and interest rate. The study considers the case for banks, operating in Krasnoyarsk. Conclusions. The paper considers two parameters of a mortgage loan, i.e. the interest burden and the monthly payment, which is calculated, according to the annuity formula. Both parameters depend on the loan amount, the interest rate, and the period of the loan. However, the interest rate is set by the bank, so the only parameter that the borrower can change is the period of payment. By changing the term to maturity, it is possible to have a loan with minimum payments and interest burden. For the purpose of optimization, we consider both parameters simultaneously. Taking into account their versatile nature, we consider the optimal time, when payments and interest burden are minimized. The paper also reviews the case of optimization of credit parameters for construction enterprises of the Krasnoyarsk Krai, in various banks.