Battle of Trafalgar
Background: In 1805, the First French Empire, under Napoleon Bonaparte, was the dominant military land power on the European continent, while the British Royal Navy controlled the seas. During the course of the war, the British imposed a naval blockade on France, which affected trade and kept the French from fully mobilising their naval resources. Despite several successful evasions of the blockade by the French navy, it failed to inflict a major defeat upon the British, who were able to attack French interests at home and abroad with relative ease.
When the Third Coalition declared war on France, after the short-lived Peace of Amiens, Napoleon renewed his determination to invade Britain. To allow his invasion flotilla to reach England, he needed to wrest control of the English Channel from the Royal Navy.
The main French fleets were at Brest in Brittany and at Toulon on the Mediterranean coast. Other ports on the French Atlantic coast harboured smaller squadrons. France and Spain were allied, so the Spanish fleet based in Cádiz and Ferrol was also available.
The British possessed an experienced and well-trained corps of naval officers. By contrast, some of the best officers in the French navy had been executed or had left the service during the early part of the French Revolution.
Vice-Admiral Pierre-Charles Villeneuve had taken command of the French Mediterranean fleet following the death of Latouche Treville. There had been more competent officers, but they had either been employed elsewhere or had fallen from Napoleon's favour. Villeneuve had shown a distinct reluctance for facing Nelson and the Royal Navy after the French defeat at the Battle of the Nile in 1798.
Napoleon's naval plan in 1805 was for the French and Spanish fleets in the Mediterranean and Cádiz to break through the blockade and join forces in the Caribbean. They would then return, assist the fleet in Brest to emerge from the blockade, and together clear the English Channel of Royal Navy ships, ensuring a safe passage for the invasion barges.

	The admirals of the campaign

Pursuit of Villeneuve: Early in 1805, Vice Admiral Lord Nelson commanded the British fleet blockading the Mediterranean port of Toulon. Unlike William Cornwallis, who maintained a close blockade off Brest with the Channel Fleet, Nelson adopted a loose blockade in hope of luring the French out to battle, saying, "to be able to get at the enemy you must let them come out to you, if you cannot get at them." However, Villeneuve's fleet successfully evaded Nelson's when the British were blown off station by storms. Nelson commenced a search of the Mediterranean, supposing that the French intended to make for Egypt, but Villeneuve instead took his fleet through the Strait of Gibraltar, rendezvoused with the Spanish fleet in Cádiz, and sailed as planned for the Caribbean. Once Nelson realised that the French were crossing the Atlantic, he set off in pursuit. He missed them by just days in the West Indies as a result of false information.

Cádiz: Having lured the British to the West Indies, Villeneuve returned from the Caribbean to Europe, intending to break the blockade at Brest.  Nelson, still in fear for Egypt, made to return to the Mediterranean. The fast sailing corvette taking word of his plans back to the admiralty spotted the French heading further north. On receiving this intelligence Lord Barham was alive to the enemy strategy and immediately ordered Admiral Cornwallis to combine his squadron with that of Vice Admiral Calder off Ferrol and to stretch out thirty to forty leagues into the Atlantic to block the French from entering the Channel.
Calder intercepted the French resulting in an inconclusive engagement during the Battle of Cape Finisterre in which two of the Spanish ships were captured. Villeneuve abandoned his plan and sailed back to Ferrol in northern Spain. There he received orders from Napoleon to return to Brest according to the main plan.
Napoleon's invasion plans for Britain depended on having a sufficiently large number of ships of the line protecting his port of Boulogne on the English Channel. This would require Villeneuve's force of 33 ships to join Vice-Admiral Ganteaume's force of 21 ships at Brest, along with a squadron of five ships under Captain Allemand, which would have given him a combined force of 59 ships of the line.
When Villeneuve set sail from Ferrol on 10 August, he was under orders from Napoleon to sail northward toward Brest. Instead, he worried that the British were observing his manoeuvres, so on 11 August, he sailed southward towards Cádiz on the southwestern coast of Spain. With no sign of Villeneuve's fleet, on 25 August, the three French army corps' invasion force near Boulogne broke camp and marched into Germany, where it was later engaged. This ended the immediate threat of invasion.
The same month, Admiral Lord Nelson returned home to Britain after two years of duty at sea. He remained ashore for 25 days and was warmly received by his countrymen. Word reached Britain on 2 September about the combined French and Spanish fleet in Cádiz harbour. Nelson had to wait until 15 September before his ship, HMS Victory, was ready to sail.
On 15 August, Cornwallis decided to detach 20 ships of the line from the fleet guarding the English Channel to sail southward to engage the enemy forces in Spain, leaving the Channel with only 11 ships of the line. The detached force formed the nucleus of the British fleet at Trafalgar. This fleet, under the command of Vice-Admiral Calder, reached Cádiz on 15 September. Nelson joined the fleet on 28 September to take command.
Hoping to lure the combined Franco-Spanish force out from Cadiz harbor and engage it in a decisive battle, Nelson kept his main force out of sight approximately 50 miles (80 km) offshore and sent a squadron of frigates (faster, but too small for the line of battle) to keep watch on the harbour This was led by Captain Blackwood aboard HMS Euryalus, with five frigates, a schooner, and a brig.

Supply situation: Nelson's fleet badly needed provisioning. On 2 October, 5 ships of the line, HMS Queen, Canopus, Spencer, Zealous, Tigre, and the frigate HMS Endymion were dispatched to Gibraltar under Rear-Admiral Sir Thomas Louis for supplies.

These ships were later diverted for convoy duty in the Mediterranean, although Nelson had expected them to return. Similarly, HMS Superb under Captain Richard Goodwin Keats had been sent to the dockyard for a re-fit after four years at sea including the chase of Villeneuve and was expected to return to the fleet where Keats was to be Nelson's second, but the ship was not released in time. Other British ships continued to arrive, and by 15 October the fleet was up to full strength for the battle. Nelson also lost Calder's flagship, the 98 gun Prince of Wales, which he sent home as Calder had been recalled by the Admiralty to face a court-martial for his apparent lack of aggression during the engagement off Cape Finisterre on 22 July.
Meanwhile, Villeneuve's fleet in Cádiz was also suffering from a serious supply shortage that could not be easily rectified by the cash-poor French. The blockade maintained by the British fleet had made it difficult for the Franco-Spanish allies to obtain stores, and their ships were ill-equipped. Villeneuve's ships were also more than two thousand men short of the force needed to sail. These were not the only problems faced by the Franco-Spanish fleet. The main French ships of the line had been kept in harbour for years by the British blockade with only brief sorties. The French crews included few experienced sailors, and, as most of the crew had to be taught the elements of seamanship on the few occasions when they got to sea, gunnery was neglected. The hasty voyage across the Atlantic and back used up vital supplies. Villeneuve's supply situation began to improve in October, but news of Nelson's arrival made Villeneuve reluctant to leave port. His captains had held a vote on the matter and decided to stay in harbour.
On 16 September, Napoleon gave orders for the French and Spanish ships at Cádiz to put to sea at the first favourable opportunity, join with 7 Spanish ships of the line then at Cartagena, go to Naples and land the soldiers they carried to reinforce his troops there, then fight decisively if they met a numerically inferior British fleet.

Fleets: 

British: On 21 October, Admiral Nelson had 27 ships of the line with  2148 cannons, and a total of  17000 crewmen and marines under his command. Nelson's flagship, HMS Victory, captained by Thomas Masterman Hardy, was one of three 100 gun first-rates in his fleet. He also had four 98 gun second-rates and 20 third-rates. One of the third-rates was an 80 gun vessel, and 16 were 74 gun vessels. The remaining three were 64 gun ships, which were being phased out of the Royal Navy at the time of the battle. Nelson also had four frigates of 38 or 36 guns, a 12 gun schooner and a 10 gun cutter.