Among the highest compliments a musician can receive is praise that their latest single sounds… super familiar. Sometimes, that’s a testament to crafting a hook so undeniable it feels like it’s always been in your ears. But other times, you’re not wrong — it was in your head all along. Think of Olivia Rodrigo’s second single, “Deja Vu.”

That top 5 Hot 100 hit sounded so much like her hero Taylor Swift’s “Cruel Summer” that Swift, along with collaborators St. Vincent and Jack Antonoff, were retroactively given songwriting credits thanks to Rodrigo’s homage to Swift’s shouty bridge. That marked the second credit Swift picked up on Rodrigo’s debut Sour, after “1 Step Forward, 3 Steps Back” added her thanks to a sample of Taylor’s Reputation song “New Years Day.”

And though Rodrigo drew inspiration from the same source on two different songs, the way those credits manifested are distinct in subtle, but crucial ways that can sometimes lead to legal action if the artist is not careful. One is the more recognized form of homage known as sampling, while the other is known as interpolation.

“For me it seemed like a natural extension of what jazz payers did when they were playing a solo… slipping two bars of ‘Hail to the Chief’ or quoting a bit of Charlie Parker as a wink to the hipsters in the crowd,” Columbia Law School lecturer and intellectual property attorney Bob Clarida tells Billboard about his take on the art of interpolation.

“It’s a way of showing you were in the know and having fun with improvising by sticking a bit of another song into a new piece of music with the expectation that it would be recognized as such,” he says. “That’s the whole point of putting it in there… making a new thing and putting an existing chunk into it. When you sample in hip-hop, though, you’re saying, ‘Oh, that’s a great drum sound or snare in that Led Zeppelin song,’ and you use that existing sound recording, not just taking notes and melody, and putting it into a new sound recording.”

In technical terms, a sample is a lift from an existing sound recording placed into another sound recording, what composer and Copyright Law Deskbook author Clarida described as akin to “inserting one photo into another photo.” Whereas an interpolation is making a new piece of music in which you don’t sample the original, but either sing or play a piece of it yourself with an acknowledgement of such — think MGK and Camila Cabello’s 2016 hit “Bad Things,” which obviously folded in parts of the chorus and piano line from indie rockers Fastball’s 1999 song “Out of My Head.”

Sometimes, though, the line between the two is blurred and artists end up in court defending themselves against a claim that they purposely, or perhaps inadvertently, interpolated someone else’s song into their own. Two of the most notorious recent examples involve Led Zeppelin — who prevailed in a long-running copyright dispute with fellow UK rockers Spirit over a claim that Zep’s iconic “Starway to Heaven” infringed on their song “Taurus” — and Robin Thicke, who lost a landmark 2015 case in which a jury found that his “Blurred Lines” infringed the copyright on Marvin Gaye’s “Got to Give It Up.”

Dr. Alexander Stewart, a musicologist and music professor at the University of Vermont who served as an expert witness in the Spirit/Zeppelin case, tells Billboard that such cases often hinge on whether the artist knowingly interpolated a prior work and whether the prosecution can convince a jury of such. “Intent doesn’t really matter… the main thing is that you have to prove is access,” he says about the sometimes tricky process of convincing a jury that an artist purposely borrowed from an existing composition.

You don’t have to prove that the borrower definitely had access, he says, but only that they could have. In the Zeppelin case, Stewart — an accomplished sax player who has recorded and performed with Lionel Hampton, Dizzy Gillespie and Wynton Marsalis, among others — was originally hired to compare the two recordings. He says Zeppelin’s Jimmy Page and Robert Plant said they had never heard the Sprit song, a claim he calls “completely absurd, since they opened for Spirit on their first tour and Spirit played that song every night, and one of them had the record in their collection!” (He notes that Spirit won that prior access point in the case, even though Zeppelin ultimately prevailed.)

It was a different story for Thicke, who could not have denied prior access to the Gaye song, since he and co-writer Pharrell famously copped to loving and wanting to pay homage to “Got to Give It Up” multiple times during the “Blurred Lines” press tour. In the latter case, Stewart says there was no way for Thicke’s lawyers to prove that the lift was incidental, which is why the jury hit the pair with a landmark $5 million damages verdict.

Given how much music most artists consume in their lives, both before and after they’ve released their own recordings, is it possible to “accidentally” interpolate another musician’s work? That was essentially the argument in a lawsuit brought against late Beatle George Harrison, who was ordered to pay $587,000 for what he described as a subconscious lift from the Chiffons’ 1963 “He’s So Fine” in his song “My Sweet Lord.”

In his biography I Me Mine, Harrison said he “wasn’t consciously aware of the similarity” to the Chiffon’s girl group hit,” which he surely would have heard when it topped the Billboard Hot 100 singles charts for four weeks in 1963. Instead he said his track was “more improvised and not fixed.” But even Harrison eventually heard what others did, writing, “Why didn’t I realize? It would have been very easy to change a note here or there, and not effect the feeling of the record.”

Stewart says that as a professor who teaches classes to musicians and non-musicians alike, he’s used to talking about music to people who aren’t necessarily trained performers. “That’s an important skill to be able to translate or explain these musical principles in ways people can understand,” he says, before going into a description of how his attempt to explain the intricacies of the chromatic scale was cut off during the Zeppelin trial due to time constraints.

And though there are very few “Perry Mason” scenes where a lawyer or expert presents explosive, gasp-inducing evidence in most of these cases — which are typically quietly settled — he did recall one such “a-ha!” moment. The case that resulted in a temporary halt in sales of the Notorious B.I.G.’s 1994 debut album Ready to Die in 2006, when Bridgeport Music and Westbound Records won a $4.2 million judgement in a federal lawsuit claiming that Bad Boy Records boss and album executive producer Sean “Diddy” Combs illegally used samples of the Ohio Players’ 1992 song “Singing in the Morning” on the album’s title track.

In that case, he says that the significance of the music at issue — to each composition — is a key factor. “In this [Ohio Players] case they were trying to say the sample from the Ohio Players was not significant, and that it was an isolated, unimportant part of the song,” says Stewart. “That night in huddling with some attorneys at the hotel, I said, ‘What if I go online and see how the songs were marketed at the time?’”

And, a-ha, he realized that the 30-second sample teasers of the B.I.G. song on several outlets that were major distributors of CDs featured the “exact segment” of the rapper’s song that used the Ohio Players sample. “‘This is it!’” he recalls thinking. “The attorney said, ‘set it up and go online in the courtroom and search for these songs on the major vendors and play the clip for the jury used to promote the song.’ I played it for the jury and they were all nodding their heads — and I knew at that moment that it was a significant expression.” (In that case, Stewart says, Diddy’s response was to “wipe out” the samples on the re-worked version of the song.)

In a nod to how contentious the issue has become today, Stewart says that while lawsuits over interpolations have decreased lately, avoiding them has become a whole second business for him. In an attempt to avoid potential legal action, he’s been asked by a number of major, unnamed artists to do a kind of pre-clearance on their music. He’s increasingly tapped to analyze a new song if there’s a concern that it sounds too familiar to “tell them whether they need to worry or not.”

In almost all cases these, he says, he informs an artist’s team or lawyer that there could be a problem with a familiar-sounding melody. “In the majority of the potential cases brought to me I have to tell the client or attorney that I don’t find a substantial similarity,” he adds, explaining that when he does do an analysis he transcribes the music and compares it note-for-note.

Complicating matters further for songwriters these days, Stewart says, is that anyone can upload a song to Soundcloud, YouTube or another sharing site and later say that their original work was clearly ripped off, regardless of how much impact it had on the charts, radio or streaming.

“Reasonably, anybody could hear anything at any time,” says Stewart.