If you have previously connected the phone to PC or Mac and used the iTunes application, then simply connect your phone again and click on Restore iPhone.
Another way is through the menu on the phone. Go to General > Reset > Erase all Content and Settings. Practically, this removes everything on the iPhone including custom apps, pictures, music, settings, etc.
The whole operation might take a while to complete successfully, but when it does finish, the phone needs to be configured again.
Warning: You should be careful when you do this, because if the phone isn't neverlocked, then you might get stuck with a hard bricked iPhone or locked, more simply to say it and Apple Care needs to be contacted afterwards.