The date of when you were paid, and thus, the money was deducted from your earnings determines what tax year it applies to. There are many situations when the money is not deposited until the next tax year, but it is irrelevant for W2/tax reporting. Always go with your YTD payroll data, not your 401k recordkeepers YTD totals.
If you are looking for a quick formula to help determine what % to contribute to spread out over the entire year, go with:
$18,000 / Your estimated taxable earnings X 100 = your target %
Example 1:
$18,000 / $75,000 x 100 = 24. So if you make $75k and you want to max out $18k, you need to contribute 24% for the entire year.
Example 2:
$18,000 / $140,000 x 100 = 12.857. So if you make $140k and you want to max out $18k, and you have to put in whole percentages, I would go with 13% and check that your payroll provider will cap your contributions at $18,000 when you hit the limit, or reduce from 13% to 12% towards the end of the year to get as close as possible.
If your employer allows you to put in whole dollar amounts instead of %, it makes it even easier.
Also, if you have any variable pay like a bonus or over-time, etc., that will complicate your calculations and you should confirm if those extra earnings are also included as 401k-eligible.