The DM decides when circumstances are appropriate for hiding. When you attempt to hide, make a Dexterity (Stealth) check. Until you are discovered or stop hiding, that check result is contested by the Perception score of a creature who might discover you.
You can’t attempt to hide from a creature that can sense you clearly, and you give away your position if you make noise, such as shouting a warning or knocking over a vase.
A creature with the invisible condition can always attempt to hide and has advantage on Dexterity (Stealth) checks to do so.
In combat, most creatures stay alert for signs of danger, so if you come out of hiding and approach a creature, it typically senses you. However, under certain circumstances, the DM might allow you to stay hidden as you approach a distracted creature, granting you advantage on an attack roll (see Unseen Attackers and Targets in the Combat & Turn Based Action section).
In most monster or NPC stat blocks, a creature has a Perception score (also known as their Passive Perception). Whether a monster is actively searching for you or just going about their business, the DM compares your Dexterity (Stealth) check result to the creature’s Perception score to see whether they notice you.
A big factor in determining whether you can find something is how well you can see. Visibility in an area could be lightly or heavily obscured (see Vision and Light for more information on this topic).