The electrical conductivity is the fundamental physical property of Mg alloys and the basic information for the design of comprehensive high-performance Mg alloys. In this work, the electrical conductivity of 29 Mg-based binary alloys has been calculated using the first-principles methods and the main factors have been analyzed by machine learning. It is found that the electrical conductivity values of the binary alloys containing elements located in the s region and p region of the periodic table are bigger than others of alloys contain alloying elements in the f region and d region. The results of machine learning show that the difference ratio of volume (∆V/VMg), extra-nuclear electron configuration and difference of valence () play the main controlling role, followed by solid solubility and electronegativity of the alloying element. For solid solution elements in Mg-based binary alloys, the impact weight on the electrical conductivity is: difference ratio of volume > number of extra-nuclear electron vacancy > difference of valence.