May I use a snippet I copied?
Short answer
Usually yes, on the terms it was published under: Stack Overflow content is CC BY-SA 4.0, newer MDN code samples are CC0, and an unlicensed GitHub repository grants nothing.
Stack Exchange lists four attribution requirements for its content. MDN code samples added before 20 August 2010 are MIT. GitHub does not claim ownership of Copilot output, but its terms make you responsible for any third-party licence that output carries. Record the source URL, licence and date in a comment beside every pasted block.
Where snippets come from
- CC BY-SA 4.0 All user content on the Stack Exchange network, with four attribution requirements. Stack Exchange Data Dump page
- CC0 / MIT MDN code samples added on or after 20 August 2010 are CC0; earlier samples are MIT. MDN attribution and copyright licensing
- No licence Without a licence, default copyright applies and no one may reproduce, distribute or create derivative works. GitHub Docs
What licence applies to Stack Overflow code?
Stack Overflow answers are published under a Creative Commons Attribution-ShareAlike licence, not a software licence. On its Stack Exchange Data Dump page, Stack Exchange, Inc. states that all user content contributed to the network is CC BY-SA 4.0 licensed. The same page lists four attribution requirements: show that the content comes from the Stack Exchange network, link directly to the original question, show the author names for every question and answer used, and link each name to the author's profile page.
Stack Overflow's own licensing help page, which explains which licence version covers posts of different dates, could not be opened from our checking environment, so this page does not say which earlier version covers an older post.
The ShareAlike part is the one developers trip over. Section 3(b) of the CC BY-SA 4.0 legal code says the licence you apply to an adaptation you share must be a Creative Commons licence with the same elements, this version or later, or a BY-SA compatible licence. Section 3(a) requires you to identify the creator, keep a notice referring to the licence, link the material where reasonably practicable, and say if you modified it.
Creative Commons itself recommends against using its licences for software. That mismatch is why many teams avoid pasting large Stack Overflow blocks into proprietary code and write their own version after reading the answer. Section 2(a)(2) of the legal code adds that where an exception such as fair use applies, the licence does not apply; whether a few lines qualify is a legal judgement.
What licence covers MDN code samples?
Two licences, split by date. MDN's attribution and copyright licensing page says code samples added on or after 20 August 2010 are in the public domain under CC0. Samples added before that date are under the MIT licence.
MDN adds a caveat: since its new platform launched on 14 December 2020, there is currently no way to determine which of the two applies to a given sample. Keeping a source link costs nothing. MDN's prose is different: documentation text is CC BY-SA 2.5 or any later version, with attribution to Mozilla Contributors.
Can I use code from a GitHub repository?
Only on the terms the repository grants. GitHub's documentation on licensing a repository says that without a licence, the default copyright laws apply, and no one may reproduce, distribute, or create derivative works from the work. Under GitHub's Terms of Service, other users may view and fork a public repository on GitHub; that does not cover pasting its code into your own product.
Look for a LICENSE file or a licence line in the README, or ask the author. Copyleft licences such as the GPL can bring their terms with them into the program a snippet ends up in, so check before mixing them into permissively licensed code.
What licence applies to an AI assistant's suggestion?
No licence in the usual sense, and no guarantee. Section J of the GitHub Terms of Service, effective 27 April 2026, states that GitHub does not claim ownership of Input or Output. The same section says Output may resemble code in the model's training data or be subject to third-party copyrights or open source licence terms, and that you are responsible for determining whether your use requires a third-party licence.
If a suggestion matches someone else's licensed code, that licence applies as if you had copied it yourself. Whether anyone owns the unmatched suggestion at all is a copyright question; under current US guidance, unedited generated code is usually not protected.
Visible is not licensed: code you can read on a public page is still someone's, on whatever terms they chose or none.
What does a credit comment look like?
Write it at the moment of pasting, while the URL is still in the address bar. A workable format is four comment lines: Source, with the answer or page URL; Author, with the display name and profile link; Licence, with the identifier and licence URL; and Copied, with the date and what you changed. For an assistant's suggestion, record the tool, the date, and whether any public-code match was reported.
For whole files or commits, put the same facts in the commit message.
How we checked
Checked on 2026-10-15 by the CodeLifter editors: the Stack Exchange Data Dump page on archive.org, MDN's attribution and copyright licensing page (last modified 10 September 2026), GitHub's Licensing a repository documentation, Section J of the GitHub Terms of Service, the CC BY-SA 4.0 legal code and the Creative Commons FAQ. Stack Overflow's own licensing help page could not be opened, so no per-date version table is given. Drafted with AI assistance; every claim checked against its source. Not legal advice.
Questions and answers
Can I use code from Stack Overflow in a commercial project?
Yes, if you meet CC BY-SA: Stack Exchange states its user content is CC BY-SA 4.0 and requires attribution with links to the question and author profiles. ShareAlike applies to adaptations you share, which many companies avoid by rewriting.
Do I have to credit Stack Overflow answers in my code?
Yes. Stack Exchange lists four requirements: indicate the Stack Exchange source, link the original question, show each author's name, and link each name to the author's profile page.
What licence is MDN code under?
Samples added on or after 20 August 2010 are CC0; samples added before are MIT. MDN says it currently cannot show which applies to a given sample, so keep a source link.
Is code on GitHub free to use?
Only if the repository grants a licence. GitHub's documentation says that without one, default copyright applies and no one may reproduce, distribute or create derivative works.
Who owns code that GitHub Copilot suggests?
GitHub's Terms of Service, Section J, say GitHub does not claim ownership of AI output and that you must check whether it needs a third-party licence.
Is CC BY-SA a good licence for code?
Creative Commons recommends against using its licences for software and encourages software licences instead. CC BY-SA code still binds you when you copy it.
Do short snippets need attribution at all?
The CC BY-SA 4.0 legal code says the licence does not apply where an exception such as fair use covers your use, but that is a legal judgement. Crediting costs one comment line.
Sources
An editor checked every claim on this page against these sources on 2026-10-15. If a source has changed since, the source is the authority.


