Offer your insights or judgment on the input financial query or topic using your financial expertise. Reply as normal question answering

How does the U.S. wash sale replacement stock rule work?
From Pub 550: More or less stock bought than sold.   If the number of shares of   substantially identical stock or securities you buy within 30 days   before or after the sale is either more or less than the number of   shares you sold, you must determine the particular shares to which the   wash sale rules apply. You do this by matching the shares bought with   an equal number of the shares sold. Match the shares bought in the   same order that you bought them, beginning with the first shares   bought. The shares or securities so matched are subject to the wash   sale rules. You must match "beginning with the first shares bought." If only activity 1 & 4 happened, you'd have bought and sold stock with no wash sale. If you remove activity 1 & 4 from consideration because they are a "normal" or non-wash sale transaction, then the Activity 2 or Activity 3 trigger a wash sale. The shares in lot 1 are sold for disallowed loss, so the disallowed basis would be added to shares in lot 2 because lot 2 was purchased before lot 3. (hat tip to user662852 who had much better wording) Second example: Activity 5, 7, and 8 all together would not be a wash sale.   The addition of activity 6 creates a wash sale. The shares in Activity 5 are sold for a disallowed loss in Activity 7 & 8 because of the wash sale triggering purchase in Activity 6.   Activity 6 is where you add the disallowed basis because they are the "first shares bought" that cause the wash sale rule to be triggered.