Nanoporous carbon has been considered an interesting and potentially useful material for storing hydrogen. Using nanoporous carbon periodic supercells with 216 atoms and 50 % porosity, constructed with a novel ab initio approach devised by us, the dangling bonds of the carbon atoms were first saturated with hydrogen, then relaxed and its total energy calculated with and without hydrogen. Next the same number of hydrogen atoms, in molecular form, was randomly placed within the pore of the pure carbon supercell, then the sample relaxed, and finally its total energy calculated, also with and without hydrogens. From these results the average energy per hydrogen atom is obtained for both cases. For the molecular hydrogen sample the binding energy found per hydrogen atom is 343.89 meV, which compares favourably with values reported in the literature, 300-400 meV/molecule.