A commander-in-chief is the most senior commander of a nation's military forces or a major division of those forces such as the navy, army or air force. While traditionally held by a military expert, in Western societies the role is often held by a civilian.
In the United States, the President holds several dual roles, that as head of state, head of government, and Commander-in-Chief. The US Constitution describes the Commander in Chief in Article II, Section 2:
The President shall be Commander in Chief of the Army and Navy of the United States, and of the Militia of the several States, when called into the actual Service of the United States;
Many governments may separate the role of Commander-in-Chief from that of Head of State (a monarch for example) or Head of Government (prime minister). The presidency itself in many parliamentary republics is only an honorary position as a head state, while not being the head of government, such as a prime minister. Or vice versa, a president may be only a head of government while not being a Supreme Leader (such as in Iran).
The role of Commander-in-chief can be disconnected entirely from that of Head of State and Head of Government, such as in the largest nation in the world, China, where the Commander-in-Chief is selected by the Military Commission of the Communist Party, and not the government (State Council).