Contrary to popular belief, songs are not "sold" to the artists that record them. In fact, artists who record "outside" songs, pay nothing for the privilege until records are sold.
Songwriters earn money in two ways: a) When records are sold and b) when their songs are played on radio, TV and other public areas (restaurants, concerts, etc).
Payments from record sales are called mechanical royalties and are paid by the record company to the publisher of the song through the Harry Fox Agency. The royalty rate is set by congress (the "statutory rate") and is at this writing set at 9.1 cents per unit sold on or offline. Therefore if you had one song that was written and published solely by you on a million selling album, you would earn $91,000 in mechanical royalties.
Performance royalties are collected from radio and TV broadcasters, etc. by the Performing rights organizations ASCAP, BMI, or SESAC in the United States (each country has its own P.R.O.). The P.R.O.s distribute these payments to their member songwriters and publishers based on formulas that calculate how many people have been exposed to the song. A number one pop single might earn as much as a million dollars in performance royalties in its biggest year.
That varies widely depending on the kind of show or film using your music. Money is earned in two ways: the licensing fee, paid up front to the writer/artist, and the performance royalty, which is distributed to the writer by a performing rights organization ( ASCAP, BMI, or SESAC in the U.S.).
The license fee is determined by the overall music budget a music supervisor has to work with, and the negotiating power of the artist. Unknown artists get far less license money than superstars, for example. TV shows and small films pay less than major studio feature films. A prime-time network TV show might pay a license of $500 - $5000 for an unknown artist - same for the smaller films. Major studio pictures pay well-known artists in the tens of thousands of dollars.
Performance income is determined by the number of people estimated to have seen the show and therefore heard the music. The more popular the show - the more money you make on performance royalties. A network TV usage might pay in the $1000 - $2000 range for one broadcast. You make new royalties every time the show is re-run, which is particularly good news if you've got music on a show that goes into syndication and airs frequently in markets around the world. Cable broadcasts generally pay less than broadcast networks (less viewers).
No performance royalties are generated on theatrical showings of films in the U.S.A. (though they are paid in other countries), but when the film is aired on TV, you would make your performance money.
You may also make money when videos or DVDs are sold, depending on the nature of your original license agreement.