Selective ion transport underpins fundamental biological processes for efficient energy conversion and signal propagation. Mimicking these ‘ionics’ in synthetic nanofluidic channels has been increasingly promising for realizing self-sustained systems by harvesting clean energy from diverse environments, such as light, moisture, salinity gradient, etc. Here, we report a spatially nanoconfined ion separation strategy that enables harvesting electricity from CO2 adsorption. This breakthrough relies on the development of Nanosheet-Agarose Hydrogel (NAH) composite-based generators, wherein the oppositely charged ions are released in water-filled hydrogel channels upon adsorbing CO2. By tuning the ion size and ion-channel interactions, the released cations at the hundred-nanometer scale are spatially confined within the hydrogel network, while ångström-scale anions pass through unhindered. This leads to near-perfect anion/cation separation across the generator with a selectivity (D-/D+) of up to 1.8 × 106, allowing conversion into external electricity. With amplification by connecting multiple as-designed generators, the ion separation-induced electricity reaching 5 V is used to power electronic devices. This study introduces an effective spatial nanoconfinement strategy for widely demanded high-precision ion separation, encouraging a carbon-negative technique with simultaneous CO2 adsorption and energy generation.