How many months to breakeven is the deciding factor. There are two ways to figure breakeven.
The savings from just the difference in loan rate. Say going from 4% to the current 3.25% on a 30 year. How long to recover the refi costs? Depends on the loan amount and costs but it's going to be maybe 50-60 months on ave.
Or, the savings from resetting the term to 360 months AND the lower interest rate which could lower the P+I payment substantially, thus reducing the breakeven to maybe 12-15 months depending on costs and loan amount.
In the second case, using the savings to increase the monthly payments would reduce the payout term possibly below what is was before refinancing. So this would be a bigger benefit of refinancing.