BERLIN, May 12 (Reuters) - If Britain were to leave the European Union, it could cost Germany up to 45 billion euros ($50 billion) by the end of 2017 as exports from Europe’s largest economy would likely be hit, a study by DZ Bank showed on Thursday.

Britain is counting down to a referendum on its membership of the European Union on June 23, with opinion polls showing voters are roughly evenly split.

“There’s a lot at stake for the German economy because Great Britain is one of its most important trading partners,” DZ Bank economist Monika Boven said.

If Britons were to vote for leaving the EU, the German economy would start to feel the effects in the second half of this year, Boven said.

In that case, the German economy would grow by 1.4 percent this year instead of DZ Bank’s current prediction of 1.8 percent, and 0.5 percent in 2017 versus 1.7 percent, the study showed.

The German government expects the economy to grow by 1.7 percent this year and 1.5 percent next year. It has not released separate growth estimates in case of a Brexit.

Given that Germany’s annual economic output is at least 3 trillion euros, DZ Bank estimates of what post-Brexit growth rates would look like would amount to economic output being around 45 billion euros lower by the end of 2017, the study showed.

“In our crisis scenario we’re even expecting a slight recession in Germany around the turn of the year,” Boven said.

Last year German shipments to the United Kingdom surged by almost 13 percent to just under 90 billion euros - the largest amount it has ever exported there. Germany only sold more goods to the United States and France.

Boven said the British market had helped stabilise the German economy at a time when the global economic environment had been tough, so the exporting sector would be directly hit if Britain were to leave the EU. (Reporting by Rene Wagner; Writing by Michelle Martin; Editing by Raissa Kasolowsky)