NH3 synthesis via the electrocatalytic nitrogen reduction reaction (NRR) under ambient conditions has been regarded as a sustainable strategy for fertilizer production, hydrogen fuel storage, and mitigating greenhouse gas emissions. Electrochemical reduction reaction of nitrogen to ammonia has been widely investigated as a potential technology to overcome thermodynamic barrier of high-temperature and high-pressure needed for industrial Haber-Bosch process. The design of construction of heteroatoms (e.g., B, N, P, S) doped carbon materials have become a research focus as metal-free electrocatalysts owing to their good electrochemical stability and high electronic conductivity. N-doping carbon materials could induce the protonated pyridinic N and adjacent atomic vacancy site, which are favor of N2 adsorption. Besides, on account of charge density difference, B-doping carbon materials could induce inhomogeneity for carbon to adsorb N2 molecules. Compared with single heteroatom dopant, heteroatom co-doping could bring in charge redistribution of carbon, which can facilitate the chemisorption of N2 molecules and following electron transfer.Herein, we present a metal-free B and N co-doped porous carbon nanofibers (B/N-CNF) fabricated by an electrospinning and calcination strategy. The FESEM image of B/N-CNF showed the typical morphology of the cross-linked carbon networks composed of nanofibers with a diameter of ~100 nm. The contents of B and N dopant for B/N-CNF were 29.9% and 27.6%, respectively. The N2 adsorption-desorption isotherms curve of B/N-CNF exhibited a high BET specific surface area of 748 m2 g-1 and a mesopores structure with pore diameter of around 4 nm and volume of ~0.39 cm3 g-1. Benefitting from a high surface area and synergistic effect between B and N dopants, the B/N-CNF exhibited a high electrocatalytic activity for NRR in a basic electrolyte, achieving the highest FE of 13.2% at -0.5 V and the NH3 yield rate of 32.5 μg h-1 mg-1 cat. at -0.7 V. Such a high NRR activity was superior to most of the previously reported B- or N- doped carbon materials. It was found that B atoms facilitated the cleavage of N≡N bonds, and the N atoms enhanced the electronic conductivity of CNF nanofibers.The B/N-CNF delivered superior catalytic activity for electrochemical NRR, featured by the highest FE of 13.2% at -0.5 V and NH3 yield of 32.5 μg h-1 mg-1 cat. at -0.7 V in basic electrolytes. The high NRR performance could be attributed to the synergistic effect between B and N co-dopants. The FE value of B/N-CNF was almost the highest among all previously reported carbon-based materials with single N- or B-doping. Moreover, an electrolyzer with B/N-CNF as the cathode and commercial Ir/C as the anode was successfully fabricated to confirm the NRR activity of B/N-CNF driven by alkaline batteries and solar panels. The developed B/N-CNF presented in this work paves a promising pathway for rational design of highly efficient dual heteroatoms doped carbon materials for not only NRR, but other electrochemical energy conversion reactions.