I understand that code on Stack Overflow is licensed under a CC BY-SA 4.0 license, and that fair use doctrine may not apply to code snippets.

I also recognize that it is ideal to rewrite code posted on Stack Overflow in our own words, both for legal reasons and for the learning experience it presents. However, what about code that would be hard or impossible to rewrite in our own words because there is only one accepted way to write it? Would it possibly be ineligible for copyright?

For instance, let's say that I go to Stack Overflow because a Python math function like math.modf is not working. I then see a Stack Overflow post explaining that to make math functions work, you need to enter this line:

import math

If I copy and paste the import math code into my own program, then release it under a non-Creative Commons license, does that mean that I am violating copyright? I'm doubtful that this would be the case due to the originality requirement within U.S. copyright law:

The Originality Requirement

Originality is “the bedrock principle of copyright” and “the very premise of copyright law.” Feist Publications, Inc. v. Rural Telephone Service Co., Inc., 499 U.S. 340, 347 (1991) (citation omitted).

“To qualify for copyright protection, a work must be original to the author,” which means that the work must be “independently created by the author” and it must possess “at least some minimal degree of creativity.” Id. at 345 (citations omitted)


The above chapter goes on to say that:

“[T]here is nothing remotely creative” about a work that merely reflects “an age-old practice, firmly rooted in tradition and so commonplace that it has come to be expected as a matter of course.”

A line like import math does not strike me as very creative; rather, it is simply a required bit of code for getting Python's math library to run within a program. I doubt it would be necessary to rewrite the code as import math as m when import math works just fine.

In other words, I am wondering if the originality requirement implies that some code snippets on Stack Overflow may not be original enough to be copyrightable in the U.S. Please let me know your thoughts.

Additional notes:

  1. I do not believe that this FAQ post, while informative, addresses this specific question, since that post does not make any reference to the originality requirement for U.S. copyright. The answer to that post states, in part, that "Anything that you post to Stack Overflow will be under the terms of the Creative Commons license." However, I believe there are cases (such as the one in my example above) where a code snippet may not qualify for a Creative Commons copyright because it fails to meet the originality requirement. In fact, such cases may be substantial, especially for beginner-level questions that address general programming conventions.

  2. tpg2114 pointed out in the Meta forum (where this question had originally been posted) that a detailed explanation + import math or similarly non-original code block + detailed explanation as a whole would qualify for a CC license. I think my main concern is about situations where the code provided is the widely accepted best practice for a particular language, rather than someone's original creative work. In other words, if the line of code reflects how thousands of programmers around the world would accomplish a task because it's the best way to do so, I'm just doubtful whether a copyright license would apply.

  3. tpg2114 also helped me realize that a relevant question here is: if something can't be copyrighted, does it qualify for a Creative Commons license? The following quotes from the Creative Commons website indicate that material that can't be copyrighted also can't have a Creative Commons license applied to it:

  1. "CC licenses do not contractually impose restrictions on uses of a work where there is no underlying copyright."
  1. "CC licenses are operative only when applied to material in which a copyright exists, and even then only when a particular use would otherwise not be permitted by copyright."
  1. "You should also not apply Creative Commons licenses to works that are no longer protected by copyright or are otherwise in the public domain."
    Source for all 3 quotes
  1. This raises a new question: even if a post + code snippet as a whole are eligible for Creative Commons (due to the originality expressed in the text, for instance), if the code snippet by itself does not qualify for copyright because it's similar to import math, would I be able to use that without releasing my own program under Creative Commons?

I believe the following quote may help answer this question:

"To constitute an adaptation [which would need to be licensed under CC-BY-SA as well if the source was CC-BY-SA], the resulting work itself must be considered based on or derived from the original. This means that if you use a few lines from a poem to illustrate a poetry technique in an article you’re writing, your article is not an adaptation because your article is not derived from or based on the poem from which you took a few lines." Source

So in other words, if I take an excerpt like import math from a CC-BY-SA post on Stack Overflow and incorporate it into a larger project, my project may not be an adaptation of the Stack Overflow post, and therefore I may not need to release my project under CC-BY-SA as well. I say "may not" because (1) I'm not a lawyer, and (2) the code snippet isn't just an illustration or an example, but rather plays an important role in the functioning of my actual program.

  1. I also found this helpful article from an attorney that addresses whether simple code snippets can be copyrighted: However, this article states that Stack Overflow posts are covered by CC-BY, when in fact they're covered under CC-BY-SA.
  • 4
    It is certainly possible (and indeed almost certain( that this would be the case with some snippets. The issue would be what percentage of them. But it is difficult to quantify since it is a case by case analysis and there isn't a bright line test to determine whether it is or it isn't. There are a significant share that would by any reasonable analysis meet originality thresholds, and a very small percentage that clearly wouldn't. But there would be a big gray area. Pull out of my a--- estimates 70% copyrightable, 3% not, 27% gray area. The copyright standard is much lower than for patents.
    – ohwilleke
    Commented Mar 3, 2021 at 19:37
  • 1
    @ohwilleke Thank you for your response! With regard to snippets that wouldn't be copyrightable on their own, do you think it matters whether or not that snippet is part of a larger post that would be copyrightable and thus fall under CC-BY-SA 4.0? My sense is that using that snippet without using the rest of the text would mean that my new work wouldn't be an adaptation of the original work, so therefore I'm doubtful that I would need to apply the CC-BY-SA license to my new work.
    – KBurchfiel
    Commented Mar 3, 2021 at 21:02
  • @KBurchiel I don't know the CC licensee variants well enough to give you a well founded answer without a lot of research.
    – ohwilleke
    Commented Mar 3, 2021 at 21:20
  • Previously on softwareengineering: softwareengineering.stackexchange.com/questions/12171/… In particular, this answer re: threshold of copyrightability and de minimis copying: softwareengineering.stackexchange.com/a/375666/180482 Commented May 20, 2021 at 17:34

1 Answer 1


You are in general correct, KBurchfiel. A code snippet such as

import math;


For i := 1 to 10  
  print i;

has no originality, and is not protected by copyright. A post eplaining the meaning an usage of such a snippet might well be original enough to be protected by US copyright, indeed it probably would. But the code on its own would not be. Anyone could read such a post, and if s/he understood it, use the code snippet and not be in violation of copyright, not compelled to place the entire program in which such a snippet was used under a CC-=BY-SA license.

The creative commons people would prefer that a CC license not be applied to a publication that is not protected by copyright, and if it is so applied it is legally meaningless. But they have no legal way to enforce such a preference.

A stack exchange post that consisted of nothing but such an uncopyrightable code snippet, with no explanation r discussion, might well be downvoted or even deleted. But that is a matter of site policy on what is a useful answer, not a matter of copyright.

Using an excerpt from a copyrighted work so small that the excerpt alone would be uncopyrightable, would probably be fair use under US law, and might well be fair dealing in UK law.

Something that is fair use does not compel the reuser to abide by the terms of a CC license, because those terms apply only when the content could not be reused without the CC license's permission.

However, a code snippet does not need to be very much more original than the above examples before it becomes copyrightable. Whether it can be used via fair use rather than via the CC-BY-SA license is a very fact-based decision (the usual four-factor analysis is spelled out in 17 USC 107).. But if the snippet can be rewritten to express the same concepts but in a different expression, then there is no copyright issue, and again the CC license will not apply.

If the snippet is complex and original enough to be copyrightable (a fairly low bar) and it is re-used unchanged, under conditions where fair use does not apply, then the CC-BY-SA license's terms must be complied with for the use to be legal. That is several "IFs" however. The exact details of a specific case will matter in such cases, there is not one rule for all snippets, all posts, or all programs.

  • Thank you for the thorough response!
    – KBurchfiel
    Commented May 22, 2021 at 23:36
  • I read this analysis as subtly different from @KBurchfiel's, and I suspect that KBurchfiel's analysis is more precise. This answer says that copying import math is fair use because it's so small. But that seems off to me. That analysis might apply to copying two lines of a modern sonnet, for example, where those two lines are a small excerpt of a larger original work. But suppose the modern sonnet was constructed around two lines of a Shakespeare sonnet by writing 12 additional lines, and the two lines being quoted are the reused lines. That's not fair use, it's just public domain.
    – phoog
    Commented May 23, 2021 at 5:12
  • There are several lines of reasoning that lead to the conclusion that import math is not subject to copyright protection. It's not creative; the author of the post did not originate it; it is a formulaic instruction for a machine.
    – phoog
    Commented May 23, 2021 at 5:16
  • @phoog you misstate my analysis. I said that "Import math" was too simple and unoriginal to be protected by copyright at all, and therefore copying it is not infringement. I further said that IF a larger and more complex snippet, which was copyrightable, was copied, that might be fair use, dependent on the usual multi-factor fair-use analysis. And if and only if fair use applied, then the terms of the CC license did not apply, which was a major issue asked about in the question. Commented May 23, 2021 at 12:38
  • 1
    @DavidSegal thank you for your response. Perhaps I read the answer too hastily. I will read it again when I have a bit more time.
    – phoog
    Commented May 23, 2021 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .