Buying (or selling) a futures contract means that you are entering into a contractual agreement to buy (or sell) the contracted commodity or financial instrument in the contracted amount (the contract size) at the price you have bought (or sold) the contract on the contract expire date (maturity date). It is important to understand that futures contracts are tradeable instruments, meaning that you are free to sell (or buy back) your contract at any time before the expiry date.
For example, if you buy 1 "lot" (1 contract) of a gold future on the Comex exchange for the contract month of December 2016, then you entering into a contract to buy 100 ounces (the contract size) of gold at the price at which you buy the contract - not the spot price on the day of expiry when the contract comes to maturity. The December 2016 gold futures contract has an expiry date of 28 December. You are free to trade this contract at any time before its expiry by selling it back to another market participant. If you sell the contract at a price higher than you have purchased it, then you will realise a profit of 100 times the difference between the price you bought the contract and the price you sold the contract, where 100 is the contract size of the gold contract. Similarly, if you sell the contract at a price lower than the price you have purchased it, then you will realise a loss. (Commissions paid will also effect your net profit or loss).
If you hold your contract until the expiry date and exercise your contract by taking (or making) delivery, then you are obliged to buy (or sell) 100 ounces of gold at the price at which you bought (or sold) the contract - not the current spot price.
So long as your contract is "open" (i.e., prior to the expiry date and so long as you own the contract) you are required to make a "good faith deposit" to show that you intend to honour your contractual obligations. This deposit is usually called "initial margin". Typically, the initial margin amount will be about 2% of the total contract value for the gold contract. So if you buy (or sell) one contract for 100 ounces of gold at, say, $1275 an ounce, then the total contract value will be $127,500 and your deposit requirement would be about $2,500. The initial margin is returned to you when you sell (or buy) back your futures contract, or when you exercise your contract on expiry.
In addition to initial margin, you will be required to maintain a second type of margin called "variation margin". The variation margin is the running profit or loss you are showing on your open contract. For the sake of simplicity, lets look only at the case where you have purchased a futures contract. If the futures price is higher than your contract (buy) price, then you are showing a profit on your current position and this profit (the variation margin) will be used to offset your initial margin requirement. Conversely, if the futures price has dropped below your contracted (buy) price, then you will be showing a loss on your open position and this loss (the variation margin) will be added to your initial margin and you will be called to put up more money in order to show good faith that you intend to honour your obligations.
Note that neither the initial margin nor the variation margin are accounting items. In other words, these are not postings that are debited or credited to the ledger in your trading account. So in some sense "you don't have to pay anything upfront", but you do need to put up a refundable deposit to show good faith.