cipher - Encrypt Folders and Wipe Free Space

Maintained on
Table of Contents

The cipher command manages encryption (EFS) of files and folders on NTFS drives. It can also overwrite the traces of deleted files in a drive’s free space.

This article focuses on two uses:

  • Encrypting and decrypting folders and files (/e, /d)
  • Wiping deleted data left in free space (/w)

Basic Usage

Syntax
cipher [/e | /d] [/s:folder] [/a] [/i] [/h] [path ...]
cipher /w:folder
cipher /x[:encrypted_file] output_file_name
OptionDescription
/eEncrypts the specified folder. Files added to it later are also encrypted
/dDecrypts the specified folder
/s:folderApplies the operation to the specified folder and all its subfolders
/aApplies the operation to files as well as folders
/iContinues even if errors occur
/hIncludes files with the hidden or system attribute
/w:folderOverwrites data left in the unused space of the volume
/xBacks up the certificate and private key used for encryption to a file

Checking the Encryption Status

Run without arguments, it lists the encryption status of the files and folders in the current folder.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>cipher
Listing C:\work
New files added to this directory will not be encrypted.
 
U memo.txt
E secret.txt
C:\users\user>

The letter at the start of each line shows the status.

LetterMeaning
UNot encrypted (Unencrypted)
EEncrypted
Output varies by environment

The output above is an example. The wording of the messages varies by Windows version and display language.

What to Know Before Encrypting

Encryption with cipher uses EFS (Encrypting File System). Check the following before you use it.

  • It works only on NTFS drives. FAT32 and exFAT drives (such as USB flash drives) can’t be encrypted
  • EFS isn’t available in Windows Home editions. You need Pro, Enterprise, Education, or a similar edition
  • Encrypted files can be opened only by users who hold the certificate and private key used to encrypt them. Other users and other operating systems can’t read them
  • If you copy an encrypted file to a non-NTFS drive such as FAT32 or exFAT, the copy is an unencrypted (plain) file
  • EFS doesn’t work on ReFS drives either
Back up your key right after you first encrypt

EFS keys are tied to your user account. If you lose the key, for example by reinstalling Windows or deleting the account, you can never open the encrypted files again. The certificate is created automatically the first time you encrypt something, so back it up right away as described in “Backing Up Your Key” below.

Encrypting a Folder

Run /e with a folder to make it an encrypted folder.

Encrypt
cipher /e "C:\work\secret"

In this state, files you add later are encrypted automatically. To also encrypt the files already in the folder, add /s and /a.

Encrypt
cipher /e /a /s:"C:\work\secret"

In File Explorer, the names of encrypted files are shown in green by default.

Encrypt the parent folder too

If the parent folder isn’t encrypted, an encrypted file may be saved in decrypted form when you edit it. Encrypt the folder that contains the files, not only the files themselves.

Quote paths that contain spaces

Enclose paths with spaces, such as C:\My Documents, in ". With /s:, enclose the part after it, as in /s:"C:\My Documents".

Decrypting

To decrypt, use /d instead of /e.

Decrypt
cipher /d /a /s:"C:\work\secret"

Backing Up Your Key

This exports the certificate and private key used for encryption as a .pfx file. You’ll be asked for a password, and the file is protected with it. If you haven’t encrypted anything yet, encrypt a folder first so the certificate is created.

Back
cipher /x "%USERPROFILE%\Desktop\efs-backup"

This creates efs-backup.pfx on your desktop. Store it in a different place from the encrypted files, such as an external drive. If you keep both on the same drive, a failure of that drive loses both.

Never hand out the .pfx file

A .pfx file contains your private key. Anyone who knows the password can open your encrypted files, so be careful with where you store it and with the password.

Wiping Deleted Data (/w)

Deleting a file doesn’t immediately erase its data from the disk. The space is just marked as free, and data recovery software may be able to restore it.

cipher /w overwrites the unused space of a volume so that deleted data is harder to recover. Use it, for example, before handing over or disposing of a PC.

Wipe
cipher /w:C:\

For /w:, specify any folder on the volume you want to wipe. The unused space of the whole volume containing that folder is processed. /w ignores other options, so combining it with /e or similar has no effect.

It overwrites the free space three times, with 0x00, 0xFF, and random data, in that order. Depending on the drive size and free space, it can take tens of minutes to several hours.

Files that exist now are not erased

/w wipes only space that has already been deleted and is unused. Your current files are left as they are. However, the drive’s free space is temporarily filled while it runs, so avoid other work in the meantime.

Small files may be skipped

Data of very small files (under about 1 KB) is stored in NTFS’s management area (the MFT), so /w may not overwrite it.

Limited effect on SSDs

On SSDs, wear leveling spreads writes around, so some areas that still hold the original data may remain even after overwriting. To reliably erase SSD data, encrypt the whole drive with BitLocker or similar from the start, or use the manufacturer’s erase tool (such as Secure Erase).

Using It in a Batch File

This batch file checks that the folder exists before encrypting, then shows the result.

encrypt-folder.cmd
@echo off
set "TARGET=%~1"

if "%TARGET%"=="" (
    echo Usage: encrypt-folder.cmd folder_path
    exit /b 1
)

if not exist "%TARGET%\" (
    echo Folder not found: "%TARGET%"
    exit /b 1
)

cipher /e /a /s:"%TARGET%"

echo.
echo Check the result. Entries marked E are encrypted.
cipher "%TARGET%"

For arguments and existence checks, see

and .

Don't judge success by the exit code alone

The exit code of cipher isn’t officially defined. Even when it fails, for example on a non-NTFS drive, the exit code may not tell you, so check the output and the encryption status (E) as in the example above.

Summary

GoalCommand
Check the encryption statuscipher
Encrypt a foldercipher /e "folder"
Encrypt including existing filescipher /e /a /s:"folder"
Decryptcipher /d /a /s:"folder"
Back up the certificate and keycipher /x "output_file_name"
Wipe deleted datacipher /w:C:\

Practice Questions

Practice Problem

Which option overwrites the traces of deleted files in a drive’s free space?

Choose one answer.

  1. /e
  2. /x
  3. /w

Practice Problem

Which statement about encryption (EFS) with cipher is correct?

Choose one answer.

  1. Folders on a FAT32 USB flash drive can also be encrypted
  2. If you lose the key you can’t open the encrypted files, so back it up with cipher /x
  3. Running cipher /w also securely erases the files that exist now
#Command Prompt #Command Line #Commands #cipher #Encryption #EFS #Security #File Operations