To find wire gauge from amps, pick the smallest AWG whose ampacity at your insulation temperature meets the current. At the 75°C column, copper carries 20 A on 12 AWG, 35 A on 10 AWG, 50 A on 8 AWG, 65 A on 6 AWG, and 85 A on 4 AWG. So a 40-amp load lands on 8 AWG copper (50 A), leaving 10 A of headroom.
This wire ampacity calculator stores all three NEC temperature columns for copper and aluminum, so you can compare how much a hotter-rated insulation or a different metal changes the answer. Remember: ampacity is the raw limit — for continuous loads, apply the 125% rule (use the wire size calculator for that), and always size final terminations at 75°C.