Defense or defence is protecting something from attack. Defenders have advantages over attackers. They can use fortifications and weapons that are too large to move. The defending side in an air battle can have help from anti-aircraft warfare.
Trench warfare during World War I was an example of the advantages of defenders. Attackers were rarely able to take territory that the enemy defended with the new weapons of the time. Later, armies developed newer weapons and methods and that again allowed them to attack and take even fortified places. Tanks, for example, were well protected from machine guns, and groups of tanks could move fast enough to avoid being completely destroyed by artillery.
A country's government may form an army and navy and/or an air force to protect the country and its people from attacks. The same forces can also attack other countries. A country can also use the military to kill or arrest people, or members of groups, from other countries who have hurt or killed their own citizens.