There is a special function called a cryptographic hash. Basically it takes anything as input and produces a fixed-length output. For all intents and purposes here, you can basically treat the output as being random. Meaning you can’t predict what the output is going to be for any given input without simply trying.
For miners, the input is the block they want to add to the block chain, plus a magic number they get to come up with. They then combine the two and perform the cryptographic hash. What they’re looking for is for a output of the hash that has certain properties. For example, the hash (being a number) has 32 trailing zeros.
Since the output isn’t predictable it’s basically simply a matter of choosing random magic numbers (as part of the input), combining it with the block, hashing it, and seeing what you get out of it. It’s brute force and odds go to whoever is faster (can make more guesses in a certain amount of time).
Whoever produces the correct hash output first gets to add their block to the block chain. This block will have a special transaction that creates new cryptocurrency out of thin air and adds it to their wallet. Basically they get paid. Additionally, the block main contain special transactions from other users that give money to whoever adds that block to the block chain.