Salam. I think by spirit you mean soul. If yes, then you are right. When one sleeps, Allah takes his soul and may or not may not return it to his body. As Allah states in Quran: (39:42)
Allah takes the souls at the time of their death, and those that do not die [He takes] during their sleep. Then He keeps those for which He has decreed death and releases the others for a specified term. Indeed in that are signs for a people who give thought.
This ayyah declares that Allah takes souls in two forms: First soul from ones who died and second from those living ones who are alive during their sleep.
And Allah states: (6:60)
Translation: (Sahih International) And it is He who takes your souls by night and knows what you have committed by day. Then He revives you therein that a specified term may be fulfilled. Then to Him will be your return; then He will inform you about what you used to do.
There are some ahadith as well but I think these two ayyah especially the first one clears the point. Could I help you?