Ventilation. With the windows open, the air in the apartment became worse

Why?

About the shortcomings of natural ventilation systems

The example described in the title is not fictional. The situation where unclean air from the communal exhaust or common hallway enters the apartment when the windows are open is typical for spaces with passive ventilationPassive, or natural ventilation is when air inside a building moves due to natural pressure differences.
Active (supply-exhaust) ventilation uses a special pump to push air into the room.
.
Let's see how this happens.

Here's the main thing you need to know to understand the air exchange processes in a house. Air ALWAYS moves from a zone of high pressure to a zone of low pressure, and that's it. You can draw arrows on the project however you like, but if the pressure in the communal exhaust pipe or in the common hallway is higher than in your home, the air will not flow from you there, but from there to you.
Now let's analyze a few typical situations when the pressure outside your window is LOWER than the pressure in the exhaust pipe or common hallway, and consequently, when you open the window, instead of ventilating, you get a flow of stale air from common areas or even directly from neighboring apartments into your apartment:

  1. Wind load. Even with relatively weak wind, a building, especially a multi-story one, acts like an airplane wing, creating zones of high and low pressure around the solid body when airflow occurs. If at some point your bedroom window is in a low-pressure zone, and the ventilation outlet is in a high-pressure zone, it's quite logical that when the window is open, air from the ventilation pipe will flow into your apartment. Even with light wind, such pressure differentials can create serious ventilation problems. And with moderate wind, the upper floors of a skyscraper can deviate from the vertical by tens of centimeters due to pressure differentials.
  2. Uneven heating of the building by the sun. Here it's not just simple, but very simple: the southern wall always heats up more than the northern one, warm air rises along the heated wall, pressure drops (Bernoulli's law), and then it's the same as in point 1.
  3. Reverse draft. Details about this are in a separate article, but here I'll just remind you of the essence of the phenomenon. For example, on a hot summer day, if the air inside the building is cooler than outside, the ventilation pipe is inside the building (which is typical), and the air, passing through the ventilation system in the opposite direction, gets additionally cooled, then the whole system will work like a chimney, but in reverse. That is, the air from the ventilation will not go outside, but inside—straight to your apartment.

Installing a standard exhaust fan in the bathroom is unlikely to seriously solve any of the problems listed above.

And here's why. Those luxurious performance indicators listed in the instructions for most fans: 200 or even 250 m3 per hour, are achieved only with zero pressure differential.
The flow rate provided by such fans is almost always less than 4 m/s (check for yourself). Therefore, (Bernoulli's equation) a pressure differential of 2.6 Pascals (!) is enough to reduce the system's performance to zero. Most of the reasons listed above can easily create a pressure differential of 5 or even 50 Pascals. A weak kitchen fan simply won't handle that.

What to do if you're unlucky and the pressure differential in your home periodically works against you?

The radical solution with guaranteed results, unfortunately, is only one—full supply-exhaust ventilation. It's not cheap, you'll need to address issues with placing full equipment, noise levels, regular maintenance (at least filter replacement), and additional humidity control.
But believe me, it's worth it.