top of page

The Lightning Network

Lightning Network.png
What is the Lightning Network? 

The Lightning Network is a Layer-2 payment network built on top of Bitcoin that enables instant, low-cost transactions.

Instead of recording every payment on the Bitcoin blockchain, Lightning allows users to open payment channels and transact off-chain, settling only the final result on Bitcoin’s base layer. This allows for fast transaction speed and capacity with low fees while keeping Bitcoin secure and decentralised.

 

In short:
Bitcoin is for secure final settlement on the blockchain.
Lightning is for fast, everyday payments off-chain.

Why do we need the Lightning Network?

As stated in the previous chapter, the need for the Lightning Network comes from the fact that Bitcoin on its base layer cannot scale for worldwide small payments without giving up on its decentralised characteristic. 

Due to its small block size limit, Bitcoin can only scale to 7 to 20 transactions per second today. 

If we were to increase the block limit, the ability to have a full Bitcoin node for the average person will be annihilated rapidly as the data storage, bandwidth, and computing power required would increase drastically.

 

This doesn’t mean that Bitcoin can’t ever increase its block size, as the demand for base layer payment for final settlement grows, the block size may need to be increased accordingly. 

Using the blockchain for final settlement and transfer of money rather than everyday payment will allow it to grow slower, requiring people to upgrade the computer they use for a full node later, by then computing power, storage, and bandwidth will have followed the normal course of technology and become cheaper.

How does it work?

The Bitcoin Lightning Network lets users send payments off-chain through private payment channels. The parties involved open a payment channel by locking the funds into a shared multi-signature wallet; this is the only point where the blockchain is required at the start. The Lightning channel is effectively a “smart contract” using the Bitcoin base layer as the ultimate arbitrator.Within the channel, users can make unlimited amounts of payments back and forth instantly and cheaply by updating the channel’s balance with each signature without broadcasting anything to the blockchain. You don’t even need a direct channel with someone; Lightning routes payments across multiple channels using hashed time-locked contracts (HTLCs), allowing funds to move securely through the network without intermediaries taking custody. When either party wants to exit, the channel is closed, and the final balance is settled on-chain. Only the opening and closing transactions touch the Bitcoin blockchain.If one party tries to cheat by broadcasting a previous version of the channel state, the other can claim all the funds through the revocable transaction mechanism.

Let's start with a simple example for a channel between two people.

Bob and Alice want to open a Lightning channel to transact quickly and cheaply off-chain. To do so, they both have to lock some Bitcoin into a multi-signature wallet, a 2/2 where there are two possible signers and they both have to sign transactions to move the funds.

The Bitcoin Dive - Slides.053.png

For this example, Bob and Alice contributed 100 sats each.

The Bitcoin Dive - Slides.055.png

Bob wants to buy a pot of honey from Alice for 20 sats using their channel. To do so, all they have to do is update the transaction they both hold to reflect the payment.

Using each of their keys, they write and sign a new transaction, now sending 80 sats back to Bob (his 100 sats minus 20 for the pot of honey) and 120 sats back to Alice to reflect the payment of 20 sats made for the pot of honey. 

They can go back and forth, updating their “refund” transaction each time, without having to broadcast anything to the blockchain, making transactions very fast and cheap.

The Bitcoin Dive - Slides.056.png

If Bob and/or Alice want out, they just all have to broadcast their transaction to the blockchain.

The funds will then be sent to the address they originally provided, making it the second transaction on the blockchain while thousands of fast transactions could’ve happened off-chain for a fraction of the fee.

The Bitcoin Dive - Slides.057.png

This is the final settlement between Bob and Alice, closing their Lightning channel.

Lightning Network channels work by locking funds in a multi-signature wallet, where both parties continuously create and sign updated transactions that reflect the latest balance after each exchange, without broadcasting them to the blockchain.

 

Anyone can exit at any time by broadcasting the latest transaction to the blockchain. If one cheats, a script will allow the other party to claim all the funds from the channel, punishing the bad actor. Let's see how that works.

How does Lightning prevent bad behaviour? Simply by making it economically suicidal to cheat.

A system called the revocable transaction mechanism makes cheating very risky. 

It does that by adding a script to their original refund transaction that says if someone tries to cheat by broadcasting an older version of that transaction, the other party has a week (1008 blocks) to respond and take all the funds.

The Bitcoin Dive - Slides.059.png

Let’s say, hypothetically, that Bob is not an honest person and keeps the original transaction that sent 100 sats back to his address and decides to broadcast it to the blockchain...

The Bitcoin Dive - Slides.060.png

The transaction held a script to protect any party from this kind of cheat. As Alice became aware that Bob broadcasted the old transaction, she then broadcasted the most recent, updated version. 

Broadcasting a more recent version of their commitment transaction cancels Bob’s dishonest transaction and runs the original script within it.

The Bitcoin Dive - Slides.061.png

The script being activated, the entire channel’s funds will be sent to Alice, punishing Bob for being a bad actor.

How do you scale payments worldwide if you can only have a direct channel with someone?​
Let's see how Bob's friend Jack can send a payment to Alice without having a direct channel with her.

What if Bob happens to have a friend named Jack that wants to buy one of Alice’s pots of honey, but doesn’t have a direct channel with her?

The Bitcoin Dive - Slides.064.png

Well, since Bob and Alice have a channel together, Jack could send 20 sats to Bob as long as Bob agrees to send 20 sats to Alice.

The Bitcoin Dive - Slides.065.png

Jack is happy to pay 1 sats in fees for Bob’s time and effort, but he also wants to make sure that Bob sends the money to Alice. This is where HTLC comes in.

HTLC is a smart contract enforced by Bitcoin script rules. The Lightning Network uses it to route payments without having to rely on trust. 

It works by locking a payment between two conditions: 

 

  1. Hashlock: The receiver must reveal a secret S to unlock the funds for himself.

  2. Timelock: If the secret isn’t revealed before the deadline, the sender gets refunded.

 

This ensures that intermediaries can’t steal funds because they can only get paid if the final recipient reveals the secret to claim their payment.

​​In this example, we will show you how Bob's friend Jack, who doesn't have a direct channel with Alice, can still pay her using HTLC:

The Bitcoin Dive - Slides.066.png

First, Alice creates a secret S, and hashes it to create H(S). *(Learn about hashing in The Blockchain- SHA-256)

The Bitcoin Dive - Slides.067.png

She then sends the hash H(S) to Jack through a Lightning invoice. 

Jack holds onto it, as he will need it to prove that Bob paid Alice.

The Bitcoin Dive - Slides.068.png

Jack then creates an HTLC with Bob, which locks 21 sats that say: 

If Bob provides the secret S of H(S), he can claim the 21 sats. 

If he doesn’t provide it in time, the money goes back to Jack.

The Bitcoin Dive - Slides.069.png

Bob then sends another HTLC to Alice for 20 sats that says: 

If you reveal Secret S, you can claim 20 sats.

If you do not reveal it in time, Bob gets the 20 sats back.

The Bitcoin Dive - Slides.070.png

Since Alice wants to get paid, she reveals the secret S to Bob, which unlocks the 20 sats for herself.

The Bitcoin Dive - Slides.071.png

Bob, who now has the secret S, provides it to Jack. 

Jack has proof that Bob paid Alice by checking that when the secret S is hashed, it gives the original hash H(S) that Alice provided him through the invoice. 

Bob unlocks the 21 sats for himself through the HTCL he had with Jack.

The Bitcoin Dive - Slides.072.png

This is how Alice got paid by Jack without having a direct channel with him. 

Bob collected one sat of fee for facilitating the exchange, and Jack got proof that Alice got paid, without relying on trust.

This is a very simple version of how hashed time-locked contracts work on the Lightning Network by routing payments across multiple channels.

Conclusion
  • The Lightning Network is essential for Bitcoin to scale as a worldwide medium of exchange since the base layer cannot handle enough transactions per second, is too slow, and the fees are too high for small everyday payments. Using a layer 2 like the LN is required to keep the base layer decentralised. Lightning is for fast, everyday payments off-chain, while Bitcoin is for secure final settlement on the blockchain. 

  • Lightning Network channels work by locking funds in a multi-signature wallet, where both parties continuously create and sign updated transactions that reflect the latest balance after each exchange, without broadcasting them to the blockchain.

  • Anyone can exit at any time by broadcasting the latest transaction to the blockchain. If one cheats, a script will allow the other party to claim all the funds from the channel, punishing the bad actor.

  • A direct channel with someone isn’t required as Lightning can route payments across multiple channels using HTLC, allowing funds to move securely through the network.

If you want to learn more about Bitcoin, check out the Library for books, documentary, podcast or website for the rest of your journey!

bottom of page