Jeremiah, in the Old Testament, was told, "Before I formed thee in the belly I knew thee; and before thou camest forth out of the womb I sanctified thee, and I ordained thee a prophet unto the nations." From this simple statement of the Lord we are given the idea that sometime before we were born there was a period of time in which the Lord knew us. Other statements similar to this are found throughout the Bible. Further knowledge of this has been made known to us through the translation of the Book of Mormon and through revelations given through the Prophet Joseph Smith. Through these revelations we learn that we did live before we were born, but it was slightly different from the life we have here.
We are all literal children of God, our Heavenly Father. He is the Father of our spirits and it is because of that relationship that He has such a great love for us and desire to be part of our life. Knowing that the only way we could learn is through our own choices, He has given us the great gift of agency, the ability to choose--right/wrong, good/bad, yes/no, etc. As spirits we were limited in what we could learn and needed to be able to experience mortality to progress and become like our Heavenly Father.
Knowing this, the Father called a grand council of all His spirit children and laid before us a plan whereby we might be able to become like Him. The plan was called the Plan of Salvation, or the Plan of Happiness. In that plan we would be given the opportunity to experience mortal life and learn and grow from the challenges and blessings that would come from it. In order for us to truly gain all we could from mortality, we would have to pass through a veil of forgetfulness and enter this world without any memory of our previous existence. This would allow us to exercise faith in our decisions rather than base them on the knowledge we gained in our premortal life. All of us who are now living, have lived, or who will live on this earth accepted that plan and chose to come to earth and receive the blessings Heavenly Father promised us.