Berachot 6a (explanation of)
Mishna (with footnotes):
FROM WHAT TIME MAY ONE RECITE THE SHEMA’ IN THE EVENING? FROM THE TIME THAT THE PRIESTS ENTER [THEIR HOUSES] IN ORDER TO EAT THEIR TERUMAH1 UNTIL THE END OF THE FIRST WATCH.(I.e., until either a fourth or a third of the night has passed).
THESE ARE THE WORDS OF R. ELIEZER.
THE SAGES SAY: UNTIL MIDNIGHT.
R. GAMALIEL SAYS: UNTIL THE DAWN COMES UP.(Maim: about one and one fifth hours before actual sunrise).
ONCE IT HAPPENED THAT HIS (R. Gamaliel's) SONS CAME HOME [LATE] FROM A WEDDING FEAST AND THEY SAID TO HIM: WE HAVE NOT YET RECITED THE [EVENING] SHEMA’. HE SAID TO THEM: IF THE DAWN HAS NOT YET COME UP YOU ARE STILL BOUND TO RECITE. AND NOT IN RESPECT TO THIS ALONE DID THEY SO DECIDE, BUT WHEREVER THE SAGES SAY UNTIL MIDNIGHT’, THE PRECEPT MAY BE PERFORMED UNTIL THE DAWN COMES UP. THE PRECEPT OF BURNING THE FAT AND THE [SACRIFICIAL] PIECES, TOO, MAY BE PERFORMED TILL THE DAWN COMES UP.(This sentence is parenthetical. It is nowhere laid down that the burning of the fat etc. is permitted only till midnight. It is mentioned here in order to inform us that wherever the time fixed for the performance of a duty is the night, it expires at the rise of the dawn - Rashi).
SIMILARLY, ALL [THE OFFERINGS] THAT ARE TO BE EATEN WITHIN ONE DAY MAY LAWFULLY BE CONSUMED TILL THE COMING UP OF THE DAWN. WHY THEN DID THE SAGES SAY ‘UNTIL MIDNIGHT’? IN ORDER TO KEEP A MAN FAR FROM TRANSGRESSION.
Now a previous daf:
R. Levi b. Hama says in the name of R. Simeon b. Lakish: A man should always
incite the good impulse [in his soul] (In
the Talmud the good impulses and evil impulses of a man are personified as two
genii or spirits dwelling in his soul, the one prompting him to do good things
and the other one to do wicked things. The meaning of this saying here is that a
man has always to make an effort and to fight against the evil instincts)
to fight against the evil impulse. For it is written: Tremble and sin not. (Ibid.
IV, 5. The word is translated, not as tremble, but as fight, incite to fight).
If he subdues it, well and good. If not, let him study the Torah. For it is written: ‘Commune with your own heart’. (Ibid
R. Levi b. Hama says further in the name of R. Simeon b. Lakish: What is the meaning of the verse: And I will give thee the tables of stone, and the law and the commandment, which I have written that thou mayest teach them? (Shemot 24:12) ‘Tables of stone’: these are the ten commandments; ‘the law’: this is the Pentateuch; ‘the commandment’: this is the Mishnah; ‘which I have written’: these are the Prophets and the Hagiographa; ‘that thou mayest teach them’: this is the Gemara. It teaches [us] that all these things were given to Moses on Sinai.
R. Isaac says: If one recites the Shema’ upon his bed, it is as though he held a two-edged sword in his hand. (To protect him against the demons). For it is said: Let the high praises of G-d be in their mouth, and a two-edged sword in their hand.(Tehillim 149:6)
How does it indicate this? — Mar Zutra, (some say, R. Ashi) says: [The lesson is] from the preceding verse. For it is written: Let the saints exult in glory, let them sing for joy upon their beds,(Ibid. v. 5) and then it is written: Let the high praises of G-d be in their mouth, and a two-edged sword in their hand.
R. Isaac says further: If] one recites the Shema’ upon his bed, the demons keep away from him. For it is said: And the sons of reshef (E.V. 'Sparks') fly [‘uf] upward.(Iyov 5:7). The word ‘uf refers only to the Torah, as it is written: Wilt thou cause thine eyes to close [hata'if](I.e., if thou neglect it (the Torah). E.V. ‘Wilt thou set thine eyes etc.’)
R. Simeon b. Lakish says: If one studies the Torah, painful sufferings are kept away from him. For it is said: And the sons of reshef fly upward. The word ‘uf refers only to the Torah, as it is written: ‘Wilt thou cause thine eyes to close upon it? It is gone’. And ‘reshef’ refers only to painful sufferings, as it is said: ‘The wasting of hunger, and the devouring of the reshef [fiery bolt].
R. Johanan said to him: This(That the Torah is a protection against painful disease) is known even to school children.(Who study the Pentateuch, where it is plainly said). For it is said: And He said: If thou wilt diligently hearken to the voice of the Hashem thy G-d, and wilt do that which is right in His eyes, and wilt give ear to His commandments, and keep all His statutes, I will put none of the diseases upon thee which I have put upon the Egyptians; for I am Hashem that healeth thee.(Shemot 15:26) Rather [should you say]: If one has the opportunity to study the Torah and does not study it, the Holy One, blessed be He, visits him with ugly and painful sufferings which stir him up. For it is said: I was dumb with silence, I kept silence from the good thing, and my pain was stirred up.(Tehillim 39:3, E.V. ‘I held my peace, had no comfort, and my pain was held in check’).
The rest of the daf before 6a continues on with what befalls a man who does not study/observe Torah. Now quoting again the daf with its footnotes.
R. Jose b. R. Hanina says: He is rewarded with the blessings enumerated in the following verse: Oh that thou wouldest hearken to My commandments! Then would thy peace be as a river, and thy righteousness as the waves of the sea; Thy seed also would be as the sand, and the offspring of thy body like the grains thereof etc. (Yeshayahu 48:18, 19)
It has been taught: Abba Benjamin says, If the eye had the power to see them, no creature could endure the demons.
Abaye says: They are more numerous than we are and they surround us like the ridge round a field.
R. Huna says: Every one among us has a thousand on his left hand and ten thousand on his right hand.(Cf. Tehillim 91:7 which verse is quoted in some editions)
Raba says: The crushing in the Kallah(The Assemblies of Babylonian students during the months of Elul and Adar) lectures comes from them.(For really the lectures are not overcrowded). Fatigue in the knees comes from them. The wearing out of the clothes of the scholars is due to their rubbing against them. The bruising of the feet comes from them. If one wants to discover them,(MS. M.: their footprints) let him take sifted ashes and sprinkle around his bed, and in the morning he will see something like the footprints of a cock. If one wishes to see them, let him take the after-birth of a black she-cat, the offspring of a black she-cat, the first-born of a first-born, let him roast it in fire and grind it to powder, and then let him put some into his eye, and he will see them. Let him also pour it into an iron tube and seal it with an iron signet that they(the demons) should not steal it from him. Let him also close his mouth, lest he come to harm.
R. Bibi b. Abaye did so,(he put the powder into his eye) saw them and came to harm. The scholars, however, prayed for him and he recovered.
Then the daf goes into prayer in the Synagogue. And it should be noted that the Mazikin - upon which the concept of ghosts is based, are uncommon today, due to the Tefilot of the Amora'im AND Babylonian Jews of that time were extremely superstitious.
What is very important to remember is Mishna is halacha, Gemara is commentary on halacha.
How is this related to the Mishna, if it is even at all? Remember that the gemara is commentary ON the Mishna but many times within the discussions something out of the blue would be brought up because that Rav would be reminded of something during the discussions. The point of this particular daf is teaching that we are completely surrounded by the Mazikin but if we keep ourselves engrossed in Torah no harm will befall us.