God had prepared John the Baptist, while he lived in the wilderness, to appear as a preacher announcing the coming of God’s kingdom. Many came to hear him preach about the need for repentance at the river Jordan and were baptized. John was as a voice crying in the wilderness preparing the way for the Saviour.
Since Jesus was also human, but above all since He came to take away the sin of His people in a way of righteousness he also came to be baptized by John.