Nanoporous membranes promise energy-efficient water desalination. Hexagonal boron nitride (h-BN), like graphene, exhibits outstanding physical and chemical properties, making it a promising candidate for water treatment. We employed Car–Parrinello molecular dynamics simulations to establish accurate modeling of Na+ and Cl- permeation through hydrogen passivated nanopores in graphene and h-BN membranes. In these complex systems the classical potentials cannot properly account for the physics at play. We demonstrate that ion separation works well for the h-BN by imposing a barrier of 0.13 eV and 0.24 eV for Na+ and Cl- permeation respectively, compared to the graphene where the Cl- ion faces a negative barrier of 0.68 eV and is prone toward blockade and Na+ permeation is associated with a slightly negative barrier of 0.03 eV. From the change in the solvation shell, we get the following trend: Na/h-BN > Na/G > Cl/G > Cl/h-BN. We argue that the trend in the permeation barrier changes to Cl-h-BN > Na-h-BN > Na-G > Cl-G due to a combination of several interactions, including the distortion of the water network induced by the ions, the ion-water interaction, and the ion-nanopore interaction. Overall, the desalination performance of h-BN surpasses that of their graphene counterparts.