I have always understood mixing as getting the right levels on each of the tracks in a song so every element sounds balanced and not out of place
This is good.
Say a song peaks at -3dB that means theres 3dB of headroom but that song could be much louder than another one that also has 3dB of headroom. How is this possible?
There's a difference between song peaks and loudness. A song can peak at -3db but that doesn't mean that the average level of the song is always -3db. RMS levels and transients play a factor as well.
How should I go about mixing songs so that they are loud?
I can give you only a little bit of insight when it comes to this. The high mid frequencies are perceived as being much louder than the bass frequencies but don't take up as much headroom. Make sure that you're low cutting every instrument that doesn't need that low end because they just take up valuable headroom in your mix. If you're using reverbs make sure to EQ them to get rid of that low end mud. Finally use compressors to get rid of any unnecessary transients/peaks on your instruments.
some things I've made max out at 0dB and are quiet compared to other things I've made that max at -3dB.
That's because peak level does not equal RMS level.