Five armed Palestinian groups joined Hamas in the deadly 7 October attack on Israel after training together in military-style exercises from 2020 onwards, BBC News analysis shows.
The groups carried out joint drills in Gaza which closely resembled the tactics used during the deadly assault - including at a site less than 1km (0.6 miles) from the barrier with Israel - and posted them on social media.
They practised hostage-taking, raiding compounds and breaching Israel's defences during these exercises, the last of which was held just 25 days before the attack.
BBC Arabic and BBC Verify have collated evidence which shows how Hamas brought together Gaza's factions to hone their combat methods - and ultimately execute a raid into Israel which has plunged the region into war.
On 29 December 2020, Hamas's overall leader Ismail Haniyeh declared the first of four drills codenamed Strong Pillar a "strong message and a sign of unity" between Gaza's various armed factions.
As the most powerful of Gaza's armed groups, Hamas was the dominant force in a coalition which brought together 10 other Palestinian factions in a war games-style exercise overseen by a "joint operation room".
The structure was set up in 2018 to coordinate Gaza's armed factions under a central command.
Prior to 2018, Hamas had formally coordinated with Palestinian Islamic Jihad (PIJ), Gaza's second largest armed faction and - like Hamas - a proscribed terrorist organisation in the UK and other countries.
Hamas had also fought alongside other groups in previous conflicts, but the 2020 drill was billed in propaganda as evidence a wider array of groups were being unified.
Hamas's leader said the first drill reflected the "permanent readiness" of the armed factions.
The 2020 exercise was the first of four joint drills held over three years, each of which was documented in polished videos posted on public social media channels.
The BBC has visually identified 10 groups, including PIJ, by their distinctive headbands and emblems training alongside Hamas during the Strong Pillar drills in footage posted on the messaging app Telegram.
Following the 7 October attack, five of the groups went on to post videos claiming to show them taking part in the assault. Three others issued written statements on Telegram claiming to have participated.
The role of these groups has come into sharp focus as pressure builds on Hamas to find dozens of women and children believed to have been taken as captives from Israel into Gaza by other factions on 7 October.
Three groups - PIJ, the Mujahideen Brigades and Al-Nasser Salah al-Deen Brigades - claim to have seized Israeli hostages, alongside Hamas, on that day.
Efforts to extend the temporary truce in Gaza were said to be hinging on Hamas locating those hostages.
While these groups are drawn from a broad ideological spectrum ranging from hard-line Islamist to relatively secular, all shared a willingness to use violence against Israel.
Hamas statements repeatedly stressed the theme of unity between Gaza's disparate armed groups. The group suggested they were equal partners in the joint drills, whilst it continued to play a leading role in the plans to attack Israel.
Footage from the first drill shows masked commanders in a bunker appearing to conduct the exercise, and begins with a volley of rocket fire.
It cuts to heavily armed fighters overrunning a mocked-up tank marked with an Israeli flag, detaining a crew member and dragging him away as a prisoner, as well as raiding buildings.
We know from videos and harrowing witness statements that both tactics were used to capture soldiers and target civilians on 7 October, when around 1,200 people were killed and an estimated 240 hostages were taken.
The second Strong Pillar drill was held almost exactly one year later.
Ayman Nofal, a commander in the Izzedine al-Qassam Brigades - the official name for Hamas's armed wing - said the aim of the exercise on 26 December 2021 was to "affirm the unity of the resistance factions".
He said the drills would "tell the enemy that the walls and engineering measures on the borders of Gaza will not protect them".
Another Hamas statement said the "joint military manoeuvres" were designed to "simulate the liberation of settlements near Gaza" - which is how the group refers to Israeli communities.
The exercise was repeated on 28 December 2022, and propaganda images of fighters practising clearing buildings and overrunning tanks in what appears to be a replica of a military base were published to mark the event.
The exercises were reported on in Israel, so it's inconceivable they were not being closely monitored by the country's extensive intelligence agencies.
The Israel Defense Forces (IDF) have previously carried out air strikes to disrupt Hamas's training activities. In April 2023, they bombed the site used for the first Strong Pillar drill.
Weeks before the attacks, female surveillance soldiers near the Gaza border reportedly warned of unusually high drone activity and that Hamas was training to take over observation posts with replicas of their positions.
But, according to reports in the Israeli media, they say they were ignored.
Brigadier General Amir Avivi, a former IDF deputy commander in Gaza, told the BBC: "There was a lot of intelligence that they were doing this training - after all, the videos are public, and this was happening just hundreds of metres from the fence (with Israel)."
But he said while the military knew about the drills, they "didn't see what they were training for".
The IDF said they "eliminated" Nofal on 17 October 2023, the first senior Hamas military leader to be killed during the conflict.
Hamas went to great lengths to make sure the drills were realistic.
In 2022, fighters practised storming a mock Israeli military base built just 2.6km (1.6 miles) from the Erez crossing, a route between Gaza and Israel controlled by the IDF.
BBC Verify has pinpointed the site in the far north of Gaza, just 800m (0.5 miles) from the barrier, by matching geographic features seen in the training footage to aerial images of the area. As of November 2023, the site was still visible on Bing Maps.
The training camp was within 1.6km (1 mile) of an Israeli observation tower and an elevated observation box, elements in a security barrier Israel has spent hundreds of millions of dollars constructing.
The mock base is on land dug several metres below ground level, so it may not have been immediately visible to any nearby Israeli patrols - but the smoke rising from the explosions surely would have been, and the IDF is known to use aerial surveillance.
Hamas used this site to practise storming buildings, taking hostages at gunpoint and destroying security barriers.
BBC Verify has used publicly available information - including satellite imagery - to locate 14 training sites at nine different locations across Gaza.
They even trained twice at a site less than 1.6 km (1 mile) from the United Nations' aid agency distribution centre, and which was visible in the background of an official video published by the agency in December 2022.
On 10 September 2023, the so-called joint committee room published images on its dedicated Telegram channel of men in military uniforms carrying out surveillance of military installations along the Gaza barrier.
Two days later, the fourth Strong Pillar military exercise was staged, and by 7 October, all the tactics that would be deployed in the unprecedented attack had been rehearsed.
Fighters were filmed riding in the same type of white Toyota pickup trucks which were seen roaming through southern Israel the following month.
The propaganda video shows gunmen raiding mock buildings and firing at dummy targets inside, as well as training to storm a beach using a boat and underwater divers. Israel has said it repelled attempted Hamas boat landings on its shores on 7 October.
However, Hamas did not publicise its training with motorcycles and paragliders as part of the Strong Pillar propaganda.
A training video posted by Hamas three days after 7 October shows fences and barriers being demolished to allow motorcycles to pass through, a tactic they used to reach communities in southern Israel. We have not identified similar earlier videos.
Footage of fighters using paragliding equipment was also not published until the 7 October attack was under way.
In a training video shared on the day of the attack, gunmen are seen landing in a mock kibbutz at an airstrip we have located to a site north of Rafah in southern Gaza.
BBC Verify established it was recorded some time before 25 August 2022, and was stored in a computer file titled Eagle Squadron, the name Hamas uses for its aerial division - suggesting the paragliders plan was in the works for over a year.
Before 7 October, Hamas was thought to have about 30,000 fighters in the Gaza Strip, according to reports quoting IDF commanders. It was also thought that Hamas could draw on several thousands of fighters from smaller groups.
Hamas is by far the most powerful of the Palestinian armed groups, even without the support of other factions - suggesting its interest in galvanising the factions was driven by an attempt to secure broad support within Gaza at least as much as bolstering its own numbers.
The IDF has previously estimated 1,500 fighters joined the 7 October raids. The Times of Israel reported earlier this month the IDF now believes the number was closer to 3,000.
Whatever the true number, it means only a relatively small fraction of the total number of armed operatives in Gaza took part. It is not possible to verify precise numbers for how many fighters from smaller groups took part in the attack or the Strong Pillar drills.
While Hamas was building cross-faction support in the build-up to the attack, Hisham Jaber, a former Brigadier General in the Lebanese army who is now a security analyst at the Middle East Centre for Studies and Research, said he believed only Hamas was aware of the ultimate plan, and it was "probable [they] asked other factions to join on the day".
Andreas Krieg, a senior lecturer in security studies at Kings College London, told the BBC: "While there was centralised planning, execution was de-centralised, with each squad operationalising the plan as they saw fit."
He said people inside Hamas were said to be surprised by the weakness of Israel's defences, and assessed militants had likely bypassed Israel's surveillance technology by communicating offline.
Hugh Lovatt, a Middle East analyst at the European Council on Foreign Relations, said Israel would have been aware of the joint training drills but "reached the wrong conclusion", assessing they amounted to the "standard" activity of paramilitary groups in the Palestinian territories, rather than being "indicative of a looming large-scale attack".
Asked about the issues raised in this article, the Israel Defense Forces said it was "currently focused on eliminating the threat from the terrorist organisation Hamas" and questions about any potential failures "will be looked into in a later stage".
It could be several years until Israel formally reckons with whether it missed opportunities to prevent the 7 October massacre.
The ramifications for its military, intelligence services and government could be seismic.
Additional reporting by Paul Brown, Kumar Malhotra and Abdirahim Saeed. Video production by Soraya Auer.