By default, the category with lowest ID is used.
If you want control over what the category is, you can try the Hikari Category Permalink plugin, which allows you to choose which post category is used for the permalink.
http://wordpress.org/extend/plugins/hikari-category-permalink/