How do I stop my toddler from masturbating?

It's normal. Masturbation is normal, so you can't stop it. You can set limits on when and where it occurs. For example, "i know it feels good to touch your privates, but that is something that you do when you are alone in your bedroom." if he persists, gently guide him to his room. Be consistent, not condemning. Discuss excessive masturbation with your doctor, it can be a sign of abuse.
Normal. Totally and completely normal: He's discovering his body, and discovering that rubbing his penis feels good. There's nothing wrong with that. By staying low-key about it, avoid making him feel bad .
You can't. This is normal. Your toddler is discovering his/her body.