Why Did Mary and Joseph Go to Bethlehem?

There was a census being done that year and everyone had to go to their hometown to take part in the census. Joseph was from bethelehem and therefore they had to travel their for the census.