When God ordered the first census to be done after the Israelites left Egypt in the Wilderness of Sinai, it was found that all the men aged 20 years or older were 603,550 excluding the Levites. (Numbers 1)
When God ordered the second census to be done just before they entered the Promised Land while camping in the Moab Plains, it was found that all the men aged 20 years or older were 601,730 excluding the Levites. (Numbers 26:51)
Of the 603,550 men who were counted in the first census, only Caleb and Joshua were alive and counted in the second census.
So why did God spare Caleb and Joshua out of 603,550 men?
God had pronounced judgment on all those other men for He said, "They shall die in the wilderness" and so There was not a single man of those men except Caleb and Joshua (Numbers 26:65) who was alive and able to enter the Promised Land.
These other men had died because when they were told that there were giants living in their Promised Land, they begun doing the things that made them Miss their Promised Land.
These men begun crying and complaining against Moses saying it would have been better if they had died in Egypt. They also asked why God had brought them there to kill them by war and make their children victims in the wilderness. They even went as far as saying they were going to choose a leader to take them back to Egypt. (Numbers 14:1-4)
In the midst of all the crying and complaining of these men, Joshua and Caleb tried to encourage the other Israelites by telling them, "If God delights in us, He will bring us into this land and give it to us." Caleb and Joshua even went further and told them that the Promised Land was a land with Flows with milk and honey proving that God had told them the truth about where He was taking them. They tried their best to lift up the spirits of the Israelites by telling them that the protection of the people in their Promised Land had departed and God was with them. (Numbers 14:6-9)
However, those other men did not want to receive their report and they said Caleb and Joshua should be stoned (Numbers 14:10) but the glory of the Lord appeared before all the Israelites.
Therefore God spoke and said, "All these men who have seen My glory and the signs I did in Egypt and in the wilderness and have put Me to test these 10 times, and have not listened to Me shall not see the land I promised their fathers." (Numbers 14:22-23)
He continued, "But My servant Caleb I will bring into the Promised Land because he has a different spirit in him and he has followed Me wholeheartedly." (Numbers 14:24)
God also said, "The carcasses of those of who have complained against Me and who are 20 years old and above shall fall in this wilderness ." (Numbers 14:29) He made the exception by saying, "Except for Caleb and Joshua." (Numbers 14:30)
Therefore the reason that Caleb and Joshua were the only 2 men left alive and standing out of 603,550 men was because they had followed God wholeheartedly. They decided to believe God with their whole heart (have full faith) when He said He would bring them to the Promised Land regardless of the presence of giants and strong men and fortified cities.
The fact that God chose to spare 2 men out of a whole generation of men also teaches us the following things about God:
1. God does not forget people
God did not forget the men He has said would enter the Promised Land and He remembered those He had said would not enter it and it was so.
2. God does not forget His promises
God does not forget what He promises His people even if decades pass before those promises come to pass.