Despite recent increased research interest in hetero-atom (B and/or N) doping effects on the oxygen reduction reaction (ORR) performance of carbon nanomaterials, microscopic understanding of active catalytic sites and effects of B and/or N doping has not been conclusively reached. Here, through comparative first-principles simulations between BN codoping and isolated B or N doping in both graphene nanoribbons (GNRs) and carbon nanotubes (CNTs), we not only identify active sites in these doped carbon nanomaterials, but elucidate the underlying mechanism of ORR processes. While the distortion of C-C bonds in CNTs leads to strong binding of O2, spin density distribution along the edges plays a key role in enhancing the adsorption strength of O2 on GNRs. The effective adsorption of O2 facilitates the following elementary reduction reactions. Based on thermodynamic analyses, O2 adsorption as well as the electron and proton transfer to O atom are identified as key rate-determining steps. For CNTs, a good linear scaling is found between the adsorption energies of key intermediate products and that of atomic O, and thus the latter serves as a good descriptor for ORR activities. Further, N-doped high-quality CNTs are shown to exhibit best performance. For GNRs, due to edge effects, the linear relationship is broken, which promotes the catalytic activities in the BN codoping case. These findings resolve the long-standing controversy on the synergetic effects of B and N codoping, which deepens our understanding of the reaction mechanism. This work might further facilitate the optimization of the doping strategies for high-efficiency carbon-based ORR catalysts.