I've run into this a lot; in dorms, in a house with other mates from uni, at work, and so on.
Here are some things that work for me:
- If you can afford it, noise canceling headphones are awesome. If you put yourself in a quiet place, they help a huge amount. Expensive though.
- Always have ear plugs in your bag. They are small, and you can use them in a pinch. Super good for exam situations where things are quiet anyway and you just want to block out that guy who keeps clicking his pen.
- Go to a hardware store, and find the ear protection section. For 20-40$ you should be able to find industrial grade ear protection. This works really, really well; and lasts longer than ear plugs. These are more effective than bose noise canceling headphones, but less comfy and won't play music.
Note that all of the above will only lessen the sounds around you; if you are already in a loud place, it won't make it silent. Which leads me to my next piece of advice:
Go somewhere else. I still have to do this to this day. There is a quiet, distraction free place somewhere on campus where you can go. You have to find it though. I ended up with a collection of about 6 places that were generally super quiet.
You'll also want to find places that are distraction free in other ways too (eg. a desk in a basement at the end of a hall; there was nothing there but what I brought with me, and very few people ever came by). Try to avoid populous study areas; there are other distractions there. Extra good if you can find somewhere that's not too far from a toilet for those long study sessions. If I had to walk too far to find a bathroom, it would take me 10 minutes to get there, and 90 to get back on account of interesting everything.
Music that you can't process. In my case it was chinese pop music, or very loud punk rock. Experiment with different things, you'll probably find something that your brain considers passive background noise. Note that it's not enough to simply change the language or find something without words. I'll happily hum along to classical, and I have no problem singing along to bhangra music. I'd suggest looking at pop music from other cultures, or genre's that are known to be loud and noisy.
Watch the chemicals. Getting the right amount of caffeine is a tricky balance. Obviously it keeps you awake, which is a plus. But having a hit can help sharpen your mind to the work at hand a little bit. Having too much will end up being a huge distraction.
Have a refocus point. Eventually you're mind is going to wander, I found it was helpful to have something that brought it back. Some people use excercise, or a smoke break for this. For me, I printed a little sign that I would stick at eye level that read simple "GRADUATE". Whenever my mind went, this little sign would act as a mental kick in the pants. Most times I could pull it together and get back to the task at hand. Maybe after a few breathes, or something.
Know when to quit. If it's just not working; stop. Take a break (ideally, a limited break; like having no more than three printed sheets of sudoku in your bag), or just switch tasks and come back in a bit.