user5406: 
Could you please describe how the Lightning network is supposed to work? 
How does it scale better than pure blockchain transactions?  
What are the advantages and disadvantages of Lightning Network and blockchain transactions?


user83097: Lightning Network is a layer on the top of the Bitcoin Blockchain. Le'me go in more detail.
It is a technology that makes bitcoin work faster, scalable and improve bitcoin in such a way that Bitcoin could handle hundreds or thousands of transactions each second, right now Bitcoin handles about seven transactions per second which is very low compared to Visa and Mastercard who handles hundreds or thousands of transactions per second. Bitcoin lightning network is a proposal which can help in moving from seven transactions per second to hundreds or thousands transactions per second without having any central entity and without losing trust among nodes.
How Lightning Network Works ?
It works by you and me where we can send each other bitcoins on a channel that is off the blockchain so we establish a channel between each other on the blockchain, we start communicating with each other and sending transactions to each other off the blockchain. We can do hundreds or millions of such transactions without broadcasting it back to the blockchain. When we create this channel that is outside the blockchain, we can do any number of transactions without burdening the entire network.
So in their whitepaper who have proposed this idea also in which I can send a transaction to some other person without creating a direct connection to that other person. Le'me explain guys...
Suppose Me and my friend are sending transaction to each other off the blockchain so may be my friend connects to some other person X so in the lightning network, it is possible to send funds from me to person X via my friend. I dont need to have a direct connection to person X. It's really a good way to propagate funds through the network without establishing many direct connections which also could burden the whole lightning network.

This is comparable with how the internet works today When i send a packet, it can get routed through many different nodes and the nodes dont really care where the packet is coming from and where it's going, they only care where they should send it next and so the next person may send it somewhere else and then it would finally arrived at final destination. It's similar to how lightning network work if i have a connection to my friend and my friend has a connection to someone else. I could send funds from me to someone else via my friend, my friend wouldnot even know if the funds are intended to go to person X or if person X is supposed to send person Y. If the person X is recipient then transaction is finished and can be broadcasted to the original blockchain so in this way we can do millions of transactions among each other without burdening the entire network and this could really scale the Bitcoin network.
Can you trust that middle person ?
I want to send some funds from me to my friend Sachin and i want to send those funds to Sachin via middle person Shivam so I have a channel from me to Shivam and then Shivam has a channel to Sachin, now i want to send my funds to Sachin. How can i trust Shivam? May be Shivam takes my funds for himself and doesnot send anything to Sachin so this thing is handled cryptographically and transaction will be refunded back to me if Sachin doesnot recieve my transaction in a certain amount of time. 
Problems in Lightning Network ?
The worst thing that could happen to me in this lightning network is that some middle person who is unfaithful would hold my funds for a number of days and so after those days passes, I would get my funds refunded by the protocol of network.
Another problem with this network is that people could do many channels, they could open and close channels instantaneously for burdening the network. In order to open a channel, we need to broadcast this information to the main blockchain and so if some malicious person tries to open and close the hundreds of channels a second, this could really burden the blockchain. They are working in it.

user4764: Lightning allows you to lock coins between two wallets, and then send special transactions between each wallet which only become "real" when they are added to the blockchain. But you don't do that, because on-chain costs you more fees, so you keep updating the transactions between each other.
Lightning not only makes it possible to send transactions off-chain from A to B, but also from A to B to C etc. Which would make it possible to create one big network, where most transactions happen off chain, you don't need to trust anyone and where all transactions are instantaneous.

user5406: Say, you and I want to open a payment channel.
1) Putting funds into Lightning
We both send 0.05 BTC into a shared 2-of-2 multisig address. This requires a transaction on the Bitcoin blockchain.
As a "balance sheet", we each create a 2-of-2 multisig transaction that pays out 0.05 BTC to you and 0.05 BTC to me. I sign one payout transaction and give it to you. If you want to put it in effect, you need only add your own signature and broadcast it to the Bitcoin network. Vice versa, you give me your copy of the payout transaction that you have signed and I have not yet. 
These "balance sheets" are regular 2-of-2 multisig transactions in the Bitcoin network, they're just not valid yet, because they are each missing one signature. Note that these unilateral payout transactions lock the paid out funds of the executing party for some time.
2) Payment
Now, I want to pay you 0.01 BTC. We each create a new payout transaction ("balance sheet") as before, but this one says that you get 0.06 BTC and I get 0.04 BTC. Each of us gets a transaction signed by the other to that effect as before.
To make sure that neither of us can use the old payout transaction the other signed previously, we each create an "anti-cheat" transaction: It's a transaction that spends the outputs from our first payout transaction to the other.  
I.e. when I try to activate the (now obsolete) 0.05 - 0.05 BTC balance sheet, my paid-out funds are locked for a number of blocks. This gives you time to broadcast the "anti-cheat" transaction in which I signed that my 0.05 BTC output gets send to you. 
Still, it's safe for me to give that transaction to you, and the whole network, because the "anti-cheat" can only be activated as a response to the fraudulent use of an old balance sheet. By the way, this anti-cheat mechanism is why Lightning needs the Transaction Malleability fix from Segregated Witness.
With the setup as described above, I'd have to be online to catch you trying to cheat, but obviously it wouldn't be safe for me to keep payment channels open if I had to remain online all the time. So, to encourage others to help with the "anti-cheat" transaction, we set a small portion of the "anti-cheat" payout as a bounty that anyone can spend. Now, we can entrust the anti-cheat transaction to all nodes on the network, so everyone can watch for old balance-sheets being broadcast. When it happens, anyone can sign the bounty to themselves and broadcast the "anti-cheat".
3) Network payment
Alright, now you and I can send money back and forth thousands of times, with almost instant effect (depending only on how fast we can communicate with each other) without adding a single transaction to the Bitcoin blockchain. Yet, on the other hand, if one of us ever tried to defraud the other, they would be instantly taken to court by having the dispute resolved on the blockchain to their own detriment. Pretty spiffy, but not terribly useful yet.
By the theory of six degrees of separation, everyone is connected to any other participant by only a few hops. 
Let's say you want to send money to Bob, who is a barista and just made you some coffee. Bob is a friend of Alice, while I have a Payment channel with Alice. For illustration purposes, let's assume that each payment channel has two BTC in it, split equally. You do not have a direct connection to Bob.
Our "network" now looks like this:  
   You <-- 1BTC ----- 1BTC --> Me <-- 1BTC ----- 1BTC --> Alice  <-- 1BTC ----- 1BTC --> Bob

Now, since you don't have a direct payment channel to Bob (and it would be very inefficient if you had to create a payment channel with every business partner you ever meet), you route your payment through the network. Instead of only writing an update of the balance between Bob and you as I described above, this becomes a concerted effort: Your wallet finds a route from you to Bob that has a) sufficient liquidity, b) least fees, and c) fewest hops. To make a payment, each involved payment channel updates its balances. With a payment of 0.01 BTC for the coffee, this updates our network to:
   You <-- 0.99BTC ----- 1.01BTC --> Me <-- 0.99BTC ----- 1.01BTC --> Alice  <-- 0.99BTC ----- 1.01BTC --> Bob

As you can see, the balances at the ends have shifted appropriately from you to Bob, but the other participants have the same balance (although shifted to other payment channels). It's important to realize, that the transaction can only go through completely or not at all. Either we all update the balances, or no one does.
Now, imagine that you don't have only the one payment channel with me, but you have maybe a dozen payment channels with other users! :)
4) Consensual channel closing
Other than in the above case where one side closes the channel unilaterally, one of us can request the other to consensually close a channel. When we agree, we create a final payout transaction together that doesn't lock any funds and allows immediate spending after confirmation. We could even use this transaction to spend some of our balance directly to a third party on the blockchain, or to create another different payment channel.
5) Trade-offs 

You cannot receive more money through Lightning in one transaction than the sum of your payment channels' values.
Your transactions don't get stored on the blockchain for eternity, (i.e. better payment privacy), but on the other hand you keep using the same address allowing users that know who the address belongs to to monitor your balance (less personal privacy).
Instant transactions! But your money is locked up in a payment channel, which you first need to execute on the blockchain if you want to do a regular Bitcoin transaction with the money.
Less fees! Transactions on Lightning don't require a full blockchain transaction fee, but if you route through others' payment channels, they might want something for the liquidity they provide to you. However, as other Lightning nodes are competing to transfer your payment for you, this is likely to be much lower than a full transaction fee on the blockchain.


Further reading:  

How is a node in the middle prohibited from keeping the money in a routed Payment in Lightning network? 
What are the trade-offs between transacting on LN and Bitcoin mainchain? 
How are paths found in Lightning Network?


5406: <ul>
<li>Could you please describe how the Lightning network is supposed to work? </li>
<li>How does it scale better than pure blockchain transactions?  </li>
<li>What are the advantages and disadvantages of Lightning Network and blockchain transactions?</li>
</ul>
 83097: <p>Lightning Network is a layer on the top of the Bitcoin Blockchain. Le'me go in more detail.</p>

<p>It is a technology that makes bitcoin work faster, scalable and improve bitcoin in such a way that Bitcoin could handle hundreds or thousands of transactions each second, right now Bitcoin handles about seven transactions per second which is very low compared to Visa and Mastercard who handles hundreds or thousands of transactions per second. Bitcoin lightning network is a proposal which can help in moving from seven transactions per second to hundreds or thousands transactions per second without having any central entity and without losing trust among nodes.</p>

<p><strong>How Lightning Network Works ?</strong></p>

<p>It works by you and me where we can send each other bitcoins on a channel that is off the blockchain so we establish a channel between each other on the blockchain, we start communicating with each other and sending transactions to each other off the blockchain. We can do hundreds or millions of such transactions without broadcasting it back to the blockchain. When we create this channel that is outside the blockchain, we can do any number of transactions without burdening the entire network.</p>

<p>So in their whitepaper who have proposed this idea also in which I can send a transaction to some other person without creating a direct connection to that other person. Le'me explain guys...</p>

<p>Suppose Me and my friend are sending transaction to each other off the blockchain so may be my friend connects to some other person X so in the lightning network, it is possible to send funds from me to person X via my friend. I dont need to have a direct connection to person X. It's really a good way to propagate funds through the network without establishing many direct connections which also could burden the whole lightning network.
<a href="https://i.stack.imgur.com/wOP63.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/wOP63.jpg" alt="enter image description here"></a></p>

<p>This is comparable with how the internet works today When i send a packet, it can get routed through many different nodes and the nodes dont really care where the packet is coming from and where it's going, they only care where they should send it next and so the next person may send it somewhere else and then it would finally arrived at final destination. It's similar to how lightning network work if i have a connection to my friend and my friend has a connection to someone else. I could send funds from me to someone else via my friend, my friend wouldnot even know if the funds are intended to go to person X or if person X is supposed to send person Y. If the person X is recipient then transaction is finished and can be broadcasted to the original blockchain so in this way we can do millions of transactions among each other without burdening the entire network and this could really scale the Bitcoin network.</p>

<p><strong>Can you trust that middle person ?</strong></p>

<p>I want to send some funds from me to my friend Sachin and i want to send those funds to Sachin via middle person Shivam so I have a channel from me to Shivam and then Shivam has a channel to Sachin, now i want to send my funds to Sachin. How can i trust Shivam? May be Shivam takes my funds for himself and doesnot send anything to Sachin so this thing is handled cryptographically and transaction will be refunded back to me if Sachin doesnot recieve my transaction in a certain amount of time. </p>

<p><strong>Problems in Lightning Network ?</strong></p>

<p>The worst thing that could happen to me in this lightning network is that some middle person who is unfaithful would hold my funds for a number of days and so after those days passes, I would get my funds refunded by the protocol of network.
Another problem with this network is that people could do many channels, they could open and close channels instantaneously for burdening the network. In order to open a channel, we need to broadcast this information to the main blockchain and so if some malicious person tries to open and close the hundreds of channels a second, this could really burden the blockchain. They are working in it.</p>
 4764: <p>Lightning allows you to lock coins between two wallets, and then send special transactions between each wallet which only become "real" when they are added to the blockchain. But you don't do that, because on-chain costs you more fees, so you keep updating the transactions between each other.</p>

<p>Lightning not only makes it possible to send transactions off-chain from A to B, but also from A to B to C etc. Which would make it possible to create one big network, where most transactions happen off chain, you don't need to trust anyone and where all transactions are instantaneous.</p>
 5406: <p>Say, you and I want to open a payment channel.</p>

<p>1) <strong>Putting funds into Lightning</strong><br>
We both send 0.05 BTC into a shared 2-of-2 multisig address. This requires a transaction on the Bitcoin blockchain.<br>
As a "balance sheet", we each create a 2-of-2 multisig transaction that pays out 0.05 BTC to you and 0.05 BTC to me. I sign one payout transaction and give it to you. If you want to put it in effect, you need only add your own signature and broadcast it to the Bitcoin network. Vice versa, you give me your copy of the payout transaction that you have signed and I have not yet. </p>

<p>These "balance sheets" are regular 2-of-2 multisig transactions in the Bitcoin network, they're just not valid yet, because they are each missing one signature. Note that these unilateral payout transactions lock the paid out funds of the executing party for some time.</p>

<p>2) <strong>Payment</strong><br>
Now, I want to pay you 0.01 BTC. We each create a new payout transaction ("balance sheet") as before, but this one says that you get 0.06 BTC and I get 0.04 BTC. Each of us gets a transaction signed by the other to that effect as before.<br>
To make sure that neither of us can use the old payout transaction the other signed previously, we each create an "anti-cheat" transaction: It's a transaction that spends the outputs from our first payout transaction to the other.  </p>

<p><em>I.e. when I try to activate the (now obsolete) 0.05 - 0.05 BTC balance sheet, my paid-out funds are locked for a number of blocks. This gives you time to broadcast the "anti-cheat" transaction in which I signed that my 0.05 BTC output gets send to you.</em> </p>

<p>Still, it's safe for me to give that transaction to you, and the whole network, because the "anti-cheat" can only be activated as a response to the fraudulent use of an old balance sheet. By the way, this anti-cheat mechanism is why Lightning needs the Transaction Malleability fix from Segregated Witness.<br>
With the setup as described above, I'd have to be online to catch you trying to cheat, but obviously it wouldn't be safe for me to keep payment channels open if I had to remain online all the time. So, to encourage others to help with the "anti-cheat" transaction, we set a small portion of the "anti-cheat" payout as a bounty that anyone can spend. Now, we can entrust the anti-cheat transaction to all nodes on the network, so everyone can watch for old balance-sheets being broadcast. When it happens, anyone can sign the bounty to themselves and broadcast the "anti-cheat".</p>

<p>3) <strong>Network payment</strong><br>
Alright, now you and I can send money back and forth thousands of times, with almost instant effect (depending only on how fast we can communicate with each other) without adding a single transaction to the Bitcoin blockchain. Yet, on the other hand, if one of us ever tried to defraud the other, they would be instantly taken to court by having the dispute resolved on the blockchain to their own detriment. Pretty spiffy, but not terribly useful yet.<br>
By the theory of <a href="https://en.wikipedia.org/wiki/Six_degrees_of_separation" rel="noreferrer">six degrees of separation</a>, everyone is connected to any other participant by only a few hops. 
Let's say you want to send money to Bob, who is a barista and just made you some coffee. Bob is a friend of Alice, while I have a Payment channel with Alice. For illustration purposes, let's assume that each payment channel has two BTC in it, split equally. You do not have a direct connection to Bob.</p>

<p>Our "network" now looks like this:  </p>

<pre><code>   You &lt;-- 1BTC ----- 1BTC --&gt; Me &lt;-- 1BTC ----- 1BTC --&gt; Alice  &lt;-- 1BTC ----- 1BTC --&gt; Bob
</code></pre>

<p>Now, since you don't have a direct payment channel to Bob (and it would be very inefficient if you had to create a payment channel with every business partner you ever meet), you route your payment through the network. Instead of only writing an update of the balance between Bob and you as I described above, this becomes a concerted effort: Your wallet finds a route from you to Bob that has a) sufficient liquidity, b) least fees, and c) fewest hops. To make a payment, each involved payment channel updates its balances. With a payment of 0.01 BTC for the coffee, this updates our network to:</p>

<pre><code>   You &lt;-- 0.99BTC ----- 1.01BTC --&gt; Me &lt;-- 0.99BTC ----- 1.01BTC --&gt; Alice  &lt;-- 0.99BTC ----- 1.01BTC --&gt; Bob
</code></pre>

<p>As you can see, the balances at the ends have shifted appropriately from you to Bob, but the other participants have the same balance (although shifted to other payment channels). It's important to realize, that the transaction can only <a href="https://bitcoin.stackexchange.com/q/43184/5406">go through completely or not at all</a>. Either we all update the balances, or no one does.</p>

<p>Now, imagine that you don't have only the one payment channel with me, but you have maybe a dozen payment channels with other users! :)</p>

<p>4) <strong>Consensual channel closing</strong><br>
Other than in the above case where one side closes the channel unilaterally, one of us can request the other to consensually close a channel. When we agree, we create a final payout transaction together that doesn't lock any funds and allows immediate spending after confirmation. We could even use this transaction to spend some of our balance directly to a third party on the blockchain, or to create another different payment channel.</p>

<p>5) <strong>Trade-offs</strong>   </p>

<ul>
<li>You cannot receive more money through Lightning in one transaction than the sum of your payment channels' values.</li>
<li>Your transactions don't get stored on the blockchain for eternity, (i.e. better payment privacy), but on the other hand you keep using the same address allowing users that know who the address belongs to to monitor your balance (less personal privacy).</li>
<li>Instant transactions! But your money is locked up in a payment channel, which you first need to execute on the blockchain if you want to do a regular Bitcoin transaction with the money.</li>
<li>Less fees! Transactions on Lightning don't require a full blockchain transaction fee, but if you route through others' payment channels, they might want something for the liquidity they provide to you. However, as other Lightning nodes are competing to transfer your payment for you, this is likely to be much lower than a full transaction fee on the blockchain.</li>
</ul>

<hr>

<p>Further reading:  </p>

<ul>
<li><a href="https://bitcoin.stackexchange.com/q/43184/5406">How is a node in the middle prohibited from keeping the money in a routed Payment in Lightning network?</a>  </li>
<li><a href="https://bitcoin.stackexchange.com/q/42639/5406">What are the trade-offs between transacting on LN and Bitcoin mainchain?</a>  </li>
<li><a href="https://bitcoin.stackexchange.com/q/43687/5406">How are paths found in Lightning Network?</a></li>
</ul>
