The first was made the second year after the nation had left Egypt, and the second was made 38 years later, when the new generation was about to enter Canaan. These numberings were not of the entire nation, but only of the men able to fight.
Numbers is the wilderness book of the Old Testament.
It describes the failure of the nation at Kadesh-Barnea, and their wanderings in the wilderness until the unbelieving old generation had died. Only Caleb and Joshua of the older generation were permitted to enter Canaan, because they had trusted God and opposed the decision of the nation to turn back at Kadesh-Barnea. Even Moses was forbidden to go into the Promised Land because of his sin when he smote the rock instead of speaking to it. Genesis is the Book of Beginnings, Exodus the Book of Redemption, and Leviticus the Book of Atonement and Worship. Numbers, on the other hand, is the Book of Testing.