What i'm wondering is, where do good dynamics come from? That maybe sounds like a stupid and really basic question, but I'm seriously wondering about that.
If i have a good mixdown, do i have good dynamics as a result? Or do the dynamics just come from mastering?
"Good dynamics" is obviously subjective, so it's a bit hard to give any answer.
What I define as "good dynamics" is that stuff that's supposed to be quiet is quiet and stuff that's supposed to be loud is loud. For something to be dynamic there has to be a change somewhere, if not everything's the same (= no dynamic).
So, with that definition out of the way, the short answer to your question is this:
Dynamic range can not be increased at the mastering stage, only reduced. So if your track is lacking in dynamics (and assuming it's not because you've put five limiters on your master bus) you must fix it in the mix (dialing down your channel/bus compression, automating volume to change the focus of your mix throughout a track and so on).
If however you wish to decrease your track's dynamic range, you can (and should) do that both in the mix and at the mastering stage. Added compression at the mastering stage is a good way of gluing a mix together and achieve a more compact (and perceived louder) sound, just don't overdo it.
However, if you want good and loud sound, most of the work is done while mixing and arranging your track. That means prioritizing what parts of the track should have focus and which parts are less important (volume faders primarily, and then panning to some extent), removing unneeded frequencies from sounds (eq) and adding dynamic compression for sounds *that need it* (vocals typically need a lot, a sine sub nothing at all).
It's simple in principle, frustratingly hard in practice
My absolute "favorite" example of shit dynamics is Madonna's Hung Up:
https://www.youtube.com/watch?v=EDwb9jOVRtU#t=216 (can't embed with time bookmarks)
I've cued up the link at the start of the middle breakdown, which is obviously followed by what is supposed to be a huge drop. Arrangementwise it's done right, absolutely by the numbers. The track is stripped down, and elements are added back for a proper crescendo before the beat kicks back in.
However, by the time the beat kicks back in the sound pressure is already so "loud" that there's almost zero dynamic effect from the drop. If done properly, there should a solid lift in sound pressure (and therefore energy on the dancefloor) when the beat kicks back in, but since the mix is already so busy it sounds like some quiet clicks in the background.
Dynamics is obviously not all about drops, I just love using that track as an example because the mix totally fails in working with the arrangement when it comes to accentuating what should be the high point of the track.