The Trinity is sometimes referred to as a mystery. How can God be both three and one? It is helpful to remember that God is not three in the same way that he is one. That is, he is three persons in one nature. The Father, the Son, and the Holy Spirit are three distinct persons in one nature. While we cannot fully understand that, we can at least recognize that it is not a logical contradiction.
This is a diagram of the Trinity that was developed by the early church. It helps to emphasize the equality and the distinction of the members of the Trinity.