A porous Mg-based 3D metal–organic framework with unique nanoscale cages and two-fold interpenetrating pcu nets has been synthesized and characterized. It shows gas-uptake capacities for N2, H2, O2 and CO2 at low temperatures and selective adsorption of CO2 over O2 and N2 at room temperature.