Advanced coatings have recently gained significant attention in biomedical research for medical implant applications. Among these novel coatings, nanostructured coatings containing hydroxyapatite-titania due to their improvement of implant performance and lifespan are of great importance. In this article, a nanostructured hydroxyapatite-titania coating containing protein and antibiotic was applied on the surface of magnesium alloy AZ31 using electrochemical deposition. The coating's phase behavior, structure, and corrosion behavior were then examined using GIXRD, FESEM, and electrochemical methods, respectively. The biocompatibility of the coating was evaluated by assessing cell growth on the coating surface. The results show that the nanostructured coating containing protein and gentamicin, by improving morphology and increasing biocompatibility and corrosion resisatnce, leads to significant implant performance in patients' bodies and reduces the risk of complications. The whey protein acts as a polymeric agent, improving the adhesion and structural integrity of the coating, while also hindering the penetration of corrosive ions to the substrate. The combination of whey protein with hydroxyapatite and titania results in a denser and more resistant coating, ultimately contributing to the enhanced anti-corrosion performance compared to the hydroxyapatite coating alone.