EVM stack
The stack is the EVM's main workspace — a last-in-first-out pile of values that opcodes push onto and pop off of as they compute. If memory and storage are the EVM's notepad and filing cabinet, the stack is the small patch of desk where the actual arithmetic happens. Every operation that does real work reads its inputs from the top of this pile and writes its result back to the top.
Two numbers define it precisely: the stack can hold at most 1,024 items, and every item is a 256-bit (32-byte) word. The 256-bit width is unusual and deliberate — it lets a single stack slot hold a Keccak-256 hash or an Ethereum address without splitting, which simplifies cryptographic code. Pushing onto a full 1,024-deep stack causes a stack-overflow exception that reverts the call; trying to pop from an empty stack is a stack-underflow that does the same.
Opcodes can only reach a limited window of the stack. DUP1–DUP16 duplicate one of the top sixteen items onto the top, and SWAP1–SWAP16 exchange the top item with one of the next sixteen. There is no opcode to index arbitrarily deep, which is exactly why Solidity developers meet the dreaded 'Stack too deep' compiler error: when a function juggles too many local variables at once, the compiler cannot keep them all within the reachable 16-deep window and forces you to refactor (group variables into a struct, use a block scope, or spill to memory).
Because the stack is fast and free of the gas penalties that storage carries, well-optimized contracts keep hot values on the stack as long as possible. Understanding stack mechanics is essential for reading raw bytecode, writing Yul or inline assembly, and reasoning about gas costs at the lowest level.
The 16-item reach (not the 1,024 depth) is the real practical limit developers hit; you can have many variables alive, but no more than ~16 can sit between an opcode and the value it needs.