First some disclaimers: I'm only going to discuss the tv and film side since that's where I have personal experience. Besides, figuring out mechanical royalties on record sales is nothing more than simple multiplication since the statutory mechanical rate is common knowledge.
Also this info is applicable only to the placement of existing songs and compositions, not to custom underscoring type work (except for the royalty part, which would be the same).
The royalty info below is based on me being a Bmi affiliate, Ascap will be generally similar, although recent changes may affect this, see below.
This is for the US market and may not be applicable elsewhere.
All numbers are applicable to unknown and unsigned artists/songwriters/composers only.
So, there's basically 3 ways to make money from tv and film.
1- Upfront money you may get paid when you sign a contract with a music library or publisher (henceforth MLP)
2- License fees you may get paid when your song is placed in a production
3- Performance royalties you will get paid if the production airs on TV or is shown in movie theatres OUTSIDE THE US. There are no payments for US theatrical performances.
The upfront money an MLP may pay you ranges from zero to perhaps $ 1000/song. Anything above $ 500 is rare in my experience. You typically won't get anything if the contract is either non-exclusive or has a reversion clause. If a MLP pays upfront they will want to own the song, for rather obvious reasons.
Sometimes the upfront payment will amount to a "sync buyout" meaning you won't get to participate in any license fees (see below) in exchange for the upfront payment, and only be entitled to your performance royalties. In most other cases where an upfront fee is paid it will be considered an advance to be recouped from license fees, much like a label would recoup advances paid to artists from record sales.
(All these points are negotiable and if a deal doesn't feel right and they don't want to give you what you want you always have the option to walk away).
In order to use a song in a tv show or film, the production company must obtain a license from the owner of the song (or his/her legal representative), in other words from the MLP (or you if you're doing this on your own).
Technically they need a license both for use of the song (=sync license) and the master recording of the song (=master license), but these days the 2 are often lumped if the owner of both is one and the same.
Total license fees vary WIDELY and are in the range of $0 to about $5000 for TV and all but the highest budget movies (which may go a bit higher if the song is crucial).
Typical range is between $500 and $2000. Note that this is the TOTAL license fee to be divided amongst publishers and writers according to their agreements.
There is no standard here and it largely depends on how much they want your song (or you or the MLP want the placement ), what it's used for, the negotiating skills of the parties etc.
Some real life examples: Bernie Mac Show BG (background) use $675, Judging Amy BG use $1950, Law and Order SVU BG use $550, Dateline NBC PF (partial feature) use $0, Cooler Climate (Showtime movie) FF (full feature, a song) $1400. As you can see there's no rhyme and reason for the amount of the fee. I have even had songs placed on the same tv show by different MLP's and the fees have varied widely...
The license fees for most regular cable networks are in a similar range as broadcast, but NOT the royalties (see below).
This is where it gets REALLY complicated. US TV royalties vary widely, so let's look at the best case scenario and take it from there.
If your song airs on a major broadcast network show in Primetime for at least 45 seconds, the total WRITER'S royalties per broadcast are about $1300 to $1500. So if you placed the song yourself and were also collecting the publisher's share it would be twice that. Every word in bold is a variable. An instrumental background piece instead of the song will pay roughly 1/8th of that. [There is some movement in this area; ASCAP recently announced they are gonna change the ratio between song and instrumental rates to reduce that discrepancy somewhat; this would increase the amount of money paid for instrumentals (and, one would assume, lower the vocal rate to compensate). It remains to be seen what the effects of this will be and if Bmi will do something similar. Many foreign PRO's don't have this big discrepancy (which you notice when you get foreign royalties)].
Now, if the show airs in something other than Primetime, the royalties will be a bit less, although it's not a huge difference. If it's on a "netlet" (WB or UPN) rather than on one of the big four networks, it will pay less as well, perhaps about half of the major network; this is partially due to the facts that the netlets have far less affiliates (stations carrying their broadcast) nationwide. As a matter of fact, FOX pays a bit less than the above amount for ABC/CBS/NBC, since it has about 25% fewer affiliates than the former big 3.
If it is on cable it will pay FAR less than broadcast; the same exact use may pay as little as 40 or 50 bucks on something like Showtime. The main reason for this is that a cable transmission of, say, The Sopranos on HBO is considered ONE transmisson nationwide, whereas in a network broadcast EACH individual affiliate counts as a seperate transmission.
Cable TV royalties are particularly confusing: the biggest premium networks such as HBO that really compete with the broadcast networks don't necessarily pay better than "basic cable", in fact in my experience they pay less than e.g. Lifetime or TNT. This all comes down to negotiations between the PRO's and the individual cable stations.
The last variable is the timing. In the case of a song it pays proportionately less if it's on less than 45s, but not more if it's over. Instrumental music on the other hand pays per second. The longer the better.
Last but not least you get paid every time the show airs. If a show is a big success and goes into syndication, it may generate royalties for years to come (of course if it's syndicated on a smaller network or cable, the payment will be less).
If it's a big hit overseas you may get a decent chunk of money from there as well. No country pays close to what the US pays for broadcast TV, because no other country has anywhere near as many broadcast stations. Payments from foreign countries tend to be more in line with US cable, but it's kind of difficult to figure out the exact rates because usually the foreign PRO's don't specify how many times the show aired, for example; the details are rather sketchy...
At this point I have no first hand knowledge about foreign theatrical royalties; I've had some songs in major movies recently, but the royalties from overseas take a while to roll in. Obviously this will vary WIDELY according to a films success overseas. So ask me again in 3 years . For film placements, it's important to remember that most films will end up on TV at some point, first on cable and later, if it was a hit, on broadcast TV. At that point the same rates as for regular TV apply, and the same goes for eventual foreign TV performances of the movie.
One last thing about TV royalties that has surprised me over the years is that it's not always the big obvious things that make the most money. Everybody (including me) wants a song on CSI or Housewives, and that's great. But there are lots of little "unknown" shows out there...and many little things also add up to a big thing...
Here's an example:
I have a little instrumental piece that was on "Judging Amy" and 3 times on the NBC soap "Passions" a few years ago. So far it's made me about $ 2826 in royalties (not counting license fees here). On the other hand I have another little instrumental piece that was only on some little religious show called "Life In The Word", which was on for about a year and a half during daytime, not on any major network but in nationwide local syndication. The thing about that show however is that it was a daily show, and they used that piece a lot, like 3-4 times a week. Each time it aired it made only maybe 10-20 bucks, but overall it added up to $ 5106 in royalties...so you really never know.