From D&D Wiki
In 5e, I find the rules for hiding and Stealth in general to be needlessly scattered. This page serves only to condense and paraphrase these rules.
To "go stealthy," or otherwise intentionally obscure your presence from others, you take the Hide action.
The GM determines when the circumstances are appropriate for hiding. As a general guideline, to take the Hide action you must be at least lightly obscured from the senses of those from which you wish to hide. A creature with total cover is obscured and can take the Hide action against creatures that rely on sight. An invisible creature can always choose to Hide from creatures that rely on sight. Certain features may allow you to hide more easily (such as a lightfoot halfling's Naturally Stealthy).
A feature may allow you to Hide as a bonus action instead of an action. Even so, this does not change the circumstances under which you may attempt to Hide. You still must be obscured or have total cover to Hide.
When you take the Hide action, make a Dexterity (Stealth) check. Until you are discovered or you stop hiding, that check's total is contested by the Wisdom (Perception) check of any creature that actively searches for signs of your presence. You can't hide from a creature that can clearly see or otherwise detect you. If you make noise (such as shouting a warning or knocking over a vase) in the presence of a creature that could hear it, you give away your position.
In combat, most creatures stay alert for signs of danger all around, or if you come out of hiding and approach a creature, it usually sees you. However, under certain circumstances, the GM may allow you to stay hidden as you approach a creature that is distracted, thereby allowing you to gain advantage on an attack before you are seen.
It is possible to be hidden to some creatures and detected to others. As a general rule, however, if one member of a group has detected you the entire group will know of your presence.
When you hide, there's a chance someone will notice you even if they aren't searching. To determine whether such a creature notices you, the GM compares your previous Dexterity (Stealth) check result with that creature's passive Wisdom (Perception) score.
A creature's passive Perception equals 10 + its modifier to Wisdom (Perception), along with any other modifiers to its Perception. If the creature would have advantage on a Wisdom (Perception) check, it gains a +5 bonus to its passive Perception; and if it would have disadvantage, it instead has a -5 penalty.
If you or your group is moving at a fast pace (at least 40 feet per turn, 40 mph, or 30 miles per day), the group has a -5 penalty to their passive Perception scores.
Moving While Hiding
If you move 20 feet or slower per turn (no more than 200 feet per minute, 2 mph, or 18 miles per day), you can continue to hide. Your GM may require even slower movement through difficult terrain or if your movement speed is 20 feet or lower. Presumably if you move faster than this, your hiding ceases.
When a number of individuals are trying to accomplish something as a group, the GM may ask for a group ability check. In such a situation, the characters who are skilled at a particular task help cover those who aren't.
To make a group stealth check, everyone in the group makes the Dexterity (Stealth) check. If at least half the group succeeds, the whole group succeeds. Otherwise, the group fails. The effective check result for the group can be whatever the median check result was between them.
If you engage in battle against enemies before they detect you, your GM may decide that you have surprised any number of them. (The same, of course, is true if enemies engage you before you detect them.)
The GM determines who might be surprised. If neither side tries to be stealthy, they automatically notice each other. Otherwise, the GM compares the previous Dexterity (Stealth) check results of anyone hiding with the passive Perception score of each creature on the opposing side. Any character or monster that doesn't notice a threat is surprised at the start of the encounter. A member of a group can be surprised even if the other members aren't.
If you're surprised, you can't move or take an action on your first round of the combat, and you can't take a reaction until that round ends.
Unseen Attackers and Targets
When a creature can't see you, you have advantage on attack rolls against it. If you are hidden—both unseen and unheard—when you make an attack, you give away your location and cease hiding when the attack hits or misses.
When you attack a target that is hidden from you, you have disadvantage on the attack roll. This is true whether you're guessing the target's location or you're targeting a creature you can hear but not see. If the target isn't in the location you targeted, you automatically miss, but the GM typically just says that the attack missed, not whether you guessed the target's location correctly.