Warm the milk with vanilla. In a medium saucepan, add the milk and half the sugar (1/4 cup). If using a vanilla bean, split it, scrape the seeds into the milk, and add the pod. Heat over medium until steaming and just starting to bubble around the edges.
Do not boil.
Whisk the yolk mixture. In a separate bowl, whisk the egg yolks, remaining 1/4 cup sugar, cornstarch, and a pinch of salt until smooth and slightly lightened. It should look thick and glossy with no lumps.
Temper the eggs. Slowly drizzle about 1/2 cup of the hot milk into the yolk mixture while whisking constantly. This warms the eggs gently and prevents scrambling.
Repeat with another 1/2 cup of milk, whisking until combined.
Combine and cook. Pour the tempered yolk mixture back into the saucepan with the remaining hot milk. Return the pan to medium heat and whisk steadily, reaching the corners of the pot to prevent scorching.
Thicken to the right consistency. After 2–4 minutes, the mixture will start to thicken. Keep whisking until it reaches a smooth, pudding-like texture with slow bubbles plopping up.
Let it bubble for 20–30 seconds to cook off the raw starch taste. If it looks lumpy, keep whisking; it will smooth out.
Finish with butter and vanilla. Remove from heat. If using vanilla extract, add it now.
Whisk in the butter until fully melted and the cream is silky. If you used a vanilla bean, remove the pod.
Strain for extra smoothness. For a flawless texture, push the pastry cream through a fine-mesh sieve into a clean bowl. This catches any bits and makes it extra velvety.
Cool properly. Press plastic wrap directly onto the surface to prevent a skin.
Let it cool at room temperature for 20–30 minutes, then refrigerate until cold, at least 2 hours.
Use or store. Before using, whisk the chilled pastry cream briefly to restore its smoothness. It should be thick but creamy and easy to spread or pipe.