Ships placed in hangar actively participate in combat: they attack, receive damage and can be destroyed by direct fire just like any ship in fleet. This means that putting fighters in a battleship's hangar does not "protect" them from projectile damage.
However, there is a second casualty mechanism exclusive to the hangar: losses due to destroyed hangar. When carriers die, the available hangar capacity is reduced. If the remaining capacity is less than the number of transported ships still alive, some of those ships are also lost.
Hangar loss mechanic
Start
10 Titans with "Fighter Hangar Z" and research level 10 (≈ 380 fighters each = 3,800 total) with 3,000 fighters in hangar.
Combat
6 Titans are destroyed → remaining capacity = 4 × 380 = 1,520 fighters. By direct fire 400 fighters have already died → 2,600 fighters remain alive.
Hangar loss
2,600 live fighters do not fit in 1,520 capacity. The system calculates the proportion and destroys ~1,080 extra fighters due to lack of hangar space.
Final total
4 Titans and ~1,520 surviving fighters.
There are two important exceptions where ships in hangar do not suffer additional losses from this mechanism:
Defender with available planet
If you defend an attack, conquest or planet destruction, ships in hangar do NOT receive extra losses due to capacity. The planet acts as an emergency hangar.
Ships with advanced hyper engine
Ships with high-level hyper propulsion (hyper speed ≥ 5) ignore additional hangar losses: even if their carrier is destroyed, they are not lost due to lack of capacity, but the fleet's return speed is calculated based on the slowest ship's speed.
When you attack with a fleet carrying ships in hangar, if your carriers are destroyed in combat, the ships they carried may be lost proportionally. Design your carriers with enough armor or protect them with escort groups.