Sometimes it is a result of blockage of your airway, commonly by your tongue and other tissues.
Sometimes it is a result of your brain not sending the right message to breathe. Sometimes it is a combination of the two. Treatment varies based on the cause. The first thing to do is to get a sleep study
, and your physician can coach you on your specific problem.