Here is how to hard reset (back to factory default settings) the Nokia XpressMusic 5800.

I suggest backing up your phone’s contents using Nokia PC Suite before proceeding, because a hard reset will erase everything on your phone. If you have a memory card, I also suggest backing up its contents and then formatting it, because some apps you downloaded through the Ovi Store may be installed on the memory card. After the hard reset, when you reinsert the memory card, those apps may reinstall automatically.
To hard reset your phone using the on-screen keypad, enter the following code:
*#7370#
When prompted for the security code, enter:
12345
Your phone will restart and, after it finishes booting, it should be as good as new.