Since you reformatted before, unlikely to be a software issue, most prob a hardware problem.
For random reboot, likely to be PSU problem actually.
1. If you can go to BIOS, check system temperature for anomalies.
2. Remove all USB device to make sure it is not bad device interfering with booting up (bad sector HDD etc).
3. Open up your PC to clean out all dust, check that no obstruction to case/PC/PSU fan; this may cause overheating which will cause shut down (happened to me once, random shutdown kept happening, once I clean out the dust, CPU running like new again).
4. Visually check all your component for signs of defects (got once my bro's PSU literally melted, but he still managed to use it for weeks with only occasional restarts).
5. If all else fails, unplug component one by one as mentioned by others, see if you can isolate the problem, then replace damaged parts.
If you can go to BIOS, check system temperature for anomalies.
Start with 1 ram at a time first, because it is the easiest. Followed by the GPU.
Testing the PSU is a bit tricky, can take from old comp or borrow from friend. (or buy a backup)
Unlikely to be bad HDD though, if not you can't even boot up to OS or safe mode properly. But if you suspect HDD got problem, can run a crystaldiskinfo test when you finish reinstalling OS or using another comp. (or buy a backup)
Edit: Actually, it could be a HDD issue. HDD problems may start small (random reboots, freezing etc) until it blows up (cannot boot or install OS).
Since you "only" have a 500GB HDD, you might want to consider upgrading to a SSD + 2TB Seagate combo. Totally worth it.
If all the above fail, the problem is likely the Motherboard or CPU.