You need to know the neutral load from the panel. Its minimum size for the a 40 amp feeder would be 10 AWG copper, but the neutral load could require the neutral to be full size. You need to do do a load calculation for the neutral load.
This is for a project that’s already been done we have a pool sub panel with 2- 240 motors with a draw of 26amps And 2-120 circuits with a draw of 5 amps. The inspector says the #10 neutral is not sufficient and needs to be a #8