Talks are underway in Belfast to strike a deal to salvage powersharing in Northern Ireland.

Theresa May joined Taoiseach Leo Varadkar and the leaders of the Democratic Unionists and Sinn Fein in a bid to end a 400-day political deadlock.

Here we explain how the political impasse came to be and what a future deal could look like.

How and why did the Northern Ireland Executive collapse?

The Northern Ireland Executive collapsed in January 2017 with the resignation of Martin McGuinness as Deputy First Minister.

Due to the unique nature of history and circumstances in Northern Ireland, both unionists and nationalists must join together in a power sharing executive in order to lead the assembly. Since 2007, the DUP have been the largest unionist party and Sinn Féin have been the largest nationalist party.

With the larger mandate, the DUP have always been given the post of First Minister, while Sinn Féin have been given Deputy First Minister, but the two roles are effectively a joint office, with equal power, and can only exist with the full support of the other.

This arrangement has largely weathered a decade of politics, but in November 2016 a scandal emerged surrounding a Renewable Heat Incentive (also referred to as the RHI scandal or ‘Cash for Ash’), signed off by First Minister Arlene Foster in 2012. Its mismanagement had cost the Northern Ireland Executive £480m.

Sinn Féin called for Ms Foster to stand aside from her position to allow for an independent inquiry into the scandal, but she refused.

Having served as Deputy First Minister for ten years, Mr McGuinness then resigned in January 2017 and Sinn Féin announced they would not be replacing him. This stripped Ms Foster of her title as First Minister and collapsed the executive.

What happened next?

The then-Secretary of State for Northern Ireland, James Brokenshire, called fresh elections for the Northern Ireland Assembly in March 2017. It returned the DUP and Sinn Féin as the largest parties, but the gap between them had closed dramatically. Only 1,000 votes separated them in the popular vote. The DUP fell by 10 seats to 28, with Sinn Féin not far behind on 27. Crucially, it was the first time that unionists no longer held an overall majority in the Assembly.

The parties then had three weeks to reach a deal, and when that time passed, Mr Brokenshire decided not to call fresh elections, as he is entitled to do. Instead, talks continued in stops and starts throughout the year – played out against the backdrop of the dramatic 2017 UK General Election (in which the DUP played a key role), and the Brexit drama which has followed.

All the while, Northern Ireland has had no functioning government, and has effectively been run by civil servants on diminishing resources. Westminster passed a budget in November 2017 for Northern Ireland for the ongoing financial year, but this was very much a temporary fix, and all involved refrained from calling it direct rule, still holding out for a deal.

In January 2017, Karen Bradley was named Secretary of State for Northern Ireland, and began talks between the parties again. Now, they appear to be on the verge of a breakthrough.

Who is involved in the talks?

The talks are being co-chaired by the Secretary of State for Northern Ireland, Karen Bradley, representing the British government, and the Irish Tanaiste (Deputy Prime Minister), Simon Coveney, representing the government in Dublin.

The majority of the talks will be between the DUP and Sinn Féin, the two largest parties, who must strike a deal together if power sharing is to be restored. However, the Alliance Party, the SDLP and the UUP are also involved in some levels of discussion.

What are the parties discussing in the current talks?

Although it was mainly the RHI scandal and the position of Arlene Foster which sparked this crisis, Sinn Féin had other complaints too – namely that funding was being cut to Irish language services and that the DUP had abused a parliamentary mechanism known as the Petition of Concern to prevent the introduction of same sex marriage in Northern Ireland.

Sinn Féin has called for a standalone Irish Language Act – in the style of the Welsh Language Act – which would give Gaelic parity with English in Northern Ireland. This has been resisted by the DUP, who see it as an erosion of British identity.

There may also be some discussion around reforming the Petition of Concern. It allows a bill to be blocked from passing in the Northern Ireland Assembly if one side of the community feels the other is oppressing their rights.

The DUP used this to prevent the passing of same sex marriage, despite the assembly having a clear majority, much to the anger of many on both sides of the community divide. Other parties have also misused this mechanism in the past, but when considered in its correct usage, it may prove to be too crucial to be removed altogether.

All of these issues have remained on the table, as well as more outstanding problems such as how Northern Ireland should deal with its troubled past, and whether or not prosecutions – particularly of the armed forces – should play a role in any reconciliation process.

If a deal is agreed upon, what might it consist of?

The Irish Language Act has become the most prominent discussion point, not just for Sinn Féin, but among mainstream media and broadcasters, and across Northern Ireland in general. It’s unclear what it would entail, and whether it’s merely a matter of Irish on road signs and public buildings, or something greater like equal opportunities for English and Irish speakers in public sector jobs.

But any deal would almost certainly have to include it in some shape or form, even if it means the DUP insisting on similar protections for the lesser used Ulster Scots dialect.

Owing to her position in the negotiations, and her own determination not to bow to the demands of Sinn Féin, it appears Arlene Foster may be returned as First Minister. For their part, it is a drum Sinn Féin ceased beating several months ago, as the talks turned to bigger issues.

The DUP know that same sex marriage in Northern Ireland is only a matter of time, but it is unlikely that they will simply gift it to Sinn Féin in any deal, considering how badly this would play with their conservative base.

However, they may quietly agree not to block it, or the Petition of Concern could be reformed somewhat to prevent them from using it again.

If a deal is done, what will happen next?

Any deal would have to be sold by the DUP and Sinn Féin negotiating teams to their party members, after which it would be signed into effect. The DUP would then nominate a First Minister (almost certainly Arlene Foster) and Sinn Féin would nominate a Deputy First Minister (probably Michelle O’Neill).

They would then distribute various portfolio such as Education and Health, and an executive would be formed. The Northern Ireland Assembly, as elected in March 2017, would then reconvene for regular business.

What happens if the parties cannot reach an agreement on a deal?

If the parties cannot agree a basis on which to re-enter powersharing at Stormont, then Northern Ireland will be governed by direct rule from Westminster. In theory, the Northern Ireland Secretary could attempt to avert this by calling another election for the assembly, but this is unlikely to return anyone other than the DUP and Sinn Féin as the two largest parties, thus ending up back at the start.

Northern Ireland has been under direct rule from Westminster before, notably for the duration of The Troubles between 1972 and 1998, but it has largely been run by devolved government ever since. The return of direct rule would be a major setback for the province, and for cross-community reconciliation. Since Sinn Féin abstain from taking their seats at Westminster, it would leave Northern Ireland solely represented by 10 DUP MPs in the House of Commons.

Ironically, social issues that the DUP have stood against, such as same sex marriage and legalising abortion, could be almost immediately implemented once the affairs of Northern Ireland are left to a House of Commons who largely support these measures – both already legal across the rest of the UK. Therefore, despite their hold over the Conservatives, direct rule is not an ideal scenario for the DUP, and will only be greeted by more hardline loyalists who believe Northern Ireland should always be ruled directly by London.

From Sinn Féin’s perspective, direct rule is also not desirable – as their mandate in Northern Ireland elections is increasing, and this would undo that work. But if the alternative is a bad deal, it’s unclear how they would walk back on that after such a lengthy political stalemate.

What does this mean for Brexit?

The DUP campaigned to leave the EU, while Sinn Féin campaigned for Remain, though both parties have concerns about what a hard border would mean for the island.

We already know that any Northern Ireland Assembly – like the Scottish and Welsh assemblies – won’t get a vote, or indeed a veto, on the Brexit deal. But regardless of the outcome, we know that the DUP are willing to use their leverage with the Conservatives in Westminster to press Ms May on their Brexit wishes – as they did when the Prime Minister was brokering a deal in Brussels last December. This is one advantage the DUP has over Sinn Féin – who abstain from taking their seats in Westminster.

Sinn Féin are highly unlikely to take their seats in the House of Commons to vote on any Brexit deal; not when their position is largely being represented by Irish Taoiseach Leo Varadkar, himself backed up by the EU negotiating team in Brussels.