There are masks that protect you against getting infected ─ provided that you also maintain all other precautions, such as frequently washing and/or disinfecting your hands, maintaining a safe distance from others and not touching your face ─ but those masks are hard to come by. They can be identified visually by the ostensible filter in front of the mouth.
Most other masks ─ i.e. the surgical type commonly seen ─ do not protect you against getting infected, but instead are meant to protect others from being infected by you.