These are the rules from the PHB and Sage Advice Compendium accumulated, and reordered a bit to put similar concepts together. To me, this spells out a reasonably clear approach (although a clarification on how observation applies would make it more clear), and makes clear what advantages the halfling, elf and skulker get from their ability (which primarily related to observation).
Assembling this has changed my views on hiding, stealth and perception a small bit.
General Rule: The DM decides when circumstances are appropriate for hiding. When you try to hide, make a Dexterity (Stealth) check. Normally, you can’t hide from someone if you’re in full view.
Actively searching creatures: 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. [Note: While not explicit in the book, Sage Advice and Interviews by Crawford indicate that passive perception is intended to be a floor for this role.]
Not actively searching creatures: 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 DM compares your Dexterity (Stealth) check with that creature's passive Wisdom (Perception) score, which equals 10 + the creature's Wisdom modifier, as well as any other bonuses or penalties. If the creature has advantage, add 5. For disadvantage, subtract 5.
Giving yourself away: You can't hide from a creature that can see you clearly, and you give away your position if you make noise, such as shouting a warning or knocking over a vase. However, under certain circumstances, the DM might allow you to stay hidden as you approach a creature that is distracted...
Bright light: Bright light lets most creatures see normally. Even gloomy days provide bright light, as do torches, lanterns, fires, and other sources of illumination within a specific radius. Normally, you can’t hide from someone if you’re in full view.
Dim light and light obscurement: Dim light, also called shadows, creates a lightly obscured area. An area of dim light is usually a boundary between a source of bright light, such as a torch, and surrounding darkness. In a lightly obscured area, such as dim light, patchy fog, or moderate foliage, creatures have disadvantage on Wisdom (Perception) checks that rely on sight. A target has half cover if an obstacle blocks at least half of its body. A target has three-quarters cover if about three-quarters of it is covered by an obstacle.
Darkness and heavy obscurement: Darkness creates a heavily obscured area. Characters face darkness outdoors at night (even most moonlit nights), within the confines of an unlit dungeon or a subterranean vault, or in an area of magical darkness. A heavily obscured area--such as darkness, opaque fog, or dense foliage--blocks vision entirely. A creature effectively suffers from the blinded condition when trying to see something in that area. A target has total cover if it is completely concealed by an obstacle.
... and Invisibility: An invisible creature can always try to hide. Signs of its passage might still be noticed, and it does have to stay quiet. [Unless hidden,] the creature's location can be detected by any noise it makes or any tracks it leaves.
In combat: In combat, most creatures stay alert for signs of danger all around, so if you come out of hiding and approach a creature, it usually sees you. However, under certain circumstances, the DM might allow you to stay hidden as you approach a creature that is distracted, allowing you to gain advantage on an attack roll before you are seen. Combatants often try to escape their foes' notice by hiding... 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 when the attack hits or misses.
On halflings and elves and skulkers: The lightfoot halfling and wood elf traits do allow members of those subraces to try to hide in their special circumstances even when observers are nearby. Normally, you can’t hide from someone if you’re in full view. A lightfoot halfling, though, can try to vanish behind a creature that is at least one size larger, and a wood elf can try to hide simply by being in heavy rain, mist, falling snow, foliage, or similar natural phenomena. [As a skulker, you can] hide when you are lightly obscured from the creature from which you are hiding. When [a skuler is] hidden from a creature and miss it with a ranged weapon attack, making the attack doesn't reveal [its] position.
Contested checks: Until you are discovered or you stop hiding, [your stealth check] is contested by the Wisdom (Perception) check of any creature that actively searches for signs of your presence. If the contest results in a tie, the situation remains the same as it was before the contest.
When I add that all up:
When I want to hide, I ask the DM if circumstances are appropriate. The DM can overrule anything below, but my expectation is that the following will usually be true. Then I have to roll a stealth check. As I am not hidden yet, to enter hiding I must exceed the relevant perception rolls (active or passive as circumstances indicate).
If I am in bright light, I may only hide with DM permission.
If I am blocked by 1/2 or 3/4 cover or in light obscurement (where opponents have disadvantage to perception checks related to sight - which indicates that they can't see me clearly); and, in addition to one of those situations, I am not being observed (as you can't hide while in full view), I can generally hide.
If I am a wood elf, lightfoot halfling or skulker, the prohibition on being observed is lifted in some circumstances. As long as a lightfoot halfling can find cover from a creature, it can hide, but loses the hidden condition if it loses the cover (and is not otherwise in any obscurement/cover). The wood elf can hide while obscured by natural phenomena, even when observed at the time. A skulker can enter hiding even when observed so long as they have any light obscurement. In addition, I would hope that the DM would be more permissive for my lightfoot/wood elf/skulker in allowing me to hide in their stated conditions than the DM would be for other PCs - I'd get more benefit of the doubt in judgment calls.
If I am in heavy obscurement (which prevents observation entirely), I can generally hide. If I am invisible to the target I can generally hide. This also applies if someone is concealed by total cover.
If a creature wants to take an action to find me when I am already hidden, they must exceed my stealth check with their perception check.
If I lose obscurement or cover, I lose hiding unless the DM decides that I do not. However, if I hide in heavy obscurement and then move to light obscurement, I do not lose my hidden condition. However, me attacking generally ends my hidden condition.
So, Bob hides while benefiting from total cover (behind a corner) from Tim. He sneaks around the corner into dim light and remains hidden. Then he attacks, revealing his location. He is now observed. He can't hide again in the dim light, as he is now observed, unless he is a skulker, is a halfling and moves behind a creature, or is a wood elf and there is natural phenomena present (heavy rain?) - unless the DM decides to allow it. However, he could go around that corner or find other total concealment / heavy obscurement and hide then.