You control the game world. You prepare it, design it, and present it to your players. They then get to tear it to shreds. No matter what you prepare for, your players will absolutely surprise you. Embrace that, and you'll be a happier DM. That does mean you'll need to be prepared for anything, however.
Before playing a game, you'll need a few things prepared. You need:
The idea is that you will present the players with hooks that can drive the story you prepare, but you have enough leeway such that the players guide how they follow that hook. You don't want to "railroad" the players by forcing them down the plot you've decided on. They tell their own story, you just provide the skeleton. I advise you have plenty of backup traps, combat encounters, and random NPC interactions to help you improvise when the players inevitably split from your expectations so you don't need to railroad them.
When designing a combat encounter, there is a formula that helps balance the players with the monsters. You'll want the fight to feel challenging (usually) but not a cakewalk. You also don't want to outright murder the player characters by throwing, say, a frost giant at a level 5 party. The formula is as follows:
That last part is the tricky part. You determine party thresholds by adding their player level's associated numbers. These can be found in a table in the Dungeon Master's Guide. You determine the monster's thresholds by totalling their XP and adding modifiers for the amount of enemies, more enemies at once can quickly become a much bigger problem for the players.
This is a very basic run-down of this process, the details are copyrighted by Wizards of the Coast and can be found in their published Dungeon Master Guide.
The easier, but much worse way to determine how difficult an encounter is is to look at a monster's combat rating, or CR. The CR is meant to give a DM an idea of how difficult a monster would be. For instance, a monster with a CR of 5 should be a challenge for a party of 4 level 5 player characters. This unfortunately is rarely accurate and you'll most likely end up with a total party kill, or TPK, if you rely solely on CR.
So you have your prep done, what about actually running the encounter? When you call for initiative, you'll need to keep track of the turn order. Making sure to not skip any monster or player's turn is very important, as missing turns can break the illusion of the game. You need also to track monster health and other finite resources they may have, such as spell slots. You'll need to keep an eye on the placement of creatures on the battle map and keep things feeling dynamic. Lastly, you want to run every monster's turn as best as you can for the monster. You aren't playing against your players, but that bugbear sure is. Don't go easy on your players, if you designed the encounter well, they won't all die.
If you designed the encounter poorly, and you can tell mid-battle things are going very wrong, you can make minor adjustments behind the screen. You can fudge a dice roll that might have critted a player, or bring down an enemies max HP by a bit. Just be careful to not make big changes that the players catch onto, because that too will break the illusion of the game.
There's a lot to running a campaign of DnD. It can seem overwhelming, but the secret is that all Dungeon Masters feel some amount of anxiety when they run the game. Talk with your players, ask if they're enjoying it. Almost certainly they'll tell you they're having fun. You're here to bring a game of DnD to life for your friends, so don't panic, sit back, and enjoy the game.
A great source for DMing tips is Matt Colvilles Running the Game series on Youtube. Another great source is the r/dndbehindthescreen subreddit.