Structural design of barium hexaferrites BaMgxCo2-xFe16O27 (x = 0:0, 1, 2) has been studied, and the magnetic and electronic structure of that has then been investigated using first principle total energy calculation. All calculations are based on the density functional theory. In order to improve the description of strongly correlated 3d electrons of iron, the general gradient approximation plus Hubbard U (GGA+U) method is used. We found that in the lowest energy configuration Mg and Co ions preferentially occupy the 6g sites. With the increase of Mg content x, the energy gap of BaMgxCo2-xFe16O27 increases but the lattice constant of unit cell decreases. The magnetic moment of the unit cell for Mg content x = 0, 1, and 2 are calculated to be 52, 49 and 46 μB/cell, respectively, in agreement with previous experimental results. The substitutions of Mg and Co at the BaFe2+2 Fe3+16O27 decrease electrical conductivity and transit it from a half-metal to semiconductor material. Based on our calculations on electronic band structure, the BaFe2Fe16O27 (BFFO) is a weak half-metal, but BaMg2Fe16O27 (BMFO), BaMgCoFe16O27 (BMCFO) and BaCo2Fe16O27 (BCFO) are semiconductors. The electrical resistivity increases by increasing Mg and Co contents due to increase in porosity which prevents the hopping of charge carriers