Sweet shrimp in garlicky olive oil is just about the ideal tapas bar snack. The sweet shrimp and garlic aroma go perfectly with a nice sherry, while the leftover oil at the bottom of the earthenware dish is the ideal sopping-up liquid for good Spanish bread. It's also one of those dishes that, even when mediocre, is still pretty darn good. I've eaten enough mediocre gambas al ajillo in my day—even in Spain!—to say that with confidence.

But when it's done perfectly, when the shrimp are juicy and tender with a crunchy pop, when the oil sings with a chorus of layered garlic flavors, it can be transcendent. That's what we're after today.

The traditional preparation for gambas al ajillo is overwhelmingly simple: heat up olive oil in an earthenware cazuela on a fire until hot. Add some slivered garlic and shrimp, cook them briefly, perhaps with a touch of red pepper or a bay leaf, finish it off with a shot of brandy or sherry vinegar, and serve it all with a sprinkle of parsley.

Using that method gives you good results, but you can do better. Let's break it down one element at a time.

The Shrimp

Head-on shrimp are generally pricier than their headless brethren, but here's the truth: they're usually worse as well. The issue is that shrimp heads contain powerful enzymes that start to break down shrimp flesh as soon as they die. Within hours, head-on shrimp will become noticeably mushier. Headless shrimp, on the other hand, have their heads removed before shipping, which means that their bodies retain their fresh, briny crunch. Unless you can get your shrimp live (a possibility if you live near a good Asian market), you're better off going with the headless version.

While we're at it, you're also better off buying frozen shrimp. Why is that? It's because pretty much every shrimp you'll ever see at the supermarket or fishmonger was frozen at sea. Those "fresh" shrimp they're selling? All they are is frozen shrimp that have been thawed out at the store, and who knows how long they've been sitting there thawed? Your best bet is to get them frozen and thaw them yourself.

I buy regular shell-on shrimp for three reasons. First, shelled shrimp are often mangled and unappetizing. Secondly, shell-on shrimp tend to be much cheaper. Finally, those shells pack a sweet, flavorful punch. Remember that scene in Willy Wonka and the Chocolate Factory where Gene Wilder sings that melancholy song while sipping sweet nectar out of a flower-shaped tea cup, then finishes by eating the tea cup? Yeah, shrimp are sort of like that. Throw out the shell and you're missing out.

The question, of course, is how do you make the most out of both the flesh and the shell? I use a three-step process. First, I marinate the shrimp. Next, I infuse oil with flavor from the shell. Finally, I gently cook the marinated shrimp in the flavored oil, doubling up on shrimp flavor. And while I'm at it, I use the same processes to introduce layers of garlic flavor.

The Garlic

Depending on how you introduce and cook garlic, its flavors can vary pretty drastically. When it comes to my raw shrimp, I like to add plain grated garlic. The shrimp only cook for a few moments later on, so the garlic remains nearly raw—it cooks just enough to get rid of its raw edge, while still maintaining its spicy bite.

Oil and salt also go into the marinade, along with a dash of baking soda. Why salt and the soda? It's a trick I learned when working on my recipe for The Best Wonton Soup.

Salt acts like a brine, helping the shrimp retain their juiciness, while baking soda causes the flesh to turn a little crunchy. It's an ancient Chinese secret. Or something like that. Either way, it works.

I set the marinating shrimp aside at room temperature for the salt and baking soda to work their magic while I start working on the rest of the oil.

Let's get one thing straight: Spanish-style shrimp is an oily dish. Some would argue that the shrimp and garlic-infused olive oil is actually the best part of the dish. An extra treat for you to sop up with your bread when you get to the bottom of the bowl.

Which is essentially to say: be generous with it. I use a full half cup of olive oil for a pound of shrimp. As I mentioned, I add my shrimp shells to the oil to infuse. At this stage, I also add some smashed garlic cloves and a pinch of red pepper flakes (even better is a strip of dried guajillo or other sweet and fruity chili). Set over moderately low heat for about ten minutes, the garlic softens and sweetens and the shrimp shells turn a deep ruby red. Both of them impart sweetness and an intense aroma to that oil.

After the oil is infused, it's time to add the final layer of garlic: fried fresh slices. I fry the slices in the strained oil until they turn golden brown before returning the marinated shrimp to the pan. The key here is to cook the shrimp—just—until they're cooked through. They go from crisp and tender to tough and chewy in a matter of moments. It's better to err on the side of undercooked, as they'll continue to cook on the way to the table.

A dash of sherry vinegar and a handful of chopped parsley add some bright flavors to the sweet and oily mix.

By the way, that thing that those show-offy Spanish restaurants like to do, where youe shrimp comes in a hot cazuela sizzling away in bubbly-hot oil? It looks cool, but all it actually succeeds at is ensuring that your shrimp overcook as they sit there, bubbling away. Steer clear!

I don't always eat shrimp, but when I do, I like them garlicky, and this dish delivers it in spades.