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.
A soldier wears one when Joel and Sarah attempt to reach the highway. The player obtains one in The Quarantine Zone, where Joel collects it, 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.
Soldiers in the Boston QZ wear them as well when outside the protection of the walls, namely Ramirez, while a special HAZMAT section of the military wear gas masks along with other protection when searching infected buildings for civilians.
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. This useful feature allows the wearer to drink from a canteen without removing the mask.