It's usually a combination of factors. Sometimes entire studios get cut, like how Embracer completely shuttered Volition. Sometimes an entire team is let go if the project gets cancelled. For the really massive games (the kind with multiple studios working on them, like Call of Duty) there's the chance that entire studios or subteams (e.g. the DMZ subteam on Call of Duty) can get eliminated if the decision is made to cut further support for the game mode. These kind of decisions get made at the publishing executive level.
When the studio/game isn't getting shut down/cancelled, the (remaining) team/studio leadership generally divides the employees between a "keepers" group (usually devs who are deemed absolutely necessary for a product's ongoing development) and an "everybody else" group. Keepers are the ones who know all of the innermost workings of the projects that are slated to continue. Without enough of them, the tribal knowledge is lost and the project is basically unsalvageable. The keepers are automatically safe from the reaper.
For everybody else, there's the group quotas and value ranking. There's usually some number of each specific discipline that will get stays of execution - server engineer, UI/UX designer, tech artist, QA, and so on. Each remaining employee is judged on the decision-maker's criteria, and this is where things generally get subjective. General qualities like cost to keep (i.e. salary), experience level, and productivity factor in, but so do things like how much the decision-maker likes the person, ease of working with this employee, and overall manager perceptions (e.g. did the manager see the worker crunching/overtime? Did the manager see the worker goofing off?). The highest in the value ranking for each discipline get to stay and everybody else gets cut.
Suggested Reading: [A Gamer's Primer to Practically Dealing with Job Loss]
Got a burning question you want answered?