In 27 BC, four years after becoming sole ruler of the Roman oikoumene (inhabited world), Augustus Caesar expanded his slate of tax reforms to include registrations in all of the Empire's Provinces. Prior to that year, Rome only took a census in Italy. After that year, Augustus made sure his Governors could not over-fleece Rome's provincial flocks.
In 9 BC, Augustus Caesar unjustly demoted Herod the Great from "friend" to "subject". Herod's chief advisor Nicolas wasn't able to clear up the confusion for almost a year, during which time Augustus must have instigated the census recorded by Luke. The Emperor's ex-brother-in-law, Gaius Sentius Saturninus, may be the one who decided on the odd "each to his own city" requirement.
As Governor of Syria until 6 BC, Saturninus may or may not have received assistance from one Quirinius (who in any event did not take a Judean census as Governor until 6 AD). Whether Luke was wrong, or whether Luke's meaning is obscure, Quirinius does not actually factor into the birth of Christ so far as we know.
The logistics were ridiculous but thorough. Above all, they would have been time consuming. Rome could not staff every city in Herod's Kingdom at once, and the cities could not simultaneously have hosted both soldiers and homecoming visitors while also under-staffed locally. It could not have been "fruit-basket turnover" all at once. Somehow, Saturninus had to advance-publish a staggered schedule of times and locations for each city to be registered. If they got behind schedule, the Governor would have had to republish a new schedule, kingdom-wide. Therefore, it's more likely Saturninus drew up a schedule with plenty of breathing room. Or reverted to one.
At any rate, this could not have been a quick census. It probably took most of 8 and 7 BC to accomplish. Once begun, it continued, even though Herod was reconciled with Augustus in late 8 BC.
By the time Syria's cohorts had moved down as far as Bethlehem, Joseph and Mary were living in Bethlehem. The scandal back in Nazareth made it easier to relocate, which must be why Mary went along. (Presumably, women were not required to be present at these registrations. By the way, property was not registered in Judea until 6 AD, at which time it famously sparked talk of rebellion.)
We know Mary was pregnant on the road to Bethlehem. The young couple must have moved in with Joseph's kinfolk (extended-family home living was very common) and yet they did not have enough space for the new mother to take her own room in the house. During her time of uncleanness, after childbirth, Mary and Jesus would have to stay with the household livestock. Whether that meant a stable, cave, lean-to or outbuilding, the son of God was placed in a feed-trough.
Bethlehem's registration took place shortly before or sometime after the Lord's birth. The census itself continued on, probably in a southward direction. We can say for sure it was over before summer of 6 BC, when Saturninus returned to Italy.
If Jesus was born anywhere between April of 7 BC and March of 6 BC, then he was twelve years old in March of AD 7. That was the first spring Joseph allowed Jesus to go to Jerusalem for Passover, because it was also the first spring Herod's son Archelaus was banished from Palestine.
The first conjunction of Saturn and Jupiter took place in late May, 7 BC. The Magi may have arrived after the third conjunction, that December. If Jesus was 6-8 months old when they arrived, it could explain why Herod thought he might be toddling already. The Frankincense and Gold paid for a sojourn to Egypt. And then Herod died. We have already mentioned Archelaus.
One last detail: if Jesus was born in April or May of that year, he would have touched the start of his 40th year just before ascending to heaven, in the middle of May, in AD 33. That may or may not be significant, but whether God required his second Adam to be tested for forty years, God did send His parents to Bethlehem, because of a very unique set of circumstances, which included a census.
The (probable) real story is more complex than the fairy tale.
It is no less inspiring to me.