Hydrogen peroxide (H2O2), an important industrial chemical, is currently produced through an energy-intensive anthraquinone process that is limited to large-scale facilities. Small-scale decentralized electrochemical production of H2O2 via a two-electron oxygen reduction reaction (ORR) offers unique opportunities for sanitization applications and the purification of drinking water. The development of inexpensive, efficient, and selective catalysts for this reaction remains a challenge. Herein, we examine two different porous carbon-based electrocatalysts and show that they exhibit high selectivity for H2O2 under alkaline conditions. By rationally varying synthetic methods, we explore the effect of pore size on electrocatalytic performance. Furthermore, by means of density functional calculations, we point out the critical role of carbon defects. Our theory results show that the majority of defects in graphene are naturally selective for the two-electron reduction of O2 to H2O2, and we identify the types of defects with high activity.