Lightning network works through a concept called Atomic Multi-Path Payments:
https://bitcoinops.org/en/topics/atomic-multipath/These are effectively payment channels secured by multi-signature, they start on chain with a channel opening commitment:
https://docs.lightning.engineering/the-lightning-network/liquidity/manage-liquidity#channelsThis is the start of the on chain portion of lightning.
The off chain lightning network is enabled once these channels are established, re-balancing channels is an example of an off-chain task you can do with the established channels:
https://docs.lightning.engineering/the-lightning-network/liquidity/manage-liquidity#rebalancing-channelsOnce a user wants to settle the funds back on the main bitcoin chain they need to initiate a channel close:
https://docs.lightning.engineering/the-lightning-network/liquidity/manage-liquidity#closing-channelsThere are two options for this, a cooperative close:
In a cooperative close both nodes are signing a new commitment transaction and publishing it to the network. The on-chain funds created in such a transaction will become available for a new channel opening almost immediately. In such a case it is also possible to set the fee with the --conf_target or --sat_per_byte arguments and define which address the funds should be sent to via --delivery_addr (unless this was already specified at the channel opening).
And a force close:
When closing a channel unilaterally, known as a force close, the funds will be locked up for a period of time before they can be redeemed by the closer, while the other party can redeem their funds immediately. Unless an anchor channel was created, you are unable to change the transaction fee of the closing transaction. To force close a channel use the --force flag.
Both of these closes involve finalizing the state of the atomic multi signature script committed to by the members of the channel on chain.
(closing channel quotes are from
https://docs.lightning.engineering/the-lightning-network/liquidity/manage-liquidity#rebalancing-channels)