I did some research on similar posts but so far I couldn't find the exact problem that I have.
If I turn on the computer and then I shut it down right after starting the session it works, but if the system has been running for a while and then I shut down, sometimes (not always) it gets frozen after pressing the shut down button. I've tried to reinstall Ubuntu keeping my encrypted home directory but the problems remains. I have a HP ProBook 4330s and Ubuntu 16.04 LTS. Battery is quite worn-out but I don't know if that may affect it. I am still a Linux beginner... Where can I find more info in order to keep looking for a solution?
After some time I finally managed to fix the problem. Actually I solved it by accident, I had a problem with RAM and when I changed it to a new one the problem of turning off the computer has disappeared so I deduce that this was the problem. Thank you all.