The canonization of Scripture is not a topic that can be easily covered, but let me give a brief overview.
I will not talk about the Old Testament much other than to say that Jesus accepted the Old Testament as we have it through His use of it and His calling it the word of God.
The New Testament process (very brief sketch) works this way:
1. Apostles or prophets wrote letters, gospels, and other literature.
2. The church received this work and viewed it as being authoritative for life and practice.
3. Distinctions were made between writings which were helpful, and writings which were Authoritative.
4. Very early on those authoritative books were called Scripture. Paul refers to Luke's writing as Scripture in 1 Timothy and Peter refers to Paul's writings as Scripture in 2 Peter.
5. When heretics begin to gain sway the church wrote down,which documents they were authoritative and which were not. This was not done arbitrarily, but rather had certain criteria, with the main one being its connection to an apostle.
Hope this helps.
www.studyyourbibleonline.com