Image copyright Getty Images Image caption Elon Musk said he initially didn't think his companies were likely to succeed

Elon Musk says his companies SpaceX and Tesla are both still alive only "by the skin of their teeth".

The entrepreneur told an audience at the South by South West (SXSW) conference that both companies almost went bankrupt in 2008.

"I gave both SpaceX and Tesla a probability of less than 10% likely to succeed," he said during a Q&A session.

"At the beginning in 2002, I wouldn't even let my own friends invest as I didn't want to lose their money."

Mr Musk said he made $180m (£130m) when PayPal was acquired by eBay in 2002, and he initially put $90m into SpaceX and Tesla, but the costs kept mounting.

He said 2008 was an incredibly difficult year - SpaceX's Falcon 1 rocket failed for the third time, and Tesla almost went bankrupt two days before Christmas.

By this point, he only had about $40m left.

"I could put it all into one company, and the other company would definitely die, or if I split it into both SpaceX and Tesla, then they both might die," he said.

"And when you put your energy into building something, it's your baby, so I couldn't choose. I put the money into both, and thank goodness they both came through."

Mr Musk also got divorced, and he said he had to borrow money from his friends to pay his rent.

"SpaceX is alive by the skin of its teeth, and so is Tesla - if things had just gone a little differently, both companies would be dead," he said.

Mr Musk said he had to be the chief engineer for the Falcon 1 because he couldn't get any other suitable candidates to join the company, and he didn't want to risk his venture on engineers he felt weren't of the right standard.

And although he can now afford to hire as many talented engineers as he would like, he still continues to spend 80-90% of his time working on engineering and design at both SpaceX and Tesla, leaving other executives to manage the business side of the companies.

However, he said that over time, he felt Tesla had caused him far "more drama" than SpaceX.

He also said his tunnelling firm, the Boring Company, was started as a joke because he thought the name was funny, and although he tweets about it a lot, it actually only takes up about 2% of his time.

Opportunities on Mars

When asked why he decided to go into the space industry and electric cars, he explained that he had been interested in both subjects when he was in university.

He also said he didn't feel enough progress had been made in recent years on space travel.

"I wondered why we weren't making progress with getting people on the moon, and where are all the space hotels we were promised in 2001: A Space Odyssey?" he said.

"The genesis of SpaceX was not to create a company, but how do we get Nasa's budget to be bigger?"

Mr Musk remains convinced that life on Mars is both possible and necessary.

He fears another "dark age" should a third world war occur, and feels that Mars will be integral to helping the human race survive and regenerate.

He also feels there are plentiful business opportunities there.

"They will start off building a rudimentary base... then this will open up a world of new opportunities, because Mars will need pizza joints, great bars - Mars Bars," he said.