Layer 2 is the scalability layer - the layer that aims to solve scalability in blockchains that are decentralized and secure, thus resolving the blockchain trilemma.
Layer 2s are typically sidechains or rollups. They increase the computational capacity of layer 1s, move heavy computations off-chain, and increase scalability.
Sidechains are independent blockchains built on top of layer 1 which can use their own consensus mechanisms and block requirements.
Rollups are solutions that batch transactions off-chain and then execute them as a single transaction on layer 1. There are optimistic and zero-proof rollups.
Optimistic rollups are so-called because they assume an “innocent until proven guilty”, or fraud-proof, approach to processing transactions.
The zero-knowledge proofs are a method by which one party can prove to another that a given statement is true, without giving any additional information or explanation on how it was verified.
Some examples of layer 2s: Polygon, Optimism, or Arbitrum.
Ethereum is working on combining sharding with layer 2s to enable secure scaling of the network.