Ewell was born in Georgetown, District of Columbia. He was raised in Prince William County, Virginia, from the age of 3, at an estate near Manassas known as "Stony Lonesome." He was the third son of Dr. Thomas and Elizabeth Stoddert Ewell; the grandson of Benjamin Stoddert, the first U.S. Secretary of the Navy; the grandson of Revolutionary War Colonel Jesse Ewell; and the brother of Benjamin Stoddert Ewell. He graduated from the United States Military Academy in 1840, thirteenth in his class of 42 cadets. He was known to his friends as "Old Bald Head" or "Baldy." He was commissioned a second lieutenant in the 1st U.S. Dragoons and was promoted to first lieutenant in 1845. From 1843 to 1845 he served with Philip St. George Cooke and Stephen Watts Kearny on escort duty along the Santa Fe and Oregon Trails. In the Mexican–American War, serving under Winfield Scott, he was recognized and promoted to captain for his courage at Contreras and Churubusco. At Contreras, he conducted a nighttime reconnaissance with engineer Captain Robert E. Lee, his future commander.