The way this works in the RAW is that in order to hide you must have Full Cover. Which means you need to be completely out of sight. You need to be behind a wall or an obstacle large enough that it completely covers you(except in certain circumstances like one of the Halfling subraces who can hide behind creatures).
Once you have Full Cover, you can then make a Stealth check as an action(or a bonus action if you have the Rogue ability). That roll is opposed by the Passive Perception of everyone would could possibly hear or see them. They are now considered to be "Hiding" from everyone that they beat. They've failed to hide from anyone that they don't beat and those creatures can hear/see them normally(which is to say that they still can't SEE them because they are behind Full Cover. But they have a good idea of where they are because they can still hear them).
Once you are hidden from a creature, you stay hidden from them until you no longer have cover or concealment from the person you are hiding from. If you are no longer hidden, you need to start the process over again. Attacking someone also ends Hiding.
This means that if you are in the middle of a battle, you can leave the room and put a wall between you and the enemies. That gives you full cover. You can then Hide. If you beat the Passive Perception of all the enemies, they no longer know EXACTLY where you are. They can guess, however. They did see you leave the room. They just can't hear how far down the hallway you've gone. If one of the enemies walks into the hallway, they immediately see you since there is no longer a wall between you and them and therefore you don't have any cover or concealment and are no longer Hidden.
However, if you move out of the room into the hallway, you hide and the hallway is filled with smoke(or it is really dim light and the enemies don't have Darkvision), you can continue hiding even when the enemies walk into the hallway. You no longer have Full Cover but you do have Obscurement. The same thing is true of small amounts of cover. If there is a barrel that isn't big enough to completely cover you but blocks enough of you to count as "cover" then you can continue hiding while behind the barrel. The idea being that it is POSSIBLE for the enemies to see you but you are staying in the shadows and moving very carefully in order to avoid being seen. Since they have no idea where your starting location is(since you were hidden while you had Full Cover), they can't find you. But once again, if that smoke clears, someone turns on a light or someone walks around that barrel, they see you immediately. Also, if the Rogue walks up to one of the enemies and attacks then they know where he is now. He's no longer Hidden and therefore needs for find Full Cover again before he can hide again.
Passive Perception is always 10 + Perception. So if a monster has a Perception of +4 then their Passive Perception is 14. If Perception isn't listed on a monster then just use their Wisdom modifier.
The key thing to remember is that Full Cover thing. If a Rogue walks behind a barrel that is half their height, they can't hide. The monsters watch him walk behind the barrel and crouch down. They know exactly where he is and they can still see him. The idea is that in order to hide from someone they must not currently be able to see you.