They obviously don't offer 100% protection. Though I've heard a nice analogy by Christian Drosten on the popular German coronavirus podcast:
Imagine you are standing close to someone at a party who starts talking to you. You immediately notice their bad breath (~aerosols). Now imagine they are wearing a mask, then imagine you both are. How much of the bad breath would you still notice in each case? That's the effect of masks.