Keeping the backlog in good order is the responsibility of the Product Owner (PO). It's the Scrummaster's job to support the PO in this task. Regular scouting of the backlog, reviewing the stories, how they're written, attaching supporting documentation and maintaining the priorities is key to keeping the development flowing in the right direction. The backlog is the PO's interpretation of the business requriements. The team will draw from this backlog so it's important that the order is correct to ensure the development stays on track.
The backlog lists, in the order they're to be work on, the user stories. Working in an agile framework means that the priorities we set can change regularly in order to respond to change and business direction.
How stories are prioritised is not an exact science and needs to take a number of things into consideration:
Effort How much effort is required to complete the story? Larger stories will require a sprint or two while others will take only a short space of time. Smaller stories can be packaged together and delivered in a sprint. Individual, smaller stories might fit into a sprint with several larger stories. It's down to your delivery team to estimate the effort required. With this information you can decide how to prioritise the effort.
Value The effort involved in delivering a story does not necesarily match the value it delivers. The value of a story will depend on the business objectives that have been set.
Dependencies Some stories will require other stories to be completed before they're worked on. Dependent stories could include data migration whereby content cannot be worked on until the migration is complete. In this example we'd need to prioritise some stories based on the dependencies.
Time Critical Are there stories that deliver particular functionality that is needed for an event? If you're working on a live service then look at the schedule and confirm which stories must be delivered by a particular time.
So... ((Effort/Value)-Dependencies)+Time Critical is an equation that will never calculate your priorities. The calculation of priorities requires human interaction, discussion and common sense. Put your stories on a board, group them, talk through the priorities, have your work schedule to hand, move the stories around, discuss the different permutations. What you must remember is that this is agile. Today's priorities are not necessarily tomorrow's priorities. Work with what you know now and adjust as you learn more later.