Question: "If Jesus was God, how could He pray to God? Was Jesus praying to Himself?"
Answer: To understand Jesus as God on earth praying to His Father in heaven, we need to realize that the eternal Father and the eternal Son had an eternal relationship before Jesus took upon Himself the form of a man. Please read John 5:19-27, particularly verse 23 where Jesus teaches that the Father sent the Son (also see John 15:10). Jesus did not become the Son of God when He was born in Bethlehem. He has always been the Son of God from eternity past, still is the Son of God, and always will be.
Isaiah 9:6 tells us that the Son was given and the Child was born. Jesus was always part of the tri-unity, along with the Holy Spirit. The tri-unity always existed, the Father God, the Son God, and the Spirit God, not three gods, but one God existing as three persons. Jesus taught that He and His Father are one (John 10:30), meaning that He and His Father are of the same substance and the same essence. The Father, Son and Spirit are three co-equal persons existing as God. These three had, and continue to have, an eternal relationship.
When Jesus, the eternal Son of God, took upon Himself sinless humanity He also took on the form of a servant, giving up His heavenly glory (Philippians 2:5-11). As the God-man, He had to learn obedience (Hebrews 5:8) to His Father as He was tempted by Satan, accused falsely by men, rejected by His people, and eventually crucified. His praying to His heavenly Father was to ask for power (John 11:41-42) and wisdom (Mark 1:35, 6:46). His praying showed His dependence upon His Father in His humanity to carry out His Father's plan of redemption, as evidenced in Christ's high priestly prayer in John 17. His praying demonstrated that He ultimately submitted to His Father's will, which was to go to the cross and pay the penalty (death) for our breaking God's law (Matthew 26:31-46). Of course, He rose bodily from the grave, winning forgiveness and eternal life for those who repent of sin and believe in Him as the Savior.
There is no problem with God the Son praying or talking to God the Father. As mentioned, they had an eternal relationship before Christ became a man. This relationship is depicted in the Gospels so we can see how the Son of God in His humanity carried out His Father's will, and in doing so, purchased redemption for His children (John 6:38). Christ's continual submission to His heavenly Father was empowered and kept focused through His prayer life. Christ's example of prayer is ours to follow.
Jesus Christ was no less God on earth when praying to His Father in heaven. He was depicting how even in sinless humanity it is necessary to have a vital prayer life in order to do His Father's will. Jesus' praying to the Father was a demonstration of His relationship within the Trinity and an example for us that we must rely on God through prayer for the strength and wisdom we need. Since Christ, as the God-man, needed to have a vibrant prayer life, so should the follower of Christ today.