If we give energy to some metallic atoms, by heating them, their electrons jump from one electron shell to another. As they fall back to their normal state they release the excess energy in the form of light. Each atom emits a unique colour of light and thus the flame test can be used to identify different metals.