Membranes with fast and selective ion transport are widely used for water purification and devices for energy conversion and storage including fuel cells, redox flow batteries and electrochemical reactors. However, it remains challenging to design cost-effective, easily processed ion-conductive membranes with well-defined pore architectures. Here, we report a new approach to designing membranes with narrow molecular-sized channels and hydrophilic functionality that enable fast transport of salt ions and high size-exclusion selectivity towards small organic molecules. These membranes, based on polymers of intrinsic microporosity containing Tröger's base or amidoxime groups, demonstrate that exquisite control over subnanometre pore structure, the introduction of hydrophilic functional groups and thickness control all play important roles in achieving fast ion transport combined with high molecular selectivity. These membranes enable aqueous organic flow batteries with high energy efficiency and high capacity retention, suggesting their utility for a variety of energy-related devices and water purification processes.