It's all based on probability. Each state has a particular probability of transitioning to a lower energy state per unit of time and some states take longer or shorter to transition than others. I wish I had a good link for you, but the ones I can find at the moment are knee-deep in quantum mechanical terms, which are over even my head.
Note the section on probability in the Introduction and the similarity with radioactive decay.
And the section on Theory and Rate, where, as always, it requires more grey-matter usage.
when electrons are exiced they absorb energy so they jump to a higher orbit(shell), when they go into lower shells they release energy in the form of electromagnetic waves.