In The Last of Us, survivors wear gas masks to avoid breathing in the spores found in enclosed places, such as a basement, to avoid becoming infected. Joel always has a gas mask on him, and will put it on when he enters a spore infested place. Ellie does not need one due to her immunity.
The Gas Mask is first seen being used a by a soldier when Joel and Sarah attempt to reach the highway. It is first obtainable in The Quarantine Zone, where Joel obtains one along with his backpack and 9mm Pistol. As Joel travels across the United States, he will find spore infested places that he must cross in order to advance through an area. To avoid breathing in the spores, Joel puts on his gas mask when crossing through. Some of his allies will wear gas masks should they be near spores, such as Tess and Bill although the latter didn't necessarily require as he was in the uncontaminated outside air.
Some enemies that wear them have Molotov Cocktails. This can be an early warning to the player and should always be targeted first, if possible.
Most masks appear to be a variation of the S10 Gas Mask, without the top straps and the lenses tinted green. Joel uses the right attachment for the filter (the S10 having attachments on both sides) even though he is right handed, which is not useful aiming with long ranged weapons. The filter is not a standard S10 filter.
However, other masks resemble the M40 gas mask that is used by the United States military. Some survivors, notably Bill wear this model instead of the S10. It is useful in as it allows the wearer to drink from a canteen without removing the mask.