Treason is the act of betraying one's country, while espionage is the act of spying or using spies in order to obtain secret information. Although the two concepts are related and may occur simultaneously, it is also possible to participate in espionage without committing treason and vice versa.
The MI5 website defines treason as a method of obtaining useful but classified information. Governments require intelligence to guide their decision-making. Much intelligence is available through public means, but some forms of intelligence--such as information related to military systems--is top secret and only obtainable through covert tactics, or espionage. Espionage often involves bribing people in high-ranking positions of government. It also includes concealment of identities and other clandestine maneuvers. When espionage is done on behalf of one's government it is not treasonous. On the contrary, in such situations it is a civic duty.
According to the Legal Information Institute at Cornell University, treason is the act of aiding and comforting the enemies of the country to which one has sworn allegiance. A person engaged in espionage that provides a foreign government with classified information regarding one's country commits treason. However, not all treasonous activity involves espionage. For instance, a persons who supplies a foreign nation with weapons without the knowledge of his own government may be committing treason without performing espionage.