Sorting out the history of Babylonia is not easy. The city of Babylon began as a small town in the Akkadian Empire. Gradually, the city grew in importance, and eventually became a seat of power for the Akkadian Empire or for its successor empires.
Under the famous King Hammurabi, Babylon achieved its own empire, and flourished in the 1700s and 1600s B.C. (These dates are approximations; scholars debate the exact timing of Babylonian chronology.)
The Babylonian Empire came to an end, and Babylon was sacked. The city was subject to alternating waves of invasions, interspersed with attempts to re-establish its own political independence. Finally, it was under Assyrian rule from the 900s to the 600s B.C.
As scholars Joachim Marzahn and Klaudia Englund write,
The beginnings of Babylon lay in the 3rd millennium B.C. Only at the beginning of the 2nd millennium, however, does a dynasty of Babylonian kings become evident, constantly contesting neighboring states for the rule of Mesopotamia. King Hammurabi (1792-1750) eventually succeeded in uniting into one empire the lands from the region of the Persian Gulf all the way to eastern Syria. At the beginning of the first millennium B.C., Babylon was under Assyrian rule. Following the collapse of the Assyrian Empire in 612, Babylon once more became a capital. The so-called Neo-Babylonian Empire, whose most important kings were Nabopolassar (625-605) and Nebuchadnezzar (605-562), comprised the entire cultivated land and the steppe regions of the Near East west of the Tigris. From all parts of the empire, booty and tribute as well as merchandise flowed into the city and formed, next to an enormous agricultural income, the base of its wealth, which was to find its architectural expression in buildings of a hitherto unknown scale. But already in 539 the Persians conquered the country, and Babylon lost its significance. In the course of the following centuries the city was slowly deserted.
Babylon managed to free itself from Assyrian rule in 626 B.C., but its freedom was never secure, being constantly threatened by not only the Assyrians, but other military powers in the region as well. This independence was short-lived, and in 539 B.C., Babylon fell to the Persians, never to be an imperial power again.