File Extensions That Can Run Code: What to Know
Understand which file extensions are just data and which can run programs, so you know when double-clicking deserves caution.
Every file name ends with a short tag, called an extension, that tells your computer how to treat it. A .jpg is a picture, a .txt is text, and a .pdf is a document. But some extensions tell your computer to run instructions instead of simply showing content. Knowing the difference is one of the simplest ways to avoid trouble.
What an extension does
The extension is a label that associates the file with a program. When you double-click a photo, your computer opens an image viewer. When you double-click a program file, the computer runs it. That second case is where danger lies, because a harmful program can do things such as delete files, steal information or install other software.
Extensions that usually run programs
On Windows, common executable and script types include .exe, .msi, .bat, .cmd, .com, .scr, .ps1, .vbs and .js. On macOS, installers and apps such as .app, .pkg and .dmg can run or install software, and shell scripts can too. Java programs use .jar, and some systems run shortcuts or link files that point to other commands. You do not need to memorize the list. Remember the idea: if the file is a program or a script, it can act on your computer.
Extensions that are usually data
Images such as .jpg and .png, audio such as .mp3, plain text and most videos are normally treated as content to display or play. They are generally safer, though not completely risk-free, since software that opens them can sometimes contain bugs. Keeping your software updated reduces that risk.
Documents that can carry risks
Office documents and spreadsheets can include macros, small programs inside the document. If you open a file and it asks you to enable macros or editing to see the content, be careful. Unless you know exactly why a macro is needed and trust the sender, leave it disabled. PDFs are normally safe, but outdated readers have had security problems, so keep them updated.
Archives and disk images
Archives such as .zip, .7z and .rar are containers. They are not harmful in themselves, but what is inside might be. Disk images such as .iso and .dmg also hold files, which may include installers. Look inside before running anything.
Double extensions and hidden names
Attackers often disguise programs with names like holiday-photo.jpg.exe. If your computer hides extensions, you may see only holiday-photo.jpg. Turn on the option to show extensions so you can read the full name. A file that claims to be a picture but ends in .exe is a clear red flag. Icons can be faked as well, so do not rely on them alone.
Build a simple habit
Before opening a file, ask three questions:
- Do I know where this file came from?
- Does the extension match what I expect?
- Could this file run code, and do I want that?
A full routine is laid out in how to check a download before you open it, and the tricks used on download pages are covered in spotting fake download buttons and bundled installers.
Let your system help
Keep your operating system's built-in protections turned on. Many systems display a warning for files from the internet and may block unknown programs by default. Do not turn these off to save a click.
If you opened something by mistake
Disconnect from the network, run a full scan, change important passwords from another device and check for unfamiliar programs. If you are unsure what to do, ask a trusted technician.
Frequently asked questions
Can a .txt file be dangerous? A plain text file itself does not run, but a file renamed to look like text might not be one. Always check the full name and type.
Are all .exe files bad? No. They are the normal way to install many programs. The key is whether you trust the source.
Do phones have the same issue? The types differ, but the principle holds. Install apps only from official stores and be cautious with files from unknown senders.