The Children of Israel camped around Mount Sinai for over a year while God endeavored to change them from an extended family looking backward toward Egypt and the people who held them in bondage into a nation looking forward toward the Promised Land where the holy God Jehovah would grant them freedom. Funny thing about freedom: it doesn't mean freedom to do whatever the individual desires. It means order, decency, and following righteous standards. Only by obeying the directions established by God would they be truly free. Otherwise, they would become enslaved by the same wickedness and diseases endured by the nations that God was removing from Canaan while installing the Israelites in their place.
The book opens with a census. That's how this particular book of the Pentateuch received its name. There are several sub-census passages as well that dealt with assignments for the different Levitical family branches. There was much work to be done and God organized and delegated responsibility over each detail. God is not the author of confusion but of order (I Corinthians 14:33,40)! These were the reason for the year's stay at Sinai. They needed to be educated in God's school of order and decency.
While still at Sinai the Israelites celebrated their first Passover in the wilderness. Then after receiving further instructions they departed from Mount Sinai and began the last leg of their journey.
Things went downhill from there. God tested them several times to see if they would obey Him. They did not. Almost everyone failed one test or another: the people, Miriam and Aaron, 10 of the 12 spies, Korah and his family (of the Levitical tribe), and even Moses himself.
These failures lead to various punishments, all of which proved that the wages of sin is death (Romans 6:23a). Everyone who willfully disobeyed died. This lead to a second census in the book, the one taken of the children that had reached adulthood during the years of wilderness wanderings. Even Mose was forced by his own sin to make preparations for transferring leadership to Joshua, one of only two spies that passed his test when sent to reconnoiter the land and its inhabitants, as Moses would not be allowed to cross the Jordan River into the Promised Land.
Therefore, the events at the beginning of Numbers happened at Mount Sinai one year after the Exodus from Egypt. The events at the end of the book happen about 39 years later as the younger generation prepared to inherit the land that God promised their progenitor, Abraham, almost 400 years earlier.