This is exactly why chemistry is so interesting and the ways in which things can combine is also why it is so difficult.
Fundamentally, it's mostly about the electron charges on an atom which are balanced out by the number of protons in the nucleus. The proton however is a tightly packed point charge but the electrons can only exist in various energy levels (think of different shapes) around it.
You could think of it as trying to pack a bunch of magnets that have very elaborate electromagnetic field shapes into a box in a specific configuration. You might find one configuration that happens to be 'stable' until a big piece of iron is nearby and then suddenly it all snaps into a new configuration.
Fundamentally, it's mostly about the electron charges on an atom which are balanced out by the number of protons in the nucleus. The proton however is a tightly packed point charge but the electrons can only exist in various energy levels (think of different shapes) around it.
You could think of it as trying to pack a bunch of magnets that have very elaborate electromagnetic field shapes into a box in a specific configuration. You might find one configuration that happens to be 'stable' until a big piece of iron is nearby and then suddenly it all snaps into a new configuration.