How much gas for transaction

How do I know how much the network fee should be for a transaction? I am currently guessing, and sometimes I get an error “out of gas”.