All though in the micheal bay movies, they technically are brothers. But in the original g1 cartoons and comics it showed that megatron and Optimus used to study and learned to fight, and they were very close, until prime was chosen as the leader over megatron. From there on, started started being enemies.