When you want to buy a property, you will choose a solicitor who will act as a middleman for both parties.
Once you've decided the property you want to go for, you will ask the seller for a nota simple informativa del Registro de la Propiedad: it will check that the property belongs effectively to the seller, check whether it's free of debts and will give a full description of the property (very useful).
When seller and buyer agree, and before the public deed is ready, there will be a contract in place. It's usually a simple document in which the seller expresses his intent to transfer the property to the buyer, and vice and versa. After signing the document, if the buyer withdraw, he will loose his deposit. If the seller withdraw, he will have to pay double.
The transfer of the ownership of the property must be secured by a solicitor (or public notary). The deed will be given to the buyer after all the parties agree with its contents. The buyer will then have to present a proof of identity, the payment, and the seller will give the title of property (a form that reports the investment to the Central Register). Eventually the contract will require 3 signatures: the buyer, the seller and the solicitor.
The buyer will have to pay transfer tax and stamp tax (Impuesto de transmisiones patrimoniales y actos jurídicos documentados).I will depend on who is selling. If the seller is an individual, the tax is 6% of the price specified in the deed ; if the seller is an estate developer and it's a first-time transfer, then an IVA tax applies instead, meaning 7% for housing, 16% otherwise (for housing, you have to add a stamp tax of 1.5% for Madrid). The seller will pay a local tax called the plusvalia.