What is the difference between までに and 前に


> １２時 **までに** 帰らなければなりません。  
>  I must go home before 12.
>
> 寝る **前に** 本を読みます。  
>  Before I sleep, I read a book.




までに basically means "by" and it's used to mark a deadline. 12時までに～します means
you may do it at 11:30 or even at 7:00. On the other hand, 12時前に～します means you
do it (shortly) before 12:00, for example at 11:45, but usually not at 7:00.

寝る前に本を読みます is a natural sentence that simply describes what the speaker does
_at night_ , before sleeping. 寝るまでに本を読みます implies there is a deadline, so this
sounds like the speaker must read the book before sleeping, at the latest, but
he can read it _during the day_ if he wants.

