We develop a simple model for the formation energies (FEs) of alkali and alkaline earth alanates and boranates, based upon ionic bonding between metal cations and AlH4- or BH4- anions. The FEs agree well with values obtained from first principles calculations and with experimental FEs. The model shows that details of the crystal structure are relatively unimportant. The small size of the BH4- anion causes a strong bonding in the crystal, which makes boranates more stable than alanates. Smaller alkali or alkaline earth cations do not give an increased FE. They involve a larger ionization potential that compensates for the increased crystal bonding.