Highly efficient and robust non-noble bifunctional electrocatalysts with excellent stability are essential for practical large-scale application of hydrogen energy. Here, we design a hybrid nanostructure of Co2P nanoparticles encapsulated uniformly within N, P co-doped carbon layers that are then integrated into conductive carbon cloth (N-Co2P/NPC). As expected, the developed electrode exhibits very low overpotentials of 68 and 230 mV at 10 mA cm−2 for the hydrogen evolution reaction and oxygen evolution reaction, respectively. Density functional theory calculations reveal that the electronic structure of Co2P can be tailored effectively via the N-doping effect, with the d-band center shifting to a negative position compared with that at the Fermi level, leading to optimized adsorption interaction with hydrogen evolution reaction (HER)/oxygen evolution reaction (OER) intermediates. Furthermore, a stable solar-to-hydrogen conversion efficiency of 17.9% is achieved with a solar-driven water splitting electrolyzer.