Just say if I'm on my laptop for a few straight hours it'll turn itself off for no reason at all, it wont shut down... it just completely knocks itself off. Then if I try and turn it back on straight away it'll do it again

I have to wait about an hour for it to be okay again. Someone told me it could be over heating, which sounds about right tbh because the back gets really hot. Is there a way to fix this?