We can try to find the number of cases where use of a gun saved a life (meaning a life that would have otherwise been lost to a crime).
We start with the opposite: The number of lives that were not saved. In 2017, there were about 15,000 victims of "murder and non-negligent manslaughter" in the USA. (That's homicide, not gun victims. And the 40,000 gun deaths that you read about is to a huge extent suicide, accidents, or in some way justified killing.)
Elsewhere it was quoted that "official statistics show that a firearm was used by a victim to protect themselves in 1.1% of the cases of violent crime". If we assume the same rate for homicide, that would be about 165 lives saved.
That number will not be accurate. The 1.1% was "use of a firearm", it doesn't say the numbers of "successful use of a firearm". Murderers are usually more dangerous than pickpockets, so it would be possible that people draw a gun to protect someone from a pickpocket, but would run away instead of protecting someone from murder. Or it might be the other way round, that more people draw a gun to protect someone from being murdered than from having their wallet stolen.
Drawing a gun is always dangerous. If the choice is "draw a gun or be killed" everyone would draw a gun. If the choice is "draw a gun or have your wallet taken" many would hand over the wallet, because drawing a gun risks a dangerous escalation.
There's also the question how many of the 15,000 are victims of "violent crime" where someone might have protected them with a gun. For example, Harold Shipman murdered about 200 people in the UK as a family doctor. Guns wouldn't have helped, because nobody knew what he was doing. So we would need to know how many of the 15,000 never were in a situation that they considered dangerous, but were poisoned, murdered in their sleep and so on. And then there is the number of cases where someone drew a gun but was killed anyway.
All in all, I think the number 165 is something of a guess, but not totally unreasonable. And getting statistics about the real numbers is practically impossible, because by definition all these cases were not homicide - if I use a gun successfully to prevent a murder, then it's not murder anymore but attempted murder.