We have inverse aggregate supply and demand curve and our product is sold at the market equilibrium price. We know that a demand curve is downward sloping, that means there will be less goods demanded at a higher price because there will be individuals whose willingness to pay for the product is lower than the price. If the price decreases, the utlity these individuals gain from the product is bigger than anything else they could afford for the money they have (their opportunity costs) and they will be willing to trade it. If the state puts a sales tax on the product, the product gets more expensive and less of it will be traded because some consumers will no longer be willing to buy it. The deadweight loss means that the money raised by the tax is smaller than the decrease in consumer and producer surplus that arises from the tax because less products will be traded. There is less products for which the consumers willingness to pay is higher than the market price and there is less products for which the market price is higher than the marginal cost of production for the firms.
To calculate the deadweight loss, we plug the new price for the product which is the old one plus the tax into the inverse demand function to find out what quantity will be demanded at that price. We take this quantity and solve the inverse supply function for the price that the suppliers would have demanded at this price. Then we subtract the price for the suppliers from the price for the consumers and the new quantity demanded from the old one and multiply these values with one another and with 1/2 to find our deadweight loss. Why 1/2? Because, graphically, the deadweight loss is the triangle between the demand and supply curve, with one corner being the old equilibrium and the others the new price for the consumer and the new quantity and the other the new price for the suppliers and the new quantity.