The bitcoin protocol itself works by having every transaction public, this is all stored in the blockchain. I send you a coin, and publicly announce this with a message signed with my private key. If I try to spend the same coin twice, then this is where the transaction confirmation chain kicks in (and why you need to wait for X number of confirmations). When you announce sending a coin to somebody else, I see the message, and additionally sign your transaction message with my private key and add it to the blockchain. The next person to see the transaction, will again sign on top of all the previous confirmations.
If I try to double spend a coin, then there will be two different sets of transaction history. The bitcoin client is configured to accept the transaction confirmation chain with the most number of signatures as valid, the other one is ignored. Additionally, clients in the network will only additionally sign the chain they believe is valid. Once you get more than a few signatures, its almost computationally impossible to fake a confirmation chain faster than the network, assuming you don't have 51%+ CPU dominance (which is the worry about cex.io going rogue).
The MtGox issue is that they wrote their own custom bitcoin software to deal with the running of a high transaction volume exchange. They where not waiting for transaction confirmations from the network to check their own internal transactions. Their software was buggy and suffered from an exploit using Transaction Malleability. See https://freedom-to-tinker.com/...
The best real world bank analogy, is if you where to go to a cashpoint ATM outside a bank, withdraw money from the system, then enter a special code into the ATM which makes it display an error message. You then go into the bank and show them the error message, and ask them to refund the ATM withdrawal from your account claiming the ATM never gave you any cash (but in truth you did get the cash). This process didn't create new cash out of thin air, in practice you just got the bank to give you free money.
Eventually the bank becomes bankrupt, and you discover that what you actually own is not cash but rather an IOU from the bank for cash, which the bank can't pay.