At the start of combat, everyone rolls initiative — a d20 plus their Dexterity modifier. The Dungeon Master ranks all combatants from highest to lowest, and that initiative order repeats every round until the fight ends.
On your turn you can move and take one action, plus a bonus action and any reactions when they apply. Ties are usually settled by comparing Dexterity scores, or the DM decides; some tables let the tied players simply choose who goes first.
A few things change the roll. The Alert feat boosts initiative — a flat +5 in the 2014 rules; the 2024 version instead adds your proficiency bonus and lets you swap places with a willing ally. Being surprised means you can’t move or act on your first turn, though you still hold your spot in the order.