In Matthew, Jesus is simply born in Bethlehem, and very soon after his birth, his parents flee to Egypt with him to avoid his being killed by Herod. After Herod's death, they return to Israel, but, to avoid Herod's son, they wind up in a town called Nazareth, a town with which, before that point, they apparently had no connection.
In Luke, he is born in Bethlehem because his parents had to leave Nazareth to register for a census. The family stays in Bethlehem for a time, and then simply heads back to Nazareth. There is no flight to Egypt, and no vast killing of male infants.
Luke's account of Jesus's birth in Bethlehem, besides being inconsistent with Matthew's, faces the following difficulties:
"1) nothing is known in history of a general census by Augustus; (2) in a Roman census Joseph would not have had to travel to Bethlehem, and Mary would not have had to travel at all; (3) no Roman census would have been made in Judea during the reign of Herod; (4) Josephus records no such census, and it would have been a notable innovation; (5) Quirinius was not governor of Syria until long after the reign of Herod."
Some people might be tempted, on seeing these problems, to decide, "See, it's all a bunch of nonsense."
But historians do not treat their sources as something to be believed or disbelieved; they are something to be interrogated, witnesses whose testimony, however inaccurate it might be, will nevertheless provide clues to help us get at the facts.
Luke and Matthew both wanted Jesus to be born in Bethlehem because prophecy said the Messiah would be born there. So why not simply have him come from Bethlehem? Why these elaborate stories as to why he was born there but was a Nazarene? There is only one plausible reason: There was an actual person called Jesus, and it was widely known that he was from Nazareth. If Luke and Matthew were simply making up this figure out of whole cloth, there would be no reason to involve a completely insignificant village like Nazareth in the story at all.