Supercapacitors are electrochemical energy storage devices that operate on the simple mechanism of adsorption of ions from an electrolyte on a high-surface-area electrode. Over the past decade, the performance of supercapacitors has greatly improved, as electrode materials have been tuned at the nanoscale and electrolytes have gained an active role, enabling more efficient storage mechanisms. In porous carbon materials with subnanometre pores, the desolvation of the ions leads to surprisingly high capacitances. Oxide materials store charge by surface redox reactions, leading to the pseudocapacitive effect. Understanding the physical mechanisms underlying charge storage in these materials is important for further development of supercapacitors. Here we review recent progress, from both in situ experiments and advanced simulation techniques, in understanding the charge storage mechanism in carbon- and oxide-based supercapacitors. We also discuss the challenges that still need to be addressed for building better supercapacitors.