Image copyright BBC Scotland/Matchlight

Freemasons have long been regarded as a secretive men-only society with arcane rituals, but Scottish lodges have broken with centuries of tradition to open their doors to the BBC.

Some dismiss it as a club full of funny handshakes and raised trouser legs but to others it is the heart of the establishment that pulls strings and wields real power behind the scenes.

Freemasonry in Scotland can trace its history back 400 years but its heyday of mass membership was a century ago.

It is now trying to dispel some of the myths and misconceptions that have become attached to it over the years and attract new members to the Craft.

The birthplace of freemasonry

Media playback is unsupported on your device Media caption Not many people know that Freemasonry is as Scottish as tartan, whisky and shortbread.

Before freemasons there were stone masons, skilled craftsmen employed to work on Scotland's landmark buildings.

The masons grouped together into something like a trade union to protect the secrets of their craft and hand them on to the next generation.

In 1598 and 1599, William Schaw's statutes set down how masons should behave both on and off the construction site.

They included instructions such as: "They shall be true to one another and live charitably together as becometh sworn brethren and companions of the Craft."

Prof Steve Murdoch, from the University of St Andrews, says: "They are often seen as the founding documentation for freemasonry in Scotland."

The Grand Lodge of Scotland's curator, Bob Cooper, said people soon became curious about this new brotherhood and asked to join.

In 1641, Sir Robert Moray - a Scottish soldier, statesman, diplomat, judge, spy and natural philosopher - joined a stone masons' lodge and many consider this to be the moment when the freemasons began.

Funny handshakes and rolled up trouser legs

Image copyright BBC Scotland/Matchlight

The infamous Masonic handshake arose with a practical purpose, according to Mr Cooper.

He says: "The handshake is a way of identifying one to another, especially when they had to move around Scotland looking for work.

"If you went to a place where you weren't known you had to have some kind of proof that you were able to work on a construction site."

The ability of masons to secretly identify each other has led to accusations of them excluding those who are not part of the society.

Another Masonic ritual is the rolled-up trouser leg.

"It's the one that gives us the most trouble," says Bob Cooper.

"What it means is that your skin touches the lodge so there is physical contact between you and the lodge.

"It's just a very old and peculiar way of emphasising the fact that you have entered an organisation that you are never going to renege on."

Initiation ceremonies

Image copyright BBC Scotland/Matchlight

Despite giving the BBC access to film in its lodges, its initiation ceremonies have never been filmed, leading to many theories about what happens.

Brother Ewan Rutherford, of the Sir Robert Moray Lodge No. 1641 in Edinburgh, says: "It was one of the most frightening experiences I have ever had and I have no idea why. Most men would probably say the same, anxious about the unknown."

Mr Cooper says: "Freemasonry wanted to do something a bit bolder, something more emphatic, something you would remember to the day you died."

But he adds: "I have taken an oath that I will not tell anyone what goes on within a Masonic lodge."

While current masons are excluded from divulging details, ex-members have posted details of the ceremony online.

It is based on the legend Hiram Abiff, the builder of the Biblical temple of Solomon, who is attacked by thugs wanting to know the secrets of building. Hiram refuses to tell them and is murdered.

This scene is enacted by masons during the initiation. The blindfolded new member has to pledge never to give away the secrets despite being given the "third degree" by his attackers.

Famous freemasons

By the latter part of the 18th Century, Freemasonry had spread like wildfire across Scotland and England.

In the farming heartlands of Ayrshire, it caught the attention of a lowborn farmer, ambitious for greater things.

Robert Burns, Scotland's national poet, joined the Tarbolton Lodge in 1781, when he was 22.

He rose to be depute master from 1784 to 1788.

Prof Gerry Carruthers, from the University of Glasgow, said Burns could have gone to the lodge and been treated as an equal in a country where he and many other men did not have the vote.

"Freemasonry was a great egalitarian platform," says the professor, who has never been a mason.

A criticism often made of the freemasons is that they do favours for one another - and for Burns that is exactly what happened.

When it looked as if hard times would force him to leave Scotland for Jamaica, it was the brotherhood that rallied round to save him.

Prof Carruthers says there were 612 copies printed of the Kilmarnock edition of Burns' first poetry book in 1786 and two-thirds of the subscriptions were taken up by freemasons.

It was freemasons further afield that propelled him to national and international fame.

Another famous Scot who joined the freemasons slightly before Burns was engineer James Watt.

He met influential people who could help with his development of the steam engine - an invention which changed the world.

Power and influence

Image copyright BBC Scotland/Matchlight Image caption Ramsay McGhee, who was Depute Grand Master at the time of filming

"I've heard it said that people only become freemasons in order to get a leg up the greasy pole," says Bob Cooper.

"That's not what freemasonry intends to do.

"There are quite possibly occasions where people have got together within freemasonry with the intent of doing that but that is not the purpose of the freemasons."

The number of masons in high-profile public positions was a controversial subject, with many viewing the secret society as a means of bestowing favours.

Ramsay McGhee was a senior police officer in the north of Scotland and remains a prominent freemason.

He says that when he was transferred to the Black Isle in 1974 half the police section were active freemasons.

"When I left the force at the back end of 2003, I was the only active senior officer in Northern Constabulary that was involved in freemasonry," he says.

In the past, masons were accused of tearing up parking tickets for fellow brothers, letting them off speeding tickets or worse.

Mr McGhee says that "in all honesty" only one person ever tried to do that with him.

"I can tell you, it didn't work," he says.

Protestant only

Image copyright Getty Images Image caption The Eye of Providence can be found on masonic temples around the world

Prof Gerry Carruthers says the freemasons developed through the Scottish Enlightenment.

"They both operate in that same 18th Century European culture where we are fed up of a past that is religiously torn and violent and we now want a more general type of Christianity that isn't so doctrinaire," he says.

The success and spread of Masonic thought throughout Europe led the Catholic Church to first prohibit membership in 1738.

It was concerned Catholics would be asked to put their membership of the lodge above the Church.

Since then, many popes have made pronouncements about the incompatibility of Catholic doctrines and Freemasonry.

The Freemasons claim to allow access to anyone who follows its tenets.

Declining membership

Image copyright BBC Scotland/Matchlight

In 1920 the freemasons was known as Scotland's conservative club for gentlemen and 54,000 joined its ranks that year.

One in 10 Scottish men were freemasons, the highest percentage anywhere in the world.

Today, numbers are dwindling with just 2,000 a year joining.

In Edinburgh, the masons have launched a university lodge to attract younger members.

Brotherhood of man

Image copyright BBC Scotland/Matchlight

Freemasonry has always been a men-only club in Scotland.

Women are not allowed to take part or even witness the events of the Masonic lodge.

Scotland's Depute Grand Master Ramsay McGhee says: "We get criticised at times because we are men only but I firmly believe there are times when men need to be with men and there are times when women need to be with women.

"I think if we are tolerant of that fact then freemasonry provides the ideal outlet for men."

Alan Rudland, of St David's (University Lodge) No 36 in Edinburgh, says men who have just joined freemasonry are referred to a "rough ashlar" - this is a stone which is formed but would not make a stable building if it were used.

Mr Rudland says: "We are using the teachings in freemasonry to make that individual a better person - going from a rough ashlar to a smooth ashlar.

"One of the basic tenets we have for freemasonry is taking good men and making them better."

The Secrets of the Masons will be on BBC Two Scotland at 21:00 on Monday 19 March and on the BBC iplayer.