It starts with a lot of by guessing.
Materials + labor = cost + "just because"= total cost. Add the "j.b." to cover your butt.
You have to get an idea of what your competition is charging. Always ballpark it on the high side and if you have to put it writing, make sure that you include SUBJECT TO CHANGE. If you get the job always communicate to your customer and always keep them advised of any changes, deletions, and/or additions. They will gain your respect.