Hiding in D&D

I found the mechancies for hiding1 in D&D 5E a little confusing to understand, as the rules are scattered in a few places in the book.

As an action (or a bonus action for a Rogue), a character can Hide2. They make a Dexterity (Stealth) check, with the total becoming the DC for other creatures to notice you. A character can’t hide if they can be clearly seen by other creatures, but they don’t need to been in full cover.

The DM compares the passive Wisdom (Perception) of other creatures to see if they notice the character. Creatures can also use the Search3 action, making a Wisdom (Perception) check to discover the character. In either case, success on the creature’s check means the character is no longer hidden.

A character has advantage on attack rolls against creatures that can’t see them4 - for a Rogue, this means they can use Sneak Attack. Once the attack hits or misses, the character is no longer hidden.

Some addition clarifications come from the game designers, but are not in the books:

The rules for unseen say “you give away your location”, but this does mean the character is no longer hidden 5

A character can be hidden from a creature even if the creature knows where they are6.

A hidden character can lean out or step out of cover to make an attack without being discovered7. They are still discovered when the attack hits or misses.

A DM might call that hiding in the same spot results in disadvantage on the Dexterity (Stealth) check8.