Pure hydroxyapatite nanocomposites with different amount of magnesium additive were synthesized using a simple sol-gel method. For this purpose, the initial gel was obtained by the chemical reaction of calcium, magnesium, and phosphorus-related precursors, and after remaining for 48 h at room temperature, it was dried for 24 h at 120˚C in an electric furnace. Finally, to remove the organic materials and volatiles, this product was placed at 600˚C for 3 h. This way, six samples with molar percentages of 0, 2, 4, 6, 8, and 10 of magnesium were prepared. To investigate the effect of magnesium amount on the nanocomposite properties, X-ray diffraction pattern (XRD), Fourier-transform infrared spectroscopy (FTIR), and scanning electron microscopy (SEM) images were used, and also, compressive strength testing was performed. The results confirmed the successful synthesis of hydroxyapatite nanocomposites and showed that with increasing magnesium content, the crystal size decreases. Moreover, pure hydroxyapatite has a needle-like and plate-like microstructure, while in hydroxyapatite substituted with 4% magnesium, only needle-like structure is observable. In addition, in hydroxyapatite substituted with 10% magnesium, only plate-like structure is visible. Finally, the sample substituted with 4% magnesium showed the highest compressive strength, and the sample substituted with 10% magnesium ranked as the second one.