Mining in physical world is extraction of valuable minerals from earth. If we apply same analogy to cryptocurrency world, mining is process of generating new coins in the system.
How mining works in cryptocurrency world
Most cryptocurrencies use blockchain technology to maintain tamper proof timestamped publicly shared ledger.
To decide next block in blockchain, miners competes with each other. Miners have to show that they have done some work to be eligible for deciding next block in blockchain, it is called proof of work mining.
Some times miners put their stakes instead of doing work, it is called proof of stake mining. In proof of stake mining, dishonest miners are penalised by confiscating their stakes. But, here we will discuss proof of work mining only.
Proof of Work Mining
Cryptocurrencies are basically p2p network, where each node runs same piece of software enforcing rules already set in consensus protocol.
Each node in network broadcasts transactions which it has listened, to all other connected nodes.
Mining uses same piece of software to listen broadcasted transactions, clubbing them in a block and creating a block header.
After block header is created, miners use a mining software which calculates a hash of block header according to hashing algorithm set in consensus rules.The hash of block header should be less than a predefined number (Target) set by network. If a miner finds this magical number before others, it broadcasts the block and other nodes in network verifies hash of block header being less than the target. If it is, miner that had broadcast correct block gets rewards(12.5 BTC in Bitcoin network) plus transaction fees of all transactions which were included in block.
The rewards are actually new coins generated by network to incentivise work done by miners.
Algorithm for finding Hash of block header determines which hardware to use.
Some mining algorithms are CPU intensive, for these algorithms ASIC miners are used. In Bitcoin, litecoin etc mining is done with ASIC hardware, while some mining algorithms involves memory computation also, so GPU is suitable these algorithms. In ethereum , zcash etc mining is done with GPU's.
Bitcoin mining guide at bitcoin.org