When I place a market order or marketable limit order that successfully executes, should I consider the bid-ask spread as part of the transaction cost of my order? The bid-ask spread is appears to be a transaction cost, especially to a buyer or seller who crosses the spread using a market order. Is there anything wrong with this thinking? Should I record the full bid-ask spread, or should I record slightly less (due to "price improvements"), or should I record half the bid-ask spread (if I can assume that the "real price" is the midpoint of the bid and ask)?
What you pay for the security when you buy it is the cost and what you receive for selling it is the proceeds. These are the numbers that you 'record' and they are used for determining P&L, ROI, taxation, etc. The rest of it makes for a good cocktail party discussion of what ifs.
There are a number of variations but let's consider a simple three party transaction that includes the buyer, the seller and the market maker who buys at the bid and sells at the ask.
The midpoint of the bid/ask is the 'real price and 1/2 the of the B/A spread is the mark up/down. Bob buys at the ask from the MM and pays the mark up. Ted sells at the bid to the MM and is marked down (Carol and Alice are the wives). The MM collects the difference as the security changes hands. It is most definitely a cost because the B/A spread is now in the market maker's pocket.
The bid-ask spread is considered an "implicit" transaction cost in that it separates the cost purely from trading from the value of the actual security. Note that it does not matter for tax purposes, but it can be a factor if you're looking to minimize such costs and maximize the return solely from choosing good securities.
The effect of buying and selling on future orders (or subsequent lots within a large transaction) can also be considered an implicit transaction cost. If you want to (or have to) sell a large stake in a stock and can't do it in one transaction due to liquidity limitations, then just the act of selling may drive the price of the stock down, affecting the price at which you can sell smaller lots.
Note that both of these do not make a significant difference for retail investors, but can be significant for institutional investors if they are very active traders (even if "explicit" transaction costs like commissioins are zero). These implicit costs, if not managed appropriately, can be a minor drain on profitability.