Often I can tune it out, I spend a lot of time blocking noise around me and mentally muting it (and frequently thus do not hear when people address me). If it's so bad I can't tune it out (often at work if other people are getting noisy) I listen to music on my headphones... the kind that cover the ears, they block more noise. I wear them sometimes when I'm not listening to music at my desk too, just to muffle things further and so people will assume I can't hear them if they call me and I don't respond.
Sometimes, if it's really bothering me, I also just leave the area if there are a lot of noisy people to return after they have calmed down and I have collected myself.
Earplugs are good too... more when sleeping. They don't block all noise but they muffle it. The silicon waxy ones are best.
Obviously, if it's something you can end I do that too. Aside from loud clamourous noises like many people talking, whiny electronic noises really bug me. There used to be a light over my desk that would start making this noise, and I kept a long poking device nearby to wack it whenever it happened, which would usually cause it to stop.