The global minimum structures of Mgn clusters have been determined using the so-called "kick method". With the improved DFT method of B3PW91 functional and Grimme's dispersion correction, a series of the most stable structure of Mgn have been found and a novel Mg9 structure has been located. Subsequently, the chemisorption of hydrogen onto Mg clusters was systemically studied. Considering the average adsorption energies and the ratio of Mg and H, we developed a function that can describe the relation between average adsorption energy and number of Mg and H atoms. Our results may be helpful in the future for developing different kinds of gas chemisorption materials.