Nano-confined chemical reactions bear great promise for a wide range of important applications in the near-to-medium term, e.g., within the emerging area of chemical storage of renewable energy. To explore this important trend, in the present work, resorcinol-/formaldehyde-based carbon aerogels were prepared by sol-gel polymerisation of resorcinol, with furfural catalysed by a sodium-carbonate solution using ambient-pressure drying. These aerogels were further carbonised in nitrogen to obtain their corresponding carbon aerogels. Through this study, the synthesis parameters were selected in a way to obtain minimum shrinkage during the drying step. The microstructure of the product was observed using Scanning Electron Microscopy (SEM) and Field Emission Scanning Electron Microscopy (FESEM) imaging techniques. The optimised carbon aerogels were found to have pore sizes of ~21 nm with a specific accessible surface area equal to 854.0 m2/g. Physical activation of the carbon aerogel with CO2 generates activated carbon aerogels with a surface area of 1756 m2/g and a total porosity volume up to 3.23 cm3/g. The product was then used as a scaffold for magnesium/cobalt-hydride formation. At first, cobalt nanoparticles were formed inside the scaffold, by reducing the confined cobalt oxide, then MgH2 was synthesised as the second required component in the scaffold, by infiltrating the solution of dibutyl magnesium (MgBu2) precursor, followed by a hydrogenation reaction. Further hydrogenation at higher temperature leads to the formation of Mg2CoH5. In situ synchrotron X-ray diffraction was employed to study the mechanism of hydride formation during the heating process.