Image copyright EPA

Hillary Clinton has been cleared for a second time by the FBI over her use of a private email server while secretary of state. What's it all about?

In July, an FBI investigation concluded no "reasonable prosecutor" would bring a criminal case against Mrs Clinton, but that she and her aides were "extremely careless" in their handling of classified information.

Then the FBI surprised everyone, 11 days before the election, by announcing it was examining newly discovered emails sent or received by Hillary Clinton.

Two days before voting booths opened across the nation, FBI Director James Comey announced he was standing by his original assessment - that Mrs Clinton should not face criminal charges.

So how did we get here?

What's the deal with Hillary Clinton's emails?

Shortly before she was sworn in as secretary of state in 2009, Hillary Clinton set up an email server at her home in Chappaqua, New York. She then relied on this server, home to the email address hdr22@clintonemail.com, for all her electronic correspondence - both work-related and personal - during her four years in office.

She also reportedly set up email addresses on the server for her long-time aide, Huma Abedin, and State Department Chief of Staff Cheryl Mills.

She did not use, or even activate, a state.gov email account, which would have been hosted on servers owned and managed by the US government.

Mrs Clinton's email system became a national story the first week of March 2015, when the New York Times ran a front-page article on the subject. The article said that the system "may have violated federal requirements" and was "alarming" to current and former government archive officials.

Profile: Hillary Rodham Clinton

Why did she do it?

Image copyright Reuters Image caption The email system was set up initially for former President Bill Clinton, Mrs Clinton said

According to Mrs Clinton, the primary reason she set up her own email was for "convenience". During a press conference at the UN, she said that she preferred to carry only one smartphone with one email address, rather than have two devices - one for work and one for personal affairs.

At the time, according to reports, government-issued Blackberry phones were unable to access multiple email accounts.

"I thought using one device would be simpler, and obviously, it hasn't worked out that way," she said.

Media playback is unsupported on your device Media caption Clinton defended her email use in March 2015

Sceptics have countered that the real reason Mrs Clinton established her own email system was because it gave her total control over her correspondence.

With her email setup, she became the sole arbiter of what should and shouldn't be provided to the government, made public via freedom of information requests or turned over to interested parties, such as the congressional committee investigating the 2012 attack on the US consulate in Benghazi.

According to the State Department inspector general report, in 2010 Mrs Clinton told her deputy chief of staff that one of her concerns with email is that she did not "want any risk of the personal being accessible".

An FBI investigation found that Mrs Clinton used "numerous personal devices" while in office and relied on several email servers. Clinton staffers told the FBI that they destroyed some of the replaced devices with a hammer while they could not account for others.

What's Hillary Clinton's 2016 plan?

Was this against the law?

Image copyright AP

Probably not. Mrs Clinton's email system existed in a grey area of the law - and one that has been changed several times since she left office.

When she became secretary of state, the controlling interpretation of the 1950 Federal Records Act was that officials using personal email accounts must ensure that official correspondence is turned over to the government. Ten months after she took office, a new regulation allowed the use of private emails only if federal records were "preserved in the appropriate agency recordkeeping system".

Mrs Clinton maintains that this requirement was satisfied because most of her emails from her personal account went to, or were forwarded to, people with government accounts, so they were automatically archived. Any other emails were turned over to State Department officials when they issued a request to her - and several of her predecessors - in October 2014.

She said it is the responsibility of the government employee "to determine what's personal and what's work-related" and that she's gone "above and beyond" what she was asked to do.

In November 2014 President Barack Obama signed the Presidential and Federal Records Act Amendments, which require government officials to forward any official correspondence to the government within 20 days. Even under this new law, however, the penalties are only administrative, not criminal.

The State Department inspector general report, released in May 2016, found that Mrs Clinton's email system violated government policy and that she did not receive permission prior to instituting it - approval that would not have been granted had she asked. Such transgressions, however, do not constitute criminal conduct.

FBI director James Comey announced the results of a separate FBI investigation on 5 July and concluded that that while "there is evidence of potential violations" of criminal statues covering the mishandling of classified information, "our judgement is that no reasonable prosecutor would bring such a case". It referred the matter to the Justice Department, which closed the case against Mrs Clinton and her aides with no charges.

The State Department has since resumed its investigation into whether Mrs Clinton or her aides violated government policy in their handling of classified information. If it determines that they did, the punishment could include a formal letter of reprimand or loss of security clearance.

A long journey as Secretary of State

How many emails are we talking about?

Image copyright Getty Images Image caption Mrs Clinton said some of her personal emails involved planning her daughter's wedding

According to Mrs Clinton, she sent or received 62,320 emails during her time as secretary of state. She, or her lawyers, have determined about half of those - 30,490, roughly 55,000 pages, were official and have been turned over to the State Department.

Mrs Clinton said the other emails are private - relating to topics like her daughter's wedding, her mother's funeral and "yoga routines".

At Hillary Clinton's request, the State Department released the first set of emails sent on her private account in May 2015, with many relating to the 2012 attack on the US consulate in Benghazi.

In early August 2015, she signed an affidavit swearing she had turned over all copies of government records from her time in office.

The FBI found "several thousand" work-related emails that were not turned over to the State Department, although it concluded that the emails were deleted prior to 2014 and were not intentionally removed "in an effort to conceal them".

About 3,000 emails are expected to be released in the run-up to election day, but many more will not be processed until after 8 November.

Have other politicians engaged in similar activities?

Mrs Clinton is far from alone. Other politicians and officials - both in federal and state governments - sometimes have relied on personal email for official business. Colin Powell, secretary of state under President George W Bush, told ABC he used a personal email account while in office, including to correspond with foreign leaders.

The State Department inspector general report found that many of Mrs Clinton's predecessors - including Mr Powell - were also not in compliance with federal recordkeeping requirements, although the rules governing their actions were less detailed when they were in office.

The New York Times reported that Mr Powell had once advised Mrs Clinton at a dinner party to use private email, although not while handling classified information. But he later denied he had ever done such a thing.

Outside of Washington, former Florida Governor Jeb Bush - a 2016 candidate for the US presidency - relied on a private email address (jeb@jeb.org). Like Mrs Clinton, he has selected which correspondence to make public.

Image copyright Getty Images Image caption Colin Powell used a personal email account while Secretary of State

Wisconsin Governor Scott Walker, another former Republican presidential aspirant, faced questions over his staff's use of private email addresses when he was Milwaukee County executive.

Government Executive magazine conducted a poll in February 2015 of 412 high-level federal workers and found that 33% of those surveyed said they use personal email for government business "at least sometimes".

Mrs Clinton differs from these examples not in manner but in extent - because she used her personal email address exclusively. And, unlike Mr Bush and Mr Walker, her actions were governed by federal law.

Clinton's 'approval bubble' has popped

Meet the 2016 presidential hopefuls

So why is this a controversy?

Image copyright Getty Images

This became a big deal in large part because Mrs Clinton is asking the US public to trust that she is complying with both the "letter and the spirit of the rules", in the words of her spokesperson, Nick Merrill.

The New York Times story was prompted by information provided to the paper by the congressional Benghazi committee, and conservative critics allege that there is no way to prove that she is being forthcoming in providing their investigation with all the relevant material.

Her "convenience" explanation has been difficult for some to swallow, given that as secretary of state she travelled with an extensive entourage capable of carrying her additional phone. And in February 2015, she told a television interviewer that she now carries multiple devices - an iPhone and a Blackberry, as well as an iPad and an iPad mini.

In addition, critics on both the left and the right have expressed concern that her reliance on a "homebrew" email system made her communications more susceptible to hackers and foreign intelligence services.

Could Clinton emails shake up the 2016 race?

Exactly how secure was her email?

Image copyright AP Image caption The server may have been located in the Clintons' home in New York state

During her press conference, Mrs Clinton said that that there "were no security breaches" of her server and that robust protections put in place "proved to be effective and secure".

Independent cybersecurity analysts have said that expert hackers can break into email servers without leaving any evidence, however. And commercially available security systems are no match for government-protected systems - but even those aren't invulnerable, as a November 2014 intrusion into the State Department's email system proved.

She has repeatedly said that no classified material was transmitted via her email account and that she sent only one email to a foreign official - in the UK.

But in July 2015, the inspector general of the US intelligence community, Charles McCullough, told Congress she had sent at least four messages that contained information derived from classified material. A month later, Mr McCullough revealed that two of the emails contained information deemed "top secret" - the highest classification level.

Responding to building pressure, Mrs Clinton finally agreed in August 2015 to hand over the private server she used for a preliminary FBI investigation into the security of classified information contained among her emails.

She also said she would hand over memory sticks containing copies of the emails.

By the time the final batch of Clinton emails were released in March 2016, the total number of emails receiving an after-the-fact classified designation had surpassed 2,000.

In May 2016 the Romanian hacker Guccifer, in US prison on felony hacking charges, told Fox News that he had successfully accessed Mrs Clinton's email server several times - an assertion the Clinton campaign denies and the State Department and prosecutors said there is no evidence to support.

The July 2016 FBI report found no "direct evidence" of unauthorised access to her email servers, according to James Comey, but that the lack of robust security meant that "it is possible that hostile actors gained access".

Clinton sent emails that have since been deemed to contain classified information

Wait, the State Department was hacked?

Image copyright White House Image caption President Barack Obama emailed Mrs Clinton at her private address, the White House has said

Indeed, it was. According to sources cited by CNN, the November 2014 attack was the "worst ever" cyberattack on a government agency , requiring department IT workers to shut down its entire unclassified email system for a weekend.

The US government suspects Russian hackers were behind the attack - and were also responsible for similar efforts against the White House, postal service and other agencies.

Although Mrs Clinton wasn't affected by that particular incident, some of her personal correspondence was revealed in March 2013 when a confidante, Sidney Blumenthal, had his aol.com address compromised by the hacker named Guccifer (later revealed to be a Romanian named Marcel-Lehel Lazar).

Although Guccifer only exposed emails Mr Blumenthal sent to Mrs Clinton, not her replies, it did reveal the secretary of state's private email address two years before the New York Times made it a national story.

Cyber attacks top US threat list

What about the new twist?

The FBI announced at the end of October that it had discovered new emails "in connection with an unrelated case... that appear to be pertinent to the investigation".

Director James Comey said investigators would determine whether the emails contain classified information.

It emerged that the newly discovered emails were being examined as part of an FBI investigation into disgraced former congressman Anthony Weiner, estranged husband of top Clinton aide Huma Abedin.

Two days before election day, Comey announced he had not changed his original conclusion that Mrs Clinton should not face criminal charges for her handling of classified information, following a review of the newly discovered emails.