Summary:
At any time another civilization or city-state may declare war on you. If so, you'll be informed by an unpleasant pop-up (or notification). You may have an opportunity to try to negotiate your way out of the conflict, or you may have no choice but to fight. See the Diplomacy section for details. Barbarians are always at war with you, so you'll never get a declaration of war from them.