DnD 5e - Initiative
Initiative determines the order of turns during combat. When combat starts, every participant makes a Dexterity check to determine their place in the initiative order. Players roll for themselves, and the Dungeon Master rolls for other creatures.
The DM ranks the combatants in order from the one with the highest Dexterity check total to the one with the lowest. This is the order (called "initiative order") in which they act during each round. The initiative order remains the same from round to round.
If a tie occurs, the DM decides the order among tied DM-controlled creatures, and the players decide the order among their tied characters.
The DM can decide the order if the tie is between a monster and a player character, but I don't encourage this. Deciding in favor of the monsters can feel hostile, and deciding in favor of the players can feel like cheating. Instead, look for an objective way to determine the outcome. The Player's Handbook suggests rolling a d20 and letting the highest roller go first, but you might also choose to let the creature with the highest Dexterity score go first, or you might use some other method that removes the requirement for the DM to decide.
The Player's Handbook states that the Dungeon Master rolls just once for an entire group of identical creatures (4 goblins, 10 rats, etc.), but I recommend breaking this rule under some circumstances. Putting numerous identical creatures into a group is a great way to speed up combat, but it also means that the players might take a series of turns then immediately take a horrifying amount of damage when most of the enemies in an encounter act back-to-back.
Instead, I recommend splitting identical monsters into multiple groups. The size of these groups will vary depending on how many of those creatures are in an encounter, but splitting them up allows the players to respond between groups of enemy attacks.
For example: If the players are fighting 6 orcs, having the 6 orcs act at the same time will make combat take less real-world time, but those orcs will do a lot of damage all at once and the players won't get a chance to respond. If the orcs roll poorly on their initiative roll, the players might kill all 6 of them before they can act. Splitting the 6 orcs into two or more groups makes the orcs' position in initiative less impactful, and it makes it less likely that you'll accidently kill a player character while the party sits on their collective hands. Use your best judgement to organize the groups. I recommend grouping adjacent or nearby groups of creatures, and have those creatures fight alongside each other to simplify keeping track of them.
Joining Combat Late
There are no official rules for what happens when a creature enters an ongoing combat after initiative has already been rolled. It's a rare occasion, but it has happened to me enough times to know that there should be rules for it, so here is how I handle it:
When a new creature enters an ongoing combat, determine if they are Surprised. Then, roll initiative for them as normal. They join the initiative order at the end of the current round, and take their first turn in the following round.