This HP support page explains how to perform Factory Recovery from within Windows, and how to do it if Windows won't start:
http://support.hp.com/gb-en/document/c01867418
Please note that it won't be successful if there are any existing internal hardware faults.
If it's a laptop,
do not attempt to run factory restore whilst running on battery power, plug it in to a mains supply because it can take several hours to complete.