In this study, density functional theory calculations are used to investigate the performance of pristine B3CN4 and its doped structures with Ti and Al atoms (Ti-B3CN4 and Al-B3CN4) as anodes for Mg-ion batteries. It is found that all these systems have a high ability to adsorb Mg with favorable adsorption energies. The electron donation of Mg on these anodes is also very high due to the negative adsorption energy of Mg2+, compared to Mg. The results suggest that Al-B3CN4 provides the best conditions for the migration of Mg atoms on the anode surface due to its lower energy barrier. By obtaining the maximum number of Mg atoms adsorbed atoms on these nanostructures, a theoretical storage capacity of about 900 mAh.g−1 is calculated, which is greater than that of many anodes developed recently. These nanostructures as anodes also provide low open circuit voltage (VOC). The VOC values obtained for B3CN4, Ti-B3CN4 and Al-B3CN4 are 0.15, 0.21 and 0.18 V, respectively. The interesting results of this research can be used experimentally to produce high-performance anode materials in the Mg-ion batteries production industry.