A longer term lowers the payment because repayment is spread over more months. It also keeps you in debt for longer. To choose, look at the payment you can afford and the total interest together.
An example with numbers
For $150,000 at a fixed 3% nominal rate with equal monthly payments, you would pay about $832 a month over 20 years and $632 over 30. With no fees, those ten extra years cut the payment by about $200 and add about $28,000 in interest.
Try it with your numbers
Simulate both terms with the same amount and rate. Compare the monthly difference with the extra cost over the whole loan.
Example figures for learning purposes. They are not a recommendation and do not replace professional advice.