Every node in the network has a
mempool contains unconfirmed transactions. Each
mempool may be slightly different as they constitute a subset of all unconfirmed transactions in the network: Some might not have been relayed to a node, so he doesn't know about them, the node owner has set a higher
minTxRelayFee and filtered out some transactions with low fee, or the node owner has set a smaller data limit for his
Anyway, all of the above is also true for any miner's node. When miners are trying to find a block, they select a set of transactions to confirm from their
mempool. From these transactions, they build a Merkle tree.
The Merkle tree allows the whole transaction data to be represented by only the Merkle root. This Merkle root is part of the block header.
Miners get to choose which transactions to include freely, and they can also put them in any order they want, as long as the transactions are valid. Since there are now often more transactions available for confirmation than block space, miners usually select transactions that maximize the fees that the miner can earn.
So, miners have selected some transactions and created a Merkle tree to contain them. They combine this with the other parts of the block header: Time-stamp, Reference to previous block, difficulty statement, and the
nonce is an arbitrary number, so miners can build a block candidate with all the other data and then try this candidate a lot of times by cycling through all possible values for the nonce.
Every try they put the block header into the hashing algorithm and receive a digest or hash of the data. If this hash satisfies the difficulty statement, the miner has found a new block and will relay it to the network.