A gas engine generates power by burning fuel and air. Part of the power that it generates is consumed by the accessories attached to the engine via the serpentine belt. An AC compressor consumes about 3–4 horsepower to run.
So yes, a small part of the horsepower is consumed by the AC system. That means that some small portion of gas goes into producing that power that would otherwise not be used without an AC system.
Also on really hot summer days the AC system may cause your engine fan to turn on when idling or at low speed because of excessively high temperatures and pressures in the AC system.
That will require more power from the alternator and may kick your vehicle into a high idle to handle it which would also consume more fuel.
However, today’s automobiles are generally so aerodynamically efficient, at highway speeds if you open a window it’s akin to tossing a small drag chute behind you. That carefully engineered airflow over your car is disrupted, causing increased drag.
Engineers have demonstrated that running A/C in a modern car generally saves you gas than just opening a window. Especially when you are moving at a slow pace of 20km/h thus the faster you go, the greater the savings.