Ritual naming and circumcising took place when a male child was eight days old. A separate ritual occurred after the purification time for the mother. If a mother gave birth to a male child the purification time was forty days and for a female child it was eighty days. Thus forty days after the birth, Joseph and Mary traveled the five miles from Bethlehem to the temple in Jerusalem to attend to the purification ritual. The fact that both rituals were performed tells us that Mary and Joseph were strict observers of the law of Moses.
But there is something very interesting going on here. In addition to the circumcising and purification rituals, a firstborn son was taken to the temple when forty days old to be presented to the Lord and according to the law redeemed at the price of five temple shekels (Numbers 18:16). The baby would be given to the priest and the priest would lift the baby up before the altar to dedicate him to the Lord. This reminded the people that thousands of years before God had saved the firstborn sons of the Israelites during the first Passover.
All of the laws of Moses were intended to teach the people and help them look forward with hope to the time when their Messiah would come to redeem His people. Circumcision and purification ceremonies reminded the people that their hope was not in generation but in regeneration, and on that ritual day the Infant being circumcised was not in token of regeneration or salvation; He was Salvation. He was not only the firstborn son of Mary being presented to God; He was the Son of God being present to His Father.
The Infant the priest held in his arms that day was not in token of the Messiah but He was the Messiah that hundreds of thousands of rituals had been performed to celebrate. He was the baby that would be our Salvation.