The spread is a cost you pay by crossing it. Suppose a stock is quoted at a bid of $19.98 and an ask of $20.00. A buyer using a market order pays $20.00; a seller using a market order at the same moment receives $19.98. The 2-cent gap is the spread, and a round trip, buying then immediately selling, would lose that 2 cents per share to nothing but the spread. On a heavily traded stock that gap is trivial, but it is always present and always paid by whoever crosses it to trade immediately.
Liquidity is what sets the width. A security that trades in large volume with many buyers and sellers has a narrow spread, often a penny or less, because competition among traders keeps the bid and ask close together. A thinly traded security, a small stock, an obscure bond, an option far from the money, has a wide spread, because there are fewer participants and more risk in quoting a price. This is a concrete way that illiquidity costs money: the same order costs more to fill in a market with few participants, and the extra cost is invisible because it is embedded in the price rather than charged as a fee.
The spread is the market maker's pay. In many markets a market maker or dealer stands ready to buy at the bid and sell at the ask continuously, providing the liquidity that lets others trade whenever they want. The spread is that firm's compensation for the service and for the risk of holding inventory that may move against it before it can offload. This is why the spread widens when markets are volatile or a security is hard to hedge: the risk of quoting a price has gone up, so the price of providing liquidity goes up with it.
A limit order lets you sit inside the spread instead of paying it. A market order accepts the current bid or ask and pays the spread for immediacy. A limit order can be placed between the bid and the ask, offering to buy a little above the bid or sell a little below the ask, which can capture part of the spread rather than pay it, at the cost of the trade possibly not filling. So the spread is not an unavoidable tax on every trade; it is the price of demanding immediate execution, and an investor willing to wait can often reduce it.