While it's true that about 20% of the pre-war US Army officer corps, and a smaller proportion of navy officers, resigned their commissions to join the Confederacy, 80% didn't, and enlisted men had no such option. The US military as a body absolutely remained loyal to the United States and participated fully in the war. The US Navy expanded greatly during the war, but remained essentially the same institution.
It's a little bit different for the US Army. In 1860, the US Army numbered right at 16,000 men. Of those, about 90% of the Army's fighting strength, including all of the infantry and cavalry units, were west of the Mississippi River. So, upon outbreak of war, those far-flung western units had to first return east, and then figure out their role in the fight. While Lincoln ordered the regular army moderately expanded, it quickly became clear that this war would primarily be prosecuted by regiments of volunteers raised from the states, not by the small regular army. In what may have been a blunder, the US Army decided to concentrate its regulars rather than parceling out experienced officers and NCOs to stiffen the volunteers. Regardless, regulars fought from Manassas on down. In particular, George Sykes' division of regulars did sterling service with the Army of the Potomac's V Corps.