Answer:
The flame provides an input of energy. It excites electrons in the material that is being burned. These electrons get promoted to a higher atomic energy level. When they return to a lower energy level, they release energy in the form of light (an output of energy.) The frequency of the light depends on the energy difference between the initial and final energy level of the electron. The color of the flame depends on the frequency of the emission.
Explanation:
There are multiple electron energy levels within an atom. During most of the time, electrons in an atom stay in levels with the lowest potential energy possible. However, when the atom gets heated (e.g., over a flame,) electrons will gain energy from the flame and move to levels of higher potential energy.
As more electrons get promoted, some will eventually fall back to their initial energy level. Electron energy levels in an atom are quantized. In other words, the energy difference between two levels is a definite value, and that no electron can exist between two energy levels.
Energy conserves. These potential energy needs to go somewhere. In the case of an electron transition, the potential energy that has been lost will be released as an electromagnetic emission. Keep in mind that only one photon will be released for each transition. That photon will account for all the potential energy differences . The Planck-Einstein Relation gives the frequency of that photon. That's the same as the frequency of the beam of light that is observed.
,
where is Planck's Constant.
The frequencies of most of these transitions are in the infrared region of the spectrum. If there are more than one few visible emissions, these emissions combine to produce a distinct flame color.