How does a Blockchain work

In order to understand the functioning of the Blockchain, it is vital we have a basic idea of what the Blockchain technology is all about and how is it different from the conventional client server model of record keeping, transactions, etc. I will suggest if you do not have the basic understanding of what Blockchain is, please refer to the detailed article on the Blockchain basics here:


At the very fundamental level, a Blockchain is the new revolutionary method of record keeping in which the records are immutable (cannot be changed), transparent (visible to all in the network) and added in a chronological order.
An analogy to explain it will be considering a system or network of computers (called nodes in the Blockchain industry Jargon) and each node having a copy of an excel file containing certain records (also called ledger). Now the algorithm of the network is such that, as soon as a new item or data is added to one of the copies of the excel, it gets automatically updated in all the copies of the excel with all other nodes of the network. The excel file here is analogous to the Blockchain which is a ledger and the whole network of computers represent the Blockchain network.

A Blockchain is a hierarchical chain of Blocks, each Block containing a number or records of different nodes/users in the Blockchain network. These Blocks are chained together using cryptographic functions. For more details please refer to my article on Blockchain basics.

How does the Blockchain work?

Consider any blockchain, the one supporting cryptocurrencies such as Bitcoin, Ethereum, Altcoins, etc. or blockchains supporting the healthcare, real estate, etc. it is all about devising a more efficient mechanism for record keeping in which data is immutable, transparent and doesn’t rely on one Central Authority (as it happens in a trust based model) for authenticity and safe keeping.

Frankly speaking, the Blockchain Technology is not an entirely new technology. In fact it is an amalgamation of conventional high performing technologies to produce the most efficient, secure and transparent way one can store records and perform transactions. In order to understand what is going inside, let us understand the technological components which make it the behemoth DISRUPTIVE TECHNOLOGY. These technologies or rather the Blockchain components are:

  1. Cryptographic Hash Function
  2. Asymmetric Cryptography for Identity Management
  3. Transaction using Cryptography
  4. Wallet
  5. Blocks
  6. Addition of Blocks in the Blockchain

1. Cryptographic Hash Function

A Cryptographic Hash function is an algorithm which can convert any input (of any length like file, text, image, etc.) into a unique output called ‘digest’ of alphanumeric string of the same length. For example let us see an example Hashing by using the popular Hashing algorithm called SHA-256.

Input TextSHA-256 Digest Value
Hello, World!0xdffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
Sample Hashing of an Input value using the SHA-256 algorithm

Cryptography has the below unique traits.

(i) Unique output. Hence no two different inputs can have the same digest or output value. This property is known as being Collision Resistant.
Hence, given two input values ‘x’ and ‘y’ it is computationally not practical to have Hash (x)=Hash (y).
(ii) Fixed length string of alphanumeric characters. For any two input values, come whatever be, a Hash function will always produce the same length of the Digest.For example the cryptographic hash function SHA-256 produces 64 character of alphanumeric digest for any input given to it.
(iii) Preimage Resistant. This means that it is computationally impractical to find out the input value of a given Hash Digest value.

This image has an empty alt attribute; its file name is 9cb81-hashing.png

Examples of Cryptographic Hash Functions are Secure Hash Algorithm (SHA-256) and Keccak

Usage of Cryptography in Blockchain

Cryptographic Hash function is employed to attain Ultra-Security in the Blockchain Network. The different applications of the Cryptographic Hash function in the Blockchain network (not limited to) are:
(i) Creating unique addresses of the Nodes/Users in the Blockchain network. Private Keys and Public Keys are derived which we will see later in the article.
(ii) Hashing (and hence securing) of the data in a Block (Blocks contain a number of Candidate Transactions in a Blockchain. Blocks are described below in the article).
(iii) Hashing (and hence securing) of the Block Header.

2. Identity Management: Asymmetric Key Cryptography

Blockchain uses Asymmetric Key Cryptography, in which each user has a pair of keys namely a Public Key and a Private Key. These two keys are connected to each other using Cryptography. The Public key is shared with other users in the network, though a Private key is kept confidential for accessing and owning the digital assets.
It can be understood by the analogy of the email that one uses. One has an email id for sending and receiving data with another person, and in order to login to his/her email he/she should have a password. Similarly one has the Public Key to send and receive digital assets with other users in the Blockchain, but in order to see those data held and own them one needs to have a Private Key.

Identity Management Analogy

Usage of Asymmetric Cryptography (Public and Private Keys) in a Blockchain

  1. A user Encrypts or Digitally Signs data using his Private Key and sends the encrypted data to another user in the Network. The Digital Signature using the Private Key assures that the user owns the data.
  2. The receiver Decrypts the data using his Public Key.
  3. The Public Key is also used to Derive an Address for a node or user in the Blockchain.
    This is done by attaching some value to the Public Key and Hashing it. The Address of a user is generally shorter than the Public Key.

    Note: One cannot afford to loose the Private Key as it can be used to access all your Digital Assets in the Blockchain Network.

3. Transaction

A transaction or a Candidate Transaction in a Blockchain Network is any data or digital asset (cryptocurrency in the case of a crypto Blockchain) which a user or a node in a Blockchain Network sends to another user in the network. A Transaction data will be made up of:
(i) Input data which is the data or digital asset to be transferred, Public Key of the sender, Digital Signature of the sender, reference to the source of the digital asset (providing provenance) – either the previous transaction where it was given to the sender, or for the case of new digital assets, the origin event. In the case of cryptocurrencies this means that value cannot be added or removed from existing digital assets. Instead, a single digital asset can be split into multiple new digital assets (each with lesser value) or multiple digital assets can be combined to form fewer new digital assets (with a correspondingly greater value). The splitting or joining of assets will be specified within the transaction output. The sender must also provide proof that they have access to the referenced inputs, generally by digitally signing the transaction – proving access to the private key.
(ii) Output data: The outputs are usually the accounts that will be the recipients of the digital assets along with how much digital asset they will receive. Each output specifies the number of digital assets to be transferred to the new owner(s), the identifier of the new owner(s), and a set of conditions the new owners must meet to spend that value. If the digital assets provided are more than required, the extra funds must be explicitly sent back to the sender (this is a mechanism to “make change”).

Please note that a Transaction in a Blockchain Network must be (a) Authenticated and (b) Validated.
The Validity of the Transaction ensures that the transaction meets the pre-formalized data formats or smart contract requirements specific to a Blockchain Network.
The Authenticity of the transaction ensures that the sender of the digital assets had access to those digital assets. The sender typically digitally sign the transaction using his Private Key, which can be verified at any time using the associated Public Key. This phenomena is called Asymmetric Key Cryptography.

4. Wallet for Private Key Storage

It is highly advisable to store your Private Key in a software that gives it ultra security rather than noting down the key in a piece of paper. These software to store your Private Key is called a Wallet. Examples of wallets you will find are Coinbase, Trezor, Electrum, Robinhood, Exodus.

5. Blocks

Let us understand this with an example. Suppose, Flipkart (that we use frequently for online purchases), is made up on Blockchain. Then for each of your purchase transactions through the Flipkart, the data will be stored in a Block of the Blockchain. In fact one Block of the Blockchain will have multiple purchase data of other buyers using the portal. A Block in a Blockchain normally contains up to 1 MB of digital data. Now the Block will normally contain your transaction data (purchased items, cost, time, date, etc.) and your identity (a Digital Signature assigned to you).
Normally in most of the Blockchains a Block will have a Block Header and Block Data. Please check the figure below which gives a detailed description about a Block in a Blockchain.

6. Addition of Blocks in the Blockchain Network

When we talk about a Centralized Network Model, such as Google, YouTube, Amazon, Instagram, etc. addition of data is governed by the Central authority. For example if you wish to add a video data in YouTube, it will be authenticated and added by the YouTube which is the Central Authority in this case.
In a Decentralized Model, there is no Central Authority for validation of the data. Then how does the data gets validated and authenticated, to be added in the Blockchain network. Let us see.

  1. A Node or User in the Blockchain Network sends digital assets (data) to another Node or group of Nodes. For example in a Bitcoin Blockchain the data can be Bitcoin which one person sends to another person in the Bitcoin Blockchain Network.
    Note: A Node or User can send this data using a mobile or desktop application or by using a Digital Wallet.
  2. The algorithm of the Blockchain checks for the validity and authenticity of the data. Validity is confirmed by checking whether the data is in the specified format of the network. Authenticity is confirmed by checking whether the data has been digitally signed by the sender using his Private Key.
    Note: Validation and Authentication of the data by the Blockchain algorithm does not ensure its addition to the Blockchain ledger(the distributed ledger).
  3. The validated and authenticated data waits in a Queue with other transaction data, until a Publishing Node creates a Block with all these individual transaction data.
    Note: In a Blockchain, we need Publishing Nodes to add a Block (which stores individual candidate transactions) to the network. The question arises why will a User or a Node like you and me will take this responsibility to publish or add Blocks in the Blockchain. The answer is because of financial benefits. For example, in the case of Bitcoin, a Publishing Node which is also called a Miner gets Bitcoins in return for publishing a Block in the Blockchain. But this is not an easy task. Multiple users compete with each other in order to add a Block in the Blockchain.
  4. As said multiple publishing nodes compete with each at the same time to add a Block in the Blockchain. But the question is who decides for which of the User will add his/her Block. Is there a Central Authority which decides this? The answer is NO! Blockchain uses Consensus Models in order to resolve the dispute among Users for the addition of the next Block in the Blockchain (for financial rewards). There are different Consensus Models such as the Proof of Work, Proof of Stake, Round Robin, Proof of Authority or Identity, etc. Each Blockchain coded and devised uses one of these Consensus models to decide who adds the next Block in the Blockchain. I will write a detailed article on the Consensus Models that are in use soon. The Bitcoin uses the Proof of Work Consensus Model in which each publishing node tries to solve a computationally intensive puzzle which requires much resources (Electricity and CPU power). The Node which solves the puzzle first is accepted as the Winner and adds the next Block in the Blockchain.
  5. Now once the Block is added all the users check for the validity and authenticity of the data in the Block, ensuring no unauthorized data is added to the Blockchain.

The figures below show how a Block is added to a Blockchain.

Hence now we have a comprehensive idea of how does a Blockchain work. We went through all the technological components of the Blockchain and saw how a Block which contains several individual candidate transactions (typically upto 1 MB) is added to the Blockchain.

Have a good day and keep reading:)

1 Comment

Leave a Reply