What is the BAT file format?
.bat is the extension for DOS batch files run from the Windows command shell, cmd.exe.
Contents of .bat files
.bat files contain commands for the command shell. Batch files let users automate tasks and run multiple commands in sequence, manage applications, or control computer resources. A well-known example is AUTOEXEC.BAT, located in the root folder of the system drive on Windows 95, 98 and Me; commands in that file executed automatically at system start to launch applications and modify default settings. Today .bat files remain fully supported on all Windows versions; their close sibling, .cmd, is the Windows NT-era equivalent with command extensions enabled by default.
Can I open .bat files?
.bat files store commands in plain text and can be edited with any text editor. However, users should take care in how they open .bat files - by default, double-clicking a .bat file automatically loads it into memory and executes its commands. Right-clicking the file and selecting Edit from the context menu lets users modify the .bat file without running its instructions. For more capable scripting, PowerShell scripts (.ps1) are the modern Windows alternative.
Can a .bat file be dangerous?
Keeping in mind that commands saved in .bat files can let the system run virtually any operation, access system resources, or install software, the risk that such files can be used to install potentially dangerous software or even destabilize the machine is real. Therefore it is recommended that users not run .bat files from unknown sources. Best practices recommend that before running any .bat file users should review its contents - even files that have been on the machine for a long time. A malicious program might have modified one or more harmless .bat files in a way that running them now causes damage to the system or installs malicious software.
Security & safety
RISK: HIGHA .bat file is EXECUTABLE: double-clicking runs every command immediately with your user privileges - it can delete files, change settings, download and launch other programs, or disable security tools. It is a common malware vector, frequently obfuscated or used as a 'dropper' that fetches a real payload, and is often disguised as a helpful 'fix', 'crack' or 'optimizer'. SAFE HANDLING: never double-click an untrusted .bat. To inspect it, right-click to Edit (or open in Notepad/Notepad++/VS Code) and READ the commands - opening in an editor does NOT execute them. Red flags inside: commands that call powershell/curl/bitsadmin to download files, base64/garbled strings, attempts to disable Defender, or writes to system folders and the registry. If unsure, upload the file to VirusTotal (it's text, so it's safe to upload) and run it only inside a VM/sandbox.
Format details
in a nutshellPrograms that open BAT files
Technical details
deep spec| Execution engine | cmd.exe (Windows Command Processor) - the shell reads and executes each line sequentially at runtime |
| File encoding | ANSI / Windows-1252 or ASCII; UTF-8 is accepted but a BOM (EF BB BF) at the very start breaks the first command |
| Magic bytes / signature | None - plain text identified by the .bat extension only; most files begin with the line @echo off |
| Comment syntax | REM keyword (official) or :: (a double-colon label trick widely used as a single-line comment) |
| Variable syntax | %VARIABLE_NAME% for environment variables; %1-%9 for positional parameters passed on the command line; %* for all arguments |
| Control flow constructs | Labels (:name), GOTO, CALL (subroutines or child scripts), IF / ELSE, FOR loops, SETLOCAL / ENDLOCAL scoping |
| Error handling | ERRORLEVEL pseudo-variable; IF ERRORLEVEL n checks; && and || conditional execution operators (requires command extensions) |
| Typical file size | 100 bytes to ~50 KB - from a few lines to a lengthy automation script |
| Sibling format | .cmd is the Windows NT-era counterpart; command extensions are on by default, giving more reliable ERRORLEVEL and FOR /F behavior |
| Code signing | No native signature mechanism - unlike PowerShell .ps1 scripts, .bat files cannot be digitally signed or policy-restricted by execution policy |
| Security behaviour on execution | Double-clicking runs the file immediately without any preview; files downloaded from the internet receive a Mark-of-the-Web flag that triggers a SmartScreen prompt |
| Superseded by | PowerShell (.ps1) for modern Windows automation, though .bat / .cmd remain fully supported and in widespread use |
| Associated platforms | Windows (all versions), MS-DOS (origin), OS/2 (limited compatibility) |
| MIME type | application/x-bat (also encountered as application/bat, application/x-msdos-program, and text/plain) |
| Released | 1981 (MS-DOS 1.0; AUTOEXEC.BAT since MS-DOS / PC DOS) |
| Latest version | No versioned spec; behavior tied to the cmd.exe of the Windows release (Windows 11 cmd as of 2026). .cmd is the NT-era sibling. |
| Specification | learn.microsoft.com |
BAT conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about BAT files.