I'm assuming your 40 gallon is 18"x36". That's about 650 sq. inches.
Here are some figure from my experience:
10 gallon, 200 sq.in for 1 gecko
20 gallon 360 sq.in. for 2 geckos
20 gallon with 12x12 second level 500 sq.in for 3 geckos
Based on that I'd recommend 4 geckos.
Remember, though, that the geckos may not get along and may need to be separated. Personally, I've done quite well with both permanent and re-combined groups but other people swear by keeping their geckos individually.
Aliza