When it comes to spreading infections, masks work in two ways: they protect you from other people and they protect other people from you.
If only one person wears a mask then a mask will only perform one layer of defense. But if both people wear a mask, then these two layers will reduce the chances of infection immensely.
Let's say we have a mask that is 80% effective. This means that if only one person wears a mask, the chance of getting infected is 20%. But if both people wear a 80% effective mask, the infection chance drops down to just 4%!
There's some very clever, yet simple maths behind this logic, which you can explore in the links below:
In this link, you can experiment with different scenarios yourself: https://aatishb.com/maskmath/ (scroll down to Maskology)
If you want to learn more about how this works, you can watch this short, yet very comprehensive video: https://www.youtube.com/watch?v=Y47t9qLc9I4