People have claimed that the two accounts of Jesus birth in Matthew and Luke are very different stories. Whilst it is true that they are two accounts from different authors who are focusing on different things I think that is possible to reconstruct the timeline from the available information.
Mary and Joseph were espoused, betrothed but not married fully. At this time they are living in Nazareth.
The angel Gabriel comes to Mary and informs her that Jesus was to be born.
Mary leaves her home and travels to see her cousin Elizabeth who is at this time six months pregnant.
Mary remains with her until John is born.
Mary returns to her home and her condition becomes known to her betrothed. Joseph knows he's not the father and decides to put her aside quietly, rather than make a public disgrace of her.
An angel comes to Joseph in a dream and tells him that the child is not the product of adultery and that taking Mary as bride is not something to be feared. He does so.
A census (Bethyada suggests that "registration" is a better description of the event) is declared by the Roman governors and enforced by their puppet government. Joseph and Mary go to the town of Bethlehem which is the home town of the House of David which both of them belong to.
They do so, and take up residence in the house of another member of their family. Remember that in that culture it is a vile insult to refuse accommodation to a clan member, and equally insulting to reject such an offer. Misunderstanding the word used for Inn, in Luke, has led to the picturesque view of Jesus being born in a stable, but since Bethlehem was probably too small to have an inn and it would have been insulting to sleep in such a place when a family home was available this option is highly unlikely. People lived with their animals in a downstairs family room, and it was probably this room in which Jesus was born because the upstairs guest room is full.
The shepherds come to visit the house this night.
Eight days after this Jesus is circumcised.
After the period of Mary's purification (14 days) Mary and Joseph take him to the temple and offer the two doves that are the sacrifice of the poor.
At a point after this, probably not too much later, the Magi from the East (probably Babylon) came to visit Jesus and give their gifts. (Bethyada also points out that it wasn't necessarily Babylon, Susa is another candidate, and the period that they visited encompasses from shortly after the birth to about 18 months later; we do have the testimony of Herod that he was less than two by the time the king decided to kill the boys)
The Magi leave, not informing Herod of their discovery.
Herod orders his soldiers to kill all males in Bethlehem under the age of two, and at this point Joseph, Mary and Jesus are heading for Egypt.
Herod dies, and the family return to Nazareth.
It may not be a perfect reconstruction, but it seems to place the events in the correct order.