Ionic compounds are formed from metal and non-metal elements
Further explanation
The chemical formula of compounds (especially ionic compounds) can be determined from the charge of each ion.
Determination of the ionic charge of the constituent elements of the compound can be seen from the electron configuration to achieve stability according to the octet rule
The charge of each ion will be crossed in the compound
Aluminum bromide
Al³⁺ + Br⁻ ⇒ AlBr₃
Magnesium bromide
Mg²⁺ + Br⁻ ⇒ MgBr₂
Sodium sulfide
Na⁺ + S²⁻ ⇒ Na₂S
Sodium nitride
Na⁺ + N³⁻ ⇒ Na₃N