When a transaction happen, the miners compute a value called "prof of work". This value is calculated in order to get a 0 value (or something very closed to 0) for the hash of the value + the transaction + the last pow.
The miner does not perform the PoW on each transaction individually, but on a set of transactions, whose combined size is less than approximately 1MB when serialized (There is a 1MB limit for non-SegWit parts and 4MB limit for the entire structure including SegWit parts).
The set of transactions is placed into a structure called a
block. The block has a header which contains, among other things, a timestamp, the
nonce, the hash of the previous block's header, and the merkle root of the set of transactions in this block. The actual representation of the transactions in the block structure is a simple serialized list.
Miners can choose which transactions they wish to include in a block and in what order. However, the usual method is to sort transactions by highest paying fee and select the first bunch of transactions which fit within the block size limit.
The merkle root is calculated by placing the transaction ids (the hash of the serialized transaction) into a binary tree where each parent's value is the hash of the concatenation of its two children's values. The value of the root of this tree is then placed into the block header, along with the other necessary information.
Proof-of-Work is then performed by taking a hash of this block header, and the proof of work is successful if the resulting hash is less than the value specified by the
target, which determines the difficulty. The target indicates how many leading zeroes the hash must have - the more leading zeroes, the smaller the possible range of hashes becomes, making it more difficult to produce a matching hash. This difficulty is adjusted according to a consensus algorithm which attempts to make blocks created on average every 10 minutes - using historical data from the past 2016 blocks and their timestamps.
The Proof-of-Work is essentially brute-forcing the double-SHA256 of the block header by using different value for the
nonce in the header until the resulting hash of the header is a value which is less than the target. The nonce can be randomly selected, but it is more sensible to simply cycle through all possible 32-bit integer values in order.
But i have read the miner discover new bitcoins too. Is it another form of mining ? I do not see the link between the POW calculation and the new bitcoins)
Each block must contain at least one transaction in its set, which must appear first in the list. This is known as the
coinbase transaction. Unlike other transactions, it has no UTXOs as inputs - but its virtual input is newly generated coins plus the aggregate of fees paid in all transactions in this block. Newly generated coins must be strictly less than or equal to
50 >> floor(block_height / 210000) bitcoin, which determines that the number of new bitcoins which may be generated is halved approximately every 4 years (210000 blocks).
The coinbase can also be used to include an extra nonce value because the
nonce in the regular block header is too small (32-bits), and its entire range can be exhausted by modern miners more quickly than new transactions are added to the block. Mining pools also usually insert their name into the coinbase transaction so it can be public knowledge.