...for the annual dialogue on "how does this work" and "what will we get for Welker" google Adamtj13. He "broke the code."
A summary, from memory:
Depends on net loss of Unrestricted Free Agents. That is, you lose more than you gain. If you lose Tom Brady, and gain two back-up safeties, you are not getting a compensatory pick.
Players cut, waived, released, whatever do not count, either for or against.
If the player you signed or lost doesn't make the roster, generally that doesn't count.
Only pick-ups during the free agency period count. Players that sit around a while and get picked up during training camp do not count.
The primary algorithm is based on average annual salary. Contributing to that is number of starts and other performance-based metrics.
There are always 32 selections. It's essentially an 8th round to the draft. When the allocation of players to teams with a net loss of players is complete, but not 32 picks, the NFL allots picks based on a more nebulous 'net loss of players' for teams that had an even balance, but lost better players (higher paid) than they gained. Then it just goes to draft order.