“A blockchain is a growing list of records, called blocks, that are linked using cryptography. Each block contains cryptographic hash of the previous block, a timestamp, and transaction data(generally represented as a merkle tree).”
~ wikipedia
To visualize blockchain technology, it is a chain of blocks where each block contains a group of data that has been collected at the same timestamp. Those blocks are related to one another in a way that a block will have an address of its previous block. In a nutshell, the diagram below will demonstrate the theoretical concept of how block chain works.

Fig.01
The hashes generated by SHA256 are hexadecimal numbers(base 16) and each hexadecimal number will have 4 bits. There must be 256 bits in the hash generated by SHA256 algorithm and in the block hash, there will be 64 hexadecimal digits in SHA256 hashes. That is 256/4 = 64. Hashing Demo

Finally this is the network target with 19 leading zeros as of now that is set in the bitcoin network.

In fig.01 all the blocks are linked to one another, each having a unique address of the previous block. Each data in a block is encrypted using SHA256(Secure Hashing Algorithm where 256 is the number of bits) and final hash is a hash of those hashes generated using SHA256(term used for that hashing is called merkle tree and hash of a block is a merkle tree root).
How SHA256 works?
The encryption has a popular story during the time of general Julius Caesar, where he found an encryption technique called Caesar cipher in which letters were written in plaintext which cannot be understood by his enemy but only his trusted ones can replace by a letter some number of positions down the alphabet. For example, with a right shift 5, A would be replaced by E and that is how they decoded the letter at receiver end. The encryption techniques have developed over the years and SHA256 is so far a one way encryption algorithm. Any information that is encrypted using this algorithm cannot be decrypted.
The hashes generated by SHA256 are hexadecimal numbers(base 16) and each hexadecimal number will have 4 bits. There must be 256 bits in the hash generated by SHA256 algorithm and in the block hash, there will be 64 hexadecimal digits in SHA256 hashes. That is 256/4 = 64. Hashing Demo
Why blockchain?
The very purpose of blockchain is to get rid of intermediaries like banks and involving any other witnesses that are centralised. For example if we are sending money via apps developed by banks and if their server gets crashed then the transaction history and your balance will not be there. Marke Gates states “Even in the United states, which has one of the most developed and regulated financial systems in the world, major financial institutions failed during the Great Financial Crisis. Financial companies that had existed for hundreds of years collapsed overnight taking people’s saving with them.” Sometimes we cannot say how safe our savings are with the bank.
Another example can be land transactions, it requires a witness agency where the transaction becomes expensive and time consuming. Moreover, if that agency loses your transaction details and later if someone claims that it's their property, then the owner of that property becomes anonymous.
Blockchain addresses those issues as the ledger that maintains the transactions is immutable because if someone tries to manipulate a block that contains your transaction, then all the successive blocks become invalid. How?
Distributed P2P network
Even if the hacker is successful in that way, he is being successful only in one machine. In the blockchain network there are countless nodes and miners who have the copy of the previous blockchain. The copy of blockchain is distributed amongst the peers in a network and is updated each time a new block is added. As and when the hacker releases his hacked blockchain, it is being compared with other nodes in the blockchain and replaced with the blockchain that the majority of the nodes have . For a hacker to be successful he must hack more than 50% of machines through consensus protocol which is practically impossible by a hacker. That makes blockchain a dynamic and secure web application.
“Blockchain technology has the ability to optimize the global infrastructure to deal with global issues in this space much more efficiently than current systems.” -Marwan Forzley, Founder of Align Commerce.
How mining works?
There have been a set of valued people who argue with the perception of earning through hardship is more important than earning through lesser effort. Those are the values that are taught in those times and are still realizable in some sphere of life but with the technology emerging with the speed of light has apparently changed the angle of earning. One of the most popular and valued mining in the bitcoin network has given the world another chance to think, adapt, explore the smarter ways of earning.
The term mining in blockchain technology is a computational puzzle solved to add a new block in a blockchain and each time a node solved that puzzle gets a reward in the form of cryptocurrency. All the mining computers connected in the blockchain network share their computational powers and make the blockchain technology much more than supercomputers. In the bitcoin network, it is roughly 256 times faster than all the top 500 supercomputers around the globe combined(during the time of writing this paper) and it is expected to become more powerful.
The specific task performed in mining is finding the number called Nonce(number only used once). What is so difficult in finding a number? The difficulty of getting a number is maintained by setting a network target to ensure the newly mined block is valid to add in a blockchain.
For example in a dice, if the target is set below 4 then there are 4 in 6 chances of getting a number below 4 but if the target is set to 2 then there is only 1 in 6 chances of getting a number below 2. That is how the difficulty in finding nonce is maintained.
A programmed hardware for guessing a number that qualifies the network target is used and actually mining refers to finding numbers that qualifies network target to add a valid block on a blockchain.
Understanding mining difficulty
Image below shows details of a block in a bitcoin network and we will calculate the target of the network as on 15th Jan 2021, and try to understand how difficult it is to mined a block. There is information given on each of the blocks on https://www.blockchain.com. The block does not disclose the exact target with hexadecimal number but it shows in decimal number of bits.
Target determination of a bitcoin
Given bits : 386,771,105
Corresponding Hexadecimal bits: 170DA8A1 Convert decimal to hexadecimal
Let's take first 2 digits and convert to decimal back: 17 (Last six digits used later)
Hexadecimal to Decimal Conversion = (1*16^1)+(7*16^0) How?
= 23 (Which is number of bytes)
23 bytes = 23 * 8 bits (1 byte = 8 bits)
Each hexadecimal number has 4 bits= 23 * 2 * 4 bits
= 23 * 2 hexadecimal numbers
= 46 hex digits
Now it says that we have 46 hex digits inclusive of the last 6 hex digits derived earlier(0DA8A1)and add 0s till 46th digit.
46 hex digits obtained: 0DA8A10000000000000000000000000000000000000000
As blockchains use SHA256 cryptography function, there must be 64 hex digits as discussed earlier. So, 64 - 46 = 18 and append 18 zeros before 46 hex digits:
0000000000000000000DA8A10000000000000000000000000000000000000000
In a bitcoin network, each block has a block hash of 64 hexadecimal numbers and the network target is delimited by the number of zeros in the hexadecimal hash in first digits. The more zeros in front of a hash, the more is the difficulty of finding a nonce.
As all the blocks are encrypted using a hash function and each block is cryptographically linked to one another, the slight change in data in a block will generate a completely different hash. And the immediate successive block has a hash of the previous block which is now different then the blocks after that becomes invalid. To correct the blocks after the tempered block, then the blocks must be mined again.
B. Mining Difficulty calculation
Current target: 0000000000000000000DA8A10000000000000000000000000000000000000000
Total possible 64 digits hex number is : 16^64 = 1.15 * 10^77 = 10^77 (approx.)
Total valid hashes with 19 leading zero: 16^(64-19) = 1.53 *10^54 = 2 * 10^54 (Approx.)
Probability that a randomly picked hash is valid = (2*10^54)/10^77
= 2 * 10^-23
= 0.00000000000000000000002%
In bitcoin network, a new valid block is added after every 10 minutes and the difficulty level is adjusted after every 2016 blocks i.e every after two weeks. So the chance of getting a valid hash is very less and it needs high computational power to get a nonce that generates a hash qualifying network target.
Since the bitcoin blockchain gained popularity only in 2016 with increasing numbers of miners and nodes, there is a rise in difficulty level for solving the puzzle because if 10 miners can easily mine a block in 10 minutes then, 20 users will solve it more quickly. Therefore, the difficulty is maintained to keep the same pace of adding a block.