Within includes all 40 minutes. If you mean close to the end of 40 minutes, in is the better preposition.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.
Anonymous i will be back within 40 minutes.Be back where??? If you mean you'll be back online, or call someone back, you should specify that. If the context makes it clear that you are at home now but will soon be back at the office, for example, then it's okay. Without context it's confusing.