Costs and fees for getting a mortgage can vary depending upon mortgage lender policies and certain of the choices you make when you get your loan. For planning purposes, you should figure on 2% to 4% of the loan amount as a working figure, but total out-of-pocket expenses for funding escrow accounts and buying needed insurance policies can push that figure higher.
If you're refinancing, you can finance those costs in a couple of different ways; HSH's refinance calculator can help you determine how best to pay those mortgage closing costs. Also, if you're refinancing, a good way to get a handle on what your new mortgage will cost is to review your existing loan's closing documents; for loans made before 2015, those costs would be listed on your HUD-1 Settlement Statement, and for loans made after 2015, on the Closing Disclosure.