Layer 2 refers to secondary blockchains built on top of a Layer 1 chain like Ethereum to improve scalability. Ethereum Layer 1 processes roughly 15 transactions per second. Layer 2 solutions process hundreds or thousands. They work by taking transactions off-chain, batching them, and then posting the batch to Layer 1. The security of the Layer 2 chain comes from Layer 1.
If there's a dispute about what happened on Layer 2, you can verify on Layer 1. Optimistic rollups assume transactions are valid unless proven otherwise. They process transactions quickly and cheaply. If someone challenges a transaction, they prove it was invalid on Layer 1. Zk-rollups use zero-knowledge proofs to prove validity without posting all transaction data on-chain.
Validiums post transaction data off-chain for privacy but are more centralized. Sidechains are independent blockchains that periodically sync with mainnet. Examples include Arbitrum, Optimism, Base, Polygon, and Starknet. Each has different tradeoffs. Some are more decentralized. Some are faster. Some are cheaper.
The unifying feature is that they're all trying to increase throughput while maintaining security guarantees. Layer 2 is essential for blockchain to scale beyond boutique use cases.