Dealloying is a common corrosion process during which an alloy is 'parted' by the selective dissolution of the most electrochemically active of its elements. This process results in the formation of a nanoporous sponge composed almost entirely of the more noble alloy constituents. Although considerable attention has been devoted to the morphological aspects of the dealloying process, its underlying physical mechanism has remained unclear. Here we propose a continuum model that is fully consistent with experiments and theoretical simulations of alloy dissolution, and demonstrate that nanoporosity in metals is due to an intrinsic dynamical pattern formation process. That is, pores form because the more noble atoms are chemically driven to aggregate into two-dimensional clusters by a phase separation process (spinodal decomposition) at the solid-electrolyte interface, and the surface area continuously increases owing to etching. Together, these processes evolve porosity with a characteristic length scale predicted by our continuum model. We expect that chemically tailored nanoporous gold made by dealloying Ag-Au should be suitable for sensor applications, particularly in a biomaterials context.