Spain hopes to reach an agreement with the UK over Gibraltar by the summer, its foreign minister has said.
Alfonso Dastis said Spain would "defend our position" but the two sides were "working towards" an agreement as soon as possible.
The UK says "informal" talks are going on about Gibraltar's post-Brexit future with Spain.
Spain has a long-standing territorial claim on Gibraltar, a UK overseas territory on the Iberian Peninsula.
Mr Dastis has previously said that sovereignty would not be an issue in Brexit negotiations.
Instead Madrid wants joint management of Gibraltar's airport and more co-operation on tax fraud and border controls.
Asked if he was hopeful agreement could be reached before October – when the UK and EU hope to reach a Brexit deal that can then be ratified by EU states – Mr Dastis told the BBC: "We are definitely determined to defend our position so I don't exclude anything.
"But we are definitely working towards having an agreement before October, even if possible by the summer, and we hope… that there is also, from the British side, a position which works towards that end."
The EU has said that no future Brexit trade deal may apply to Gibraltar without a bilateral agreement between Spain and the UK.
Mr Dastis said the two sides had met three or four times already this year: "We are having very constructive conversations."
- What will Brexit mean for Britain's overseas territories?
Spain wants joint management of Gibraltar's airport, which is located on a disputed strip of land connecting Gibraltar to the Spanish mainland.
Mr Dastis said that while Spain "cannot accept" British jurisdiction over the land, it wanted to use the airport "to the benefit of the population of Gibraltar".
Asked what joint management would mean, he said: "We will have to work out what the exact terms will be.
"We have tried twice. Once it was rejected by the UK, the second time it was rejected by us – maybe third time lucky?"
Gibraltar: key facts
- Gibraltarians are British citizens but they run their own affairs under a chief minister
- The territory is self-governing in all matters – including taxation – except foreign policy and defence, which are dealt with by the UK government
- Despite its small size, Gibraltar is strategically important, standing only 12 miles from the north coast of Africa. It has a UK military base, including a port and airstrip
Responding to Mr Dastis's comments, a spokesman for the UK government said: "We are having a wide range of discussions with member states, including Spain, about our departure from the EU, including the practical implications for Gibraltar.
"Discussions are continuing with the Government of Gibraltar and our European partners on how to address the specific challenges and opportunities here."
The Government of Gibraltar did not respond directly to Mr Dastis's comments, but in a speech last week, its chief minister Fabian Picardo said Gibraltar had agreed "key fundamentals" with the UK for after Brexit – including the continuation of current trade arrangements.
He added that Gibraltar would seek to establish "new lines of co-operation with the EU" and in particular, Spain, "not because we feel threatened, but because that is our nature".
"And we will continue to seek to construct new synergies for the future and avoid unnecessary confrontation because it has always been our approach."
He added that while Spain had a list of "historic irritants" it wanted to resolve, Gibraltar had its own list of issues that it wanted addressed – including removing Gibraltar from "financial services blacklists" and better traffic flows at the border.
"One of these is also, for us, the future arrangements that might be agreed by us for the exploitation of our £84m airport pursuant to an agreement with Spain, as well as the ability to access the EU Single Sky [an initiative aimed at streamlining air traffic management in the bloc] , even after we leave the EU".
Gibraltar was ceded to Great Britain in the 1713 Treaty of Utrecht but Spain has continued to press its claim – which is rejected by both the UK and Gibraltar itself.
Gibraltarians rejected by 99% to 1% the idea of the UK sharing sovereignty with Spain in a vote in 2002 and in a previous referendum in 1967.
But Gibraltar voted by 96% to stay in the EU in the 2016 referendum.