You can not get pregnant by masturbating.
You can not even get pregnant by masturbating someone else.
More importantly, if someone gives you a pregnancy test there is absolutely no way for them to know if you have been masturbating. Pregnancy tests are not masturbation detectors. Pregnancy tests are pregnancy detectors.
People can also not tell if you were masturbating by looking for hair on your palms. They might, however, be able to tell if you don’t wash the items you masturbate with so, if you are concerned about people knowing you masturbate, soap and water are your friends. So is doing your own laundry.
That said, although some people are uncomfortable about the fact that they masturbate, masturbation shouldn’t be a source of shame. It’s fun, it improves your sex life, and it can make it easier to get a good night’s sleep. Plus, if you have a high sex drive, masturbation can help keep you from making poor sexual decisions (that could get you pregnant) with someone else.
Explanation for why you can’t get pregnant by masturbating:
Getting pregnant requires sperm to reach a fertilized egg inside your body. Masturbating doesn’t provide the sperm. Alternatively, masturbating someone else doesn’t provide the egg (or the inside of your body.) From the perspective of pregnancy, masturbation is entirely safe sex.
This was written in response to a question asking if masturbation will make a pregnancy test turn positive.