The generalized gradient approximation (GGA) based on density functional theory(DFT)is used to analyze the geometric and electronic properties of the endohedral fullerene MC20F20 (M=Li, Na, Be, and Mg). The analysis of geometric structure indicates that the C—C bond length increases with the atomic number M, while the C—F bond length hardly changes. The doping energy of all kinds of MC20F20 is negative, indicating that the encapsulation would proceed under certain conditions. The electronic structure demonstrates that MC20F20 (M=Li and Na) and MC20F20 (M=Be and Mg) have different energy gaps and magnetic moments. The energy gaps of MC20F20 (M=Li and Na) are very small, while the energy gaps of MC20F20 (M=Be and Mg) are larger than that of C60 On the other hand, the MC20F20 (M=Li and Na) have 1μB magnetic moment, whereas the magnetic moments of MC20F20 (M=Be and Mg) are zero.