We study the nucleation of a new thermodynamic phase in pores and find that the nucleation often proceeds via two steps: nucleation of pore filling, and nucleation out of the pore. These two rates have opposing dependencies on pore size, resulting in a pore size at which the nucleation rate of the new phase is maximal. This finding is relevant to attempts to design and use porous media to crystallize proteins. DOI: 10.1103/PhysRevLett.97.065701 PACS numbers: 64.60.Qb, 68.55.Ac, 82.60.Nh Crystallization and condensation both start with heterogeneous nucleation, which occurs at a surface. The nucleus of the crystal or liquid phase forms in contact with this surface. In both cases nucleation is an activated process [1]. The barrier to formation and hence the rate of crystallization or condensation depends on the properties of the surface. In particular, this rate is known to be very sensitive to the geometry of the surface. Studies of nucleation in pores where the surfaces of the pore may confine the nucleus along one or more directions [2 -5] have found that both the size and shape of the pore strongly effect the nucleation rate. These studies were motivated by the desire to understand the hysteresis of phase transitions inside porous media [6,7]. Here, we study nucleation in pores via computer simulations, and we find that nucleation occurs in the corners of pores. Thus, for example, unless a slit pore is very long we expect condensation in it to occur via nucleation in a corner, not via nucleation far from the pore ends as was studied in earlier work [2,3]. This is consistent with the work of Paul and Rieger [7] who found less hysteresis for a closed pore (which has corners) than for an open pore (without corners).Thus our work is relevant to condensation in porous media. However, the primary motivation behind this work is to better understand the nucleation of protein crystals in solutions that contain a piece of porous medium [8,9]. The nucleation only occurs in the presence of the porous medium and the crystals are found to be stuck to this medium, implying that the protein crystal nucleates on the surface of the porous medium. Surfaces that are not porous have proved less successful at promoting nucleation [9,10]. This is evidence that it is the geometry of the pores that is accelerating nucleation. Finally, only disordered porous media were effective; media in which the pores were of uniform size, such as zeolites, did not induce nucleation [9,10]. It was hypothesized [8,9] that there is a pore size at which the nucleation rate was maximal and that as disordered porous media have pores with a range of sizes a disordered porous medium is likely to have pores near this size. A zeolite's pores are all the same size and it is improbable that this size will just happen to be a size at which the nucleation is fast. We find here that there is indeed a pore size at which the nucleation rate is fastest, supporting the earlier hypothesis.As we are interested in generic features of nucleation from pores, we study...