According to the gospels, Mary became pregnant with Jesus through a divine action. Luke 1:26-35 says that the angel Gabriel visited her beforehand and told her that "the Holy Spirit will come upon you, and the power of the Most High will overshadow you." And Matthew 1:18 says "she was found to be with child through the Holy Spirit."
When Mary became pregnant, she was engaged (but still unmarried) to Joseph. Matthew 1:19-24 says that Joseph wanted to back out of the marriage after he found out about the pregnancy. But then an angel appeared to him in a dream, told him about Jesus, and convinced him to accept Mary as his wife. Matthew 1:25 says that he "had no union with her until she gave birth to a son", thus confirming that it was a virgin birth.
Jewish girls of that period usually became engaged when they were twelve or thirteen years old. Actually, for legal purposes this engagement was regarded as the first stage of a marriage, although the girl would normally remain with her parents for about a year before going to live with her husband and consummating the marriage. If she became pregnant before then, she would face public disgrace, and if the law was strictly enforced, could even be executed as an adulteress.
Thus Joseph's initial intention to back out of the marriage could have put Mary into a very difficult situation. She may have even fled from her hometown for a while, because Luke 1:36-56 says that she spent three months of her pregnancy at the house of her relative Elizabeth in Judea. Some scholars have suggested that she made this visit to avoid the humiliation she would have experienced in her own community. In any case, Joseph's eventual decision to proceed with the marriage must have been a great relief.
According to Saint Augustine and some other early Christian writers, Mary didn't feel any labor pains when she gave birth to Jesus. These writers believed that labor pains are a curse that God put on women because of Eve's misbehavior in the Garden of Eden (see Genesis 3:16). But because Mary conceived Jesus in a divine manner, the curse didn't apply to her, and therefore the birth was painless.
Many Christians believe that Mary remained a virgin throughout her life. However, Matthew 13:55-56 and Mark 6:3 say that Jesus had four brothers and at least two sisters. Some people argue that these must have been step-brothers and step-sisters. But most biblical scholars believe that they were natural children of Mary and Joseph who were born after Jesus. Supporting evidence for this view can be found at Luke 2:7, which refers to Jesus as Mary's "first-born", thus implying that she had other children later.
The virgin birth isn't mentioned in the earliest Christian writings, such as the letters of Paul and the gospel of Mark. This has led some scholars to argue that the idea wasn't part of the original beliefs about Jesus, but was introduced later. One possible explanation is that Mary didn't tell anyone about it until she was near the end of her life, so the earliest followers of Jesus never heard about it.
Some ancient non-Christian writings give a completely different account of the birth of Jesus. These writings say that Mary was either seduced or raped, but that this was covered up. Some accounts even say that the real father of Jesus was a Roman soldier variously identified as Pantera, Pandera or Panthera. These non-Christian accounts are examined in detail by Dr. Jane D. Schaberg in her book The Illegitimacy of Jesus. Some of the evidence discussed in the book seems to support the idea that Mary was raped, but much more would be needed to provide a definite proof.
Stories about divine conceptions and virgin births were fairly common in ancient times. They were created for kings and other famous men as a way to give them a semi-divine status. Examples include the pharaohs of Egypt, Alexander the Great, and various Roman emperors. Some scholars think that the story of Jesus' virgin birth developed as an imitation of similar stories about other famous men.
Note: There is a theoretical possibility that a woman could conceive a child naturally while still a virgin. It could happen if an unfertilized egg began to multiply and develop into a fetus on its own. This would lead to a natural virgin birth. The scientific name for this process is parthenogenesis, and it has actually been observed in reptiles and fish. But a baby produced in this way will always be a female, because the egg wasn't fertilized. Therefore this couldn't be what happened In Mary's case.
Note: For more information about this topic, go to this article about the birth of Jesus.