Found this on wiki so take it for what it's worth but it covers the basic formula.
Compensatory picks
In addition to the 32 picks in each round, there are a total of 32 picks awarded at the ends of Rounds 3 through 7. These picks, known as "compensatory picks," are awarded to teams that have lost more qualifying free agents than they gained the previous year in free agency. Teams that gain and lose the same number of players but lose higher-valued players than they gain also can be awarded a pick, but only in the seventh round, after the other compensatory picks. Compensatory picks cannot be traded, and the placement of the picks is determined by a proprietary formula based on the player's salary, playing time, and postseason honors with his new team, with salary being the primary factor. So, for example, a team that lost a linebacker who signed for $2.5 million per year in free agency might get a sixth-round compensatory pick, while a team that lost a wide receiver who signed for $5 million per year might receive a fourth-round pick.
If fewer than 32 such picks are awarded, the remaining picks are awarded in the order in which teams would pick in a hypothetical eighth round of the draft (These are known as "supplemental compensatory selections").
Compensatory picks are awarded each year at the NFL annual meeting which is held at the end of March; typically, about three or four weeks before the draft.