Electrochemical N2 reduction (NRR) to ammonia is seriously limited by the competing hydrogen evolution reaction (HER), but atomic-scale factors controlling HER/NRR competition are unknown. Herein we unveil the mechanism, thermodynamics, and kinetics determining the HER/NRR efficiency on the state-of-the-art NRR electrocatalyst, Ru-N4, using grand canonical ensemble density functional theory (GCE-DFT). We show that NRR/HER intermediates coadsorb on the catalyst where NRR intermediates suppress HER and selectivity is determined by the initial step forming *NNH or *H. Our results provide crucial insight into the complex NRR/HER competition, show the necessity of using GCE-DFT calculations, and suggest ways to improve NRR selectivity.