A rattling noise emanating from your handlebars usually means a loose headset. To adjust your threadless headset, you undo the top cap bolt followed by the two stem bolts, and then replace the top cap bolt and tighten it. Once there is no more 'play' in the headset (as determined by holding the brakes and rocking the front of the bike backwards and forwards feeling for a graunchy/clicking sensation), tighten your two stem bolts and then ride away.
SOUNDS SIMPLE! As it turns out, there are ways to fuck this up. One way, I have learned to my personal cost, is to over-tighten the top bolt through being unsure of how tight it actually needs to be. The answer is that it doesn't actually need to be tight at all - only tighten it until the play disappears. The top cap bolt is not for stabilising or securing anything, it's only for pulling your forks into position so that they can be bound into place with the two stem bolts. The stem bolts, on the other hand, should be tightened "to the correct torque" because they are for stability. (NB don't tighten them so much that you can't loosen them again. I don't have a torque measuring thing so I do them up to what I believe to be subjectively tight, and I have not yet died.)
If you tighten your top cap bolt too much, this happens:
This is the remains of a star-fangled nut. The rest of the star-fangled nut is stuck in my steerer tube. I have smashed that down with a mallet since I couldn't get it out. The star-fangled nut is designed to resist the top cap bolt's upwards pull and draw the front forks up towards the stem. If you over-tighten the top cap bolt, you'll end up popping your star-fangled nut like this. So yeah, don't do that.
The good news is that this technique can be used to purposefully remove a star-fangled nut if you need to, but I didn't think of this at the time hence the mallet action.
Bonus n00b tip: you don't actually have to replace a star-fangled nut with another star-fangled nut. Hope do a contraption called a Hed Doctor that uses an expanding bung instead of a poppable nut, and it's pretty much idiot-proof.
Bonus n00b tip #2: a rattling sound emanating from your handlebars isn't always the headset! There's a chance it could be related to the horrible job you did of taping your bars where you fit the bar ends on afterwards but didn't quite secure them properly.
The image of the threadless headset above was stolen, shamelessly, from Sheldon Brown's excellent website