The regulation of water content in polymeric membranes is important in a number of applications, such as reverse electrodialysis and proton-exchange fuel-cell membranes. External thermal and water management systems add both mass and size to systems, and so intrinsic mechanisms of retaining water and maintaining ionic transport in such membranes are particularly important for applications where small system size is important. For example, in proton-exchange membrane fuel cells, where water retention in the membrane is crucial for efficient transport of hydrated ions, by operating the cells at higher temperatures without external humidification, the membrane is self-humidified with water generated by electrochemical reactions. Here we report an alternative solution that does not rely on external regulation of water supply or high temperatures. Water content in hydrocarbon polymer membranes is regulated through nanometre-scale cracks ('nanocracks') in a hydrophobic surface coating. These cracks work as nanoscale valves to retard water desorption and to maintain ion conductivity in the membrane on dehumidification. Hydrocarbon fuel-cell membranes with surface nanocrack coatings operated at intermediate temperatures show improved electrochemical performance, and coated reverse-electrodialysis membranes show enhanced ionic selectivity with low bulk resistance.