Magnesium is an alkaline earth metal that is found in some types of biological sample. One of the responsibilities of medical biological laboratories is the measurement of magnesium. In this study, the metal layer of the surface plasmon resonance sensor was improved using polypyrrole-chitosan/nickel-ferrite nanoparticles to enhance the sensitivity and selectivity of the sensor. The composite layer of polypyrrole-chitosan/nickel-ferrite nanoparticles was prepared by the electrochemical method on a gold-coated glass slide. The measurements were conducted at room temperature with different concentrations of magnesium. In order to determine the selectivity of the sensor, its response was compared with the results obtained in the presence of sodium and calcium ions. The sensitivity limit of the sensor was about 0.1 mg/L, and the response time of the sensing layer was about 350 s.