There is no right answer as each table will differ based upon DM style, player desires, etc... but here is what I do:
When I start to run a campaign, I start to build/prepare the next one. This allows me to be thinking about the 'level contextualized' issues while I am going through them.
If the new setting will be a new homebrew, I frame the world, the Deities, and the history in light detail. Essentially, I come up with a framework in which to add materials.
Regardless of what setting it is, I identify my core stories. If this is a pre-published adventure, some of those core stories are provided, but I always add onto the framework with a few of my own. I use the 'Babylon 5' model, with a major story that spans all levels, several stories that will cover entire tiers of play, and a lot of shorter adventures that will be completed within a few sessions. All I do is identify and write down a few thoughts on each. Then I look at how they relate and try to tie them together.
Then, I pick a starting location for the PCs and flesh it out to give them the starting block for the campaign. I'll go to a medium level of detail - enough that I could wing a session there at any time, but not to the level of specificity I like to have when I'm fully prepared.
Then I start talking to potential players to figure out who wants to play and what stories / characters interest them. I then start to fold those elements into the established storylines and setting pieces I have already created. I understand and expect that some of this will change - but it helps me to insert unique new angles to my game, so even if this stuff isn't pursued, it gives the world more depth. I am often doing this a year or two before the campaign kicks off.
At this point, I am ready to add meat to the framework. I'll build a few adventure options to start and prepare them as if the first level party will go there - and have notes on how to elevate the challenge should the party level a few times before arriving in that dungeon/situation. I'll write up the main NPCs and 'practice' with them to help me lock down a personality and place for them in the setting.
At this point, I keep the setting alive in my brain, but all I really do is make a few notes here and there on ideas I may use down the road - and perhaps tweak a few items and flesh out a bit more as inspiration strikes. I won't do detailed work on it any further until we do session zeros for the PCs the players will actually run. At that point, I've been living in the campaign in the back of my mind for a long time, and I am comfortable with it, which is a huge advantage in crafting a more immersive world.