What wire gauge is required for a 220V air compressor?
Since it's on a 40 amp breaker I would use #8 THHN.  5HP is only 3750 watts (1 HP = 750 Watts (rounding up)) so you are only pulling less than 18 amps when running.  Start up amps will be around 36 amps (rule of thumb) so that should be covered by the 40 amp breaker.  You can also use @Tester101 suggestion also.  

If this is an expensive piece of garage furniture you might make sure that magnetic starter has heater protection and phase drop protection, which will even work on single phase which will shut down the motor if one of the legs drop out.  Heaters are over current protection.  This sort of depends on the compressor because the starter could cost more than the compressor.