Magnesium (Mg) based alloy has been used as a biodegradable implant for fracture repair with considerable efficacy, and it has been proved that magnesium ion (Mg2+), one of the degradation products, could stimulate osteogenesis. Here, we investigated the osteogenesis property of magnesium both in vitro and in vivo, and to identify the cellular and molecular mechanisms that mediate these effects. Results showed that magnesium exerts a dose‐dependent increase in the proliferation of MC3T3 and MG63 cells, and in the expression of osteopontin (OPN), a promising biomarker of osteogenesis. Subsequently, the protein–protein interaction (PPI) network analysis showed the interactions between calmodulin (CaM) and calmodulin‐dependent protein kinase (CaMK) and CREB1. The ratio of p‐CaMKIV/CaMKIV and p‐CREB1/CREB were increased at protein level in MC3T3 and MG63 cells after treatment with Mg2+. Dual‐luciferase reporter gene assay showed that p‐CREB1 could directly bind to OPN promoter and up‐regulate the transcription of OPN after nuclear entry. Meanwhile, the expression of OPN and p‐CREB1, which increased after Mg2+ treatment, was down‐regulated by sh‐CaMKIV or sh‐CREB1. Moreover, the mineralized deposit and expression of OPN were reduced after treatment with an inhibitor of CaMKIV, KN93. In addition, massive cavities in the cortical bone around the Mg screw were showed in vivo after injection of KN93. These data indicated that the osteogenic effect of Mg is related to the activation OPN through CaM/CaMKIV/CREB1 signaling pathway.