Respuesta :

Sodium is in group 1 while magnesium is in group 2. That's why they form different ions. It's based on what groups the element is in.
sodium is in group 1. and magnesium is in group two