I Have Questions About Prison Assignments & Related Stuff

Mostly I’m after procedural stuff . . .

How do They decide what prison a criminal must serve time in after he or she is convicted? Does the judge decide? Or does some clerk just send a message to the Bureau of Prisons who then has to decide? If so, who within the BOP (or whatever other agency) decides and what criteria do they use? Sometimes, I imagine, it’s fairly obvious what prison a criminal must go to if they are a particular security risk, have certain medical problems, or whatever. But what about your “Average Joe” cons? For example, where I live, there are at least three prisons (two state, one private-owned) to choose from, not counting any federal prisons. Does each state do things differently? What about federal prisons? I know of one case in real life and several cases from reading where people got transferred out of particular prisons because those institutions were “too hard”–-in other words, a decision was made (by whom?) that a mistake was made in matching the con with the prison. What exactly are the rules governing these sorts of things, who makes up these rules, and who enforces them?

I know that’s a lot of questions, and depending on what answers I receive, I may have more. For now, any answers to any of these things would be much appreciated.

Thanks in advance, all.

This post is brought to you out of NYPD Blue and The Practice related curiosity, not out of any RL trouble.