a LOT of misinformation is being spread in this thread... Here's my effort to give a newbie-friendly explanation of most of the topics discussed so far.
A word of caution: i tried to be newbie-friendly, so i "dumbed down" several facts. So, read my post and take it as a starting point in your jouney to learn about bitcoin mining.
In order to send and receive bitcoin, you have to create transactions. A transaction is basically a signed piece of text that says:
i'm the owner of the private key that is controlling unspent output X. I want to create a new transaction with as an input unspent output X and Y as an output. Y can be spent by the owner of addres Z
It's a little bit more complex than that, but basically, this is a transaction.
A transaction has a certain size (in bytes) and is broadcasted around the network. At this point, the transaction is just stored in the memory of the nodes. After a couple of days, or when the node reboots, the unconfirmed transaction is lost. If most of the nodes forget about your transaction, it's like it never happens.
This is why miners collect unconfirmed transactions and put them into a block. A block used to contain up to 1Mb of transactions. At this moment, there's something called segwit that moves part of the transaction into a different part of the block, resulting in more transactions fitting into a block (but that's a complex, different topic). Every transaction pays a fee (the difference between the inputs and the outputs). A miner is allowed to add one transaction whose outputs can be spent by an address of his choice, and fund this address with 12.5 BTC + the sum of all fees of the transactions in said block.
The block that exists in the miner's memory is not automatically valid. If a miner could just fill blocks with transactions and broadcast them to the network right away, anybody could create a blockchain of infinite length in a short amount of time, and there would be chaos.
The design of bitcoin is aimed at producing one block every ~10 minutes. To do this, a block is only valid if the header of the block created by the miner, ran to a sha256 function twice has a value smaller than the current target. The header is made up from the previous block hash (making sure we get a block
chain), a nonce (= random data, to be chosen by the miner), the merkle tree of all transactions in the block and some other data. By varying the nonce, the miner can create an infinite amount of valid headers. The sha256d hash of these headers allways gives a new result. So, given infinite time, a miner could generate infinite sha256d hashes that are still valid for the same transactionset.
The difficulty is adjusted every 2016 blocks. When a lot of miners start creating hashes, the odds of them finding a headers whose sha256d hash is smaller than the current target increases, and so does the time between 2 blocks. After 2016 blocks, however, the network adapts the difficulty so the avg time between blocks is once again ~10 minutes.
So... Mining is creating a "block", fill it as much as possible within the given limits, maximising the amount of fees (so, maximising his profits). The next step is to generate a block header using information like the previous block hash and the merkle tree of all transactions in the block. The next step is to iterate trough nonces, each time solving sha256(sha256(header)) untill the result of said function is lower than the target.
If the miner is the first one to find a hash, he can broadcast the block to the network, thus seeing his mining address funded with 12.5 BTC + fees.
Now, after this theory, i can explain the difference between solo mining, pool mining and cloud mining:
solo mining: you use your own mining node to create a block, funding your own mining address, then use your own ASIC to try to solve the header of your own block. If you solve the block, you get the full reward. If you don't solve the block, you get nothing.
pool mining:Since the diff is so high, it's very hard to have enough ASIC's to try to solo mine bitcoin. This is why miners decided to pool together their hashrate. A central instance (the mining pool) generates a block, with the coinbase reward going to the pool owner. The pool sends the header to all miners. Then all pool members try to find a nonce that results in the hash of the header being below the target. If one member solves the block, the reward is later on divided amongst the pool members on a share based system (the bigger your hashrate, the bigger your share)
cloud mining:Some companies buy ASIC's, but don't want to carry the risk of mining (broken hardware, price fluctuations,...), so they sell 100% of their risk for part of their profit. Also, 99% of the "cloud mining" companies are actually ponzi's disguised as a mining company
To find out more information about the difficulty and the target :
https://en.bitcoin.it/wiki/DifficultyTo find out more information about mining:
https://en.bitcoin.it/wiki/Mining