IDF in Gaza_July18
An Israeli tank is seen after entering the Gaza Strip in this still image taken from video provided by the Israeli Defence Force (IDF) on July 18, 2014. Reuters/IDF

As the Israeli ground offensive grinds into its second week, the death of two Americans in the Gaza Strip has drawn attention to the presence of U.S. citizens serving in the military of another country.

Sean Carmeli, 21, and Max Steinberg, 24, who both were born in the United States, were among a total of 13 soldiers and 65 Palestinians killed on Sunday. Carmeli held dual nationality and Steinberg joined the IDF under a special immigration system that allows foreign-based Jews to join the military in order to gain Israeli nationality. Current estimates put around 2,000 U.S. citizens in the Israeli military, according to an NBC report.

Under U.S. law, being in a foreign military is not illegal -- but there are restrictions. The U.S. Department of State acknowledges that American citizens who choose to live in another country may be called upon to serve in that nation’s military. Such service is not against the law per se -- but could create diplomatic issues.

“Military service by U.S. nationals may cause problems in the conduct of our foreign relations since such service may involve U.S. nationals in hostilities against countries with which we are at peace,” reads a State Department Memo published online. “For this reason, U.S. nationals facing the possibility of foreign military service should do what is legally possible to avoid such service.”

If an American is lawfully serving in a foreign military which then becomes a U.S. foe, the law says the American may lose his or her U.S. citizenship. The scenario where a U.S. citizen fights against the U.S. or one of its allies is relatively rare, the State Department has established an administrative presumption that fighting against the U.S. constitutes an intention to relinquish U.S. nationality. However, “a person serving in the armed forces of a foreign state not engaged in hostilities against the United States does not have the intention to relinquish nationality.”

In general, Israelis must perform national service in the military, so any Americans who live there with dual nationality must also serve.

Those without Israeli citizenship who want to join the IDF can join through Garin Tazbar, a system that allows men between 18 and 23, and women between 18 and 22, to serve. Max Steinberg followed this path. Candidates must be able to speak Hebrew, have completed high school and have no criminal record.

According to the IDF, some 1,500 have joined through this route over the last 20 years. More than 70 percent chose to continue living in Israel after their service was over.

The history of serving in foreign militaries goes back to 1896 when a Supreme Court ruling in Wiborg vs U.S. 163 U.S. 632 declared that “it was not a crime under U.S. law for an individual to go abroad for the purpose of enlisting in a foreign army.” The ruling goes on to say that when that person “has been recruited or hired [by the foreign military] in the United States, a violation may have occurred.”

Carmeli "was very proud to be in the Israeli army," said a rabbi who had known him since childhood. And according to the New York Times, a friend said of Steinberg's decision to join the IDF, "I could see that this was something he really wanted to devote himself to."