German Chancellor Angela Merkel says the EU may have to consider treaty change if that is what it takes to keep the UK in.
She is confident that conditions can be created for the UK to stay in and she is "not losing sleep" over it, she said in a BBC interview.
UK Prime Minister David Cameron aims to renegotiate the UK's EU membership terms, ahead of an in/out referendum.
"I'm optimistic that if we all want it, we'll find a good solution," she said.
"It's not about losing sleep over this, but about doing our work and creating the necessary preconditions for Britain to remain in the EU."
Treaty change is a thorny issue for the EU, as France and some other countries are known to be very wary of it. The Lisbon Treaty negotiation dragged on for some eight years before its signing in 2009, and involved two Irish referendums.
"Some of the things that David Cameron is asking for I can support," Mrs Merkel told the BBC's Europe Editor Katya Adler in Berlin.
"There are other points where we have a different opinion, but we have always been able also to pursue a Europe at different speeds, to find opt-out solutions for example."
When asked whether EU treaties would be changed, she replied: "If that is really necessary then we have to consider it."
Last week, the prime minister made a whistle-stop tour of Europe trying to gather support for changes he wants before holding the UK's EU membership referendum. That vote is to take place by the end of 2017.
Tighter rules on migrants' benefits are a priority for the UK Conservatives, as they want to control immigration from the EU.
Mr Cameron also wants an opt-out from the EU pledge of "ever closer union" and more influence for national parliaments over EU laws.
Mrs Merkel was asked if she was ever irritated by UK demands in the EU. She responded with a smile and said "we know each other.... and as German chancellor I can say that I also have my own ideas of how things in the EU should be.
"The EU is a union of 28 member states that have to find compromises. Only when everyone is agreed and happy can we get proper results. That will is there. We have already found many, many solutions for many, many difficult questions - it should be like that in this case too."
There is speculation that the EU could come up with a special treaty protocol for the UK, to accommodate particular UK concerns. A similar procedure made Danish and Irish opt-outs legally binding in the past.