JPG-Repair Introduction

In this page I’ll try describe the methods available in JPG-Repair to repair JPEG photos. Repairing files with corrupt headers is easiest. It is a matter of placing the corrupt files + a sample file in one folder and clicking the repair button.

Automatic repair has it’s limits and that’s why JPG-Repair allows you to patch/edit the actual JPEG data to correct visual errors. Editing the JPEG data stream requires more skill, patience and a bit of luck.

Most repairs can be done by simply selecting the folder that contains the corrupt files (and if needed a reference or sample file) and clicking ‘Repair’.

Get started quickly with these videos
Corrupt header (no thumbnail, will not open) Corrupt RAW photo (CR2, NEF etc.) Part of image grey, distorted area


Describes the underlying method used by JPG-repair.

Repairing photos using JPG-repair Toolkit

How to recognize different types of JPEG corruption.

Repair corrupted JPEGs

How to repair corrupted JPEG headers. Corrupted headers result in different photo viewers and editor refusing to open the photo at all.

Repair corrupted RAW photos

How to get use-able data from corrupted RAW photos such as Cr2 (Canon) and NEF (Nikon). 

Repair corrupted data in JPEG bit stream

Editing RAW JPEG data with visual feedback to repair color errors and image shift and also grey blocks.

JPEG diagnostics

Unfortunately, often the question is now how a photo can be repaired, but if it can be repaired. JPG-Repair Toolkit offers some tools to diagnose corrupt JPEG photos.


To a PC a file is nothing but a bunch of binary data. The most accessible form for humans to ‘read’ that data is in HEX code. Below you see a hex dump of the file we’ll use as an example on this page.

Our JPEG file in HEX code

When I started my attempts to repair corrupt JPEG files it was this hex editor I used. I edited, added or removed bytes. This is also called patching. I then used a photo viewer to watch the effects.

Essentially JPG-Repair uses the exact same methods I used back then. The difference is that it hides the HEX code and instead provides you with visual feedback when adding / removing bytes to / from the JPEG data stream.

JPG-Repair offers tools to alter the HEX code inside a JPEG file. This is different than what a normal photo editor does. A normal editor ‘decodes’ the JPEG file, then allows you to edit or change it (apply filters, crop, flip etc.) and then encodes the file again. You change the image on the canvas, and then that end result is saved. In effect you end up with a completely new file. It will completely change the hex code.

JPG-Repair on the other hand never decodes the file. After each change you make, it simply dumps that to the raw HEX code, and then only decodes so it can show you a preview of the altered file. The same as I did with the hex editor and then opening the file in a photo viewer to watch the effects. For the largest part the hex code of the file remains the same.

JPG-Repair is not a photo editor!

So, the UI of JPG-Repair is basically nothing else than an overlay for the raw hex data inside a JPEG file. This is where JPG-Repair is totally different from ordinary photo editors:

JPG-Repair Toolkit versus a conventional photo editor.

Normal editor: Open file > decompress and decode file > display decoded data > allow modification of decoded data > to save, encode and compress data. This process always includes loss of image quality due to encoding algorithms. Even if you do not change the image, information is lost by re-encoding.

JPG-repair: Open file > edit raw data > show preview of raw data > save raw data. If no changes are made by JPG-Repair, image data is exactly the way it was as before you opened the file. As no data is re-encoded, the process is lossless. Of course if you use JPG-Repair to remove say 180 corrupted bytes, the file that is saved is equal to the original file minus the 200 corrupted bytes.


JPEG structures

JPG-repair allows to patch intact headers on files with corrupt headers. You can also edit the raw data that makes up the actual image. a JPEG file is made up of several sections. Each section is preceded by a JPEG Marker which defines what the following section is all about. Each marker defines the size of the section so that the next marker can be found. If any of those markers is corrupt, the file becomes corrupt. If the raw data that makes up the actual image (JPEG encoded data) becomes corrupt, your file may partially ‘render’: Part of the picture shows, while the rest is distorted or absent (Grey block, colored block, striped block).

A single wrong byte value can cause the rest of the image to turn to a solid grey or colored block

A single wrong byte value can cause the rest of the image to turn to a solid grey or colored block

JPG-Repair allows you to repair the section preceding the raw image data (sometimes called the header) using an intact JPEG file. It can also repair some errors in the raw JPEG data and allows you to patch (alter) this raw data.

Repairing photos with JPG-Repair Toolkit

JPG-Repair Toolkit editor allows correction of color and shift errors in corrupted jpeg
JPEG repair offers a number of tools to diagnose, repair and extract images in and from corrupt JPEG and RAW photo files

Please do not let the different buttons and options intimidate you. For most simple repairs you only need the section of the left the window. In general JPEG corruption is one of two (or both): A corrupt header or bit corruption in the actual image data. Typically the first photo is what you get when the header is corrupt. In the second example, the image actually can be opened but ‘distorts’ at some point due to bit errors in the JPEG data. 

Typical case of a corrupt header: Windows can not show a preview.

Typical case of a corrupt header: Windows can not show a preview.

Corrupt data in JPEG data. Windows may even show an intact preview, but main picture will look something like this


1 Repair corrupt JPEGs 

You need a sample file when repairing JPEGs with corrupted headers only. If the header of a JPEG is corrupted it is likely you will not be able to open it at all.

A sample file is a JPEG shot with the same camera using the same settings. For JPG-Repair to recognize it it needs to be renamed to sample.jpg.

Steps to repair corrupted JPEG headers:

  1. Select a repair mode > Pick Repair (header)
  2. You can skip the parsing options, leave default.
  3. Browse to the folder containing the corrupt file(s) and your sample. Select the corrupted files, no need to select the sample file.
  4. Click Repair.
select multiple corrupted jpegs by holding CTRL or SHIFT key

select multiple corrupted jpegs by holding CTRL or SHIFT key

JPG-Repair will get to work and save files using the following format: OriginalName-1.JPG. For each file it is able to repair it will show a preview and certain details such as resolution.

If JPEGs are not repaired or JPG-Repair reports ‘an error occurred processing this image’, the image may be beyond repair. Refer to the paragraph in interpreting the byte histogram and entropy to determine if a file can be repaired or not.


1 Repair corrupt RAW photos (NEF, CR2 etc.) 

Note: technically RAW files are not repaired. All JPG-Repair does is scan the corrupt RAW photo for embedded JPEG data > validate that data > save the data to a JPEG file. JPG-Repair can extract embedded JPEGs from damaged JPEG files too.

There are several tools available to extract embedded JPEGs from RAW photos. The difference between those and JPG-Repair is that the latter can also do this if RAW photos are corrupted.

Steps to extract JPEGs from corrupted RAW photos:

  1. Select a repair mode > Pick Extract JPEG
  2. Select a minimum resolution (see below).
  3. Browse to the folder containing the corrupted RAW file(s) and select those you want to extract embedded JPEGs from.
  4. Click Repair.

For RAW files select a minimum resolution, probably > 1.9 (MP) to skip lower resolution thumbnails and medium sized previews. Many RAW photo formats contain a full size JPEG. If this setting is set to a too low value, JPG-Repair may simply extract the medium sized preview. If too high it will skip every JPEG it comes across.

JPG-Repair will get to work and save files using the following format: OriginalName-1.JPG. For each file it is able to repair it will show a preview and certain details such as resolution.

If JPEGs are not repaired or JPG-Repair reports ‘an error occurred processing this image’, the image may be beyond repair. Refer to the paragraph in interpreting the byte histogram and entropy to determine if a file can be repaired or not.


Repairing errors in JPEG data stream

There are three things you can do with the ‘patcher’ or the editor:

  • Remove bytes
  • Add or insert bytes
  • Change the value of a byte

The basic operations are removing data (bytes) and adding bytes. Removing bytes in general causes image data to shift left, adding bytes shift all data from the point we’re patching to the right. Removing bytes allows you to weed out corrupted data that is causing the image to distort. Using this method it is often possible to repair color errors (where colors are off after a certain point in the image) and correct shift.

Step 1 is always removing corrupt data. In case the image partially displays this is caused by invalid markers. These are bytes that happen to correspond with what the JPEG specification defines as markers. JPG-Repair repairs those  automatically when you load an image and click repair. Often there is not just this one invalid marker, but it is surrounded by more corrupted bytes. And often these corrupt bytes tend to clutter. So we need to get rid of all those bad bytes. 

Using JPEG-Repair you cane experiment with removing, adding and changing bytes while it provides you with visual feedback.

You are either adding, removing or changing bytes. In general you start removing bytes until colors above and below the corrupted area match. You then save the file, and re-open the last saved file to start adding bytes to correct shift. If this is to vague, I strongly suggest to watch the above videos (video on the right).

If you remove 200 bytes and click apply, JPG-Repair shows you the ‘original’ image with the 200 bytes removed. You decide to try 300 bytes and click apply. JPG-Repair now shows the original image with 300 bytes removed from a certain byte address (and not 500: it is not like you first removed 200 and then an additional 300). So, each time you click apply it is a new experiment.

It is often possible to repair corruption in actual JPEG image data by removing the offending bytes. We call this ‘patching’. If a corrupt byte violates the JPEG standard (invalid marker) JPG-Repair will remove that data automatically. No sample file is required.

Editor to patch raw bytes in the jpeg bitstream

The editor controls explained

Section 1

Here you select if you will be removing, adding or changing bytes. In general removing bytes will cause the image below edited bytes to shift to the left, adding bytes will shift to the right. Result of changing bytes in unpredictable. ‘Free edit mode’s is automatically selected if no bad bytes were detected in the JPEG bitstream.

Re-align: Automatically add ‘stuff bytes’ to compensate for image shift that is caused by removing bytes.

Section 2

Here you specify the number of bytes you want to remove or add. The slider changes jump size for number of bytes that are selected with up/down arrows. So if you want to experiment with small changes, slide the slider to the left.

Byte values are in range 0 – 255 (00 to FF in hex).

Section 3

Here you navigate through the file, location is expressed in a byte address. The different arrows allow for small, medium and large jumps. The button below the byte address is the ‘Apply’ button. Blue up/down is for copy and paste the byte address to and from the clipboard.

Section 4

First button pastes the image to the Windows clipboard so you can import it to included photo heal tool or another photo editor (use paste or CTRL-V).

Save button below dumps all binary data to a new file. The image itself is never decoded or encoded like normal photo editors do.

Section 5

Enables magnifier and allows zooming magnifier. Once enabled, keep mosue button pressed on image to activate the magnifier.

Steps to repair / patch JPEG data bit stream:

  1. Browse to folder containing the corrupt file.
  2. leave file parsing default.
  3. Select mode ‘Patch’.
  4. Click Repair.

Three things can happen now:

  1. JPG-Repair detects ‘bad bytes‘, removes offending bytes and image looks good.
  2. JPG-Repair detects ‘bad bytes‘, repair those but image or colors still ‘shift’. If so, up the value for ‘remove bytes’ and click apply. JPG-Repair will add/remove bytes from the bad byte location. Experiment with higher values and see if image improves. Bad data tends to clutter.

  3. No bad bytes detected but still a distorted image (color errors and shifts in image data).

If the latter, no bad bytes detected:

Time for a little adventure! Finding the right spot requires patience and some luck. Do not be afraid to try things, the original corrupt file is not altered in any way. You can not make anything worse.

Due to encoding and compression of image data,there is no direct correlation between any pixel in an JPEG image and a corresponding byte. So, main challenge is to find the byte(s) corresponding with the corrupted area.

  1. Click on image in the area of corruption. Increase value for ‘remove bytes’ to 48 – 96 and click apply (v button). You have now introduced new corruption. 
  2. If new corruption is below the original corruption use the buttons to go backwards in the file. Click apply. Repeat until your corruption is close to original corruption. The goal is to overlap the old with the new corruption. 
  3. Once at the correct location start increasing value for ‘remove bytes’ until colors below and above corruption match as closely as possible.
  4. Use copy button to remember the byte address or simply write it down.
  5. Click save button.

Use magnifier to zoom in on details:

What the start of the jpeg corruption typically looks like

What the start of the corruption typically looks like






Bad bytes were detected:

This is often the case and the byte address automatically adjusted. If damage is limited to one area then you can now immediately start removing bytes and watch the effect on the image. Goal is to remove enough corrupted bytes, so color above and below the corrupted area match as good as possible.

Once the result is acceptable (apart from image shift), click Save.

To shift image back again:

  1. Select the file you have just saved and click ‘repair’
  2. Paste byte address that you saved earlier.
  3. Select ‘add bytes’ and increase value.
  4. Click apply and view
  5. Repeat until image shifted back

If you removed a large amount of bytes you may need to do more than just shift the image to align. It may be required to insert several rows of pixels to get the right amount of space between the higher and lower portion of the image.

Adding bytes leaves a ‘grey-ish’ square. You can use the included Photo Heal tool to repair this. Easiest is to copy the image to the clipboard and import to Photo Heal using CTRL-V. You can also simply save the file and open it in Photo Heal.

Condition of a file

Not all JPEG files can be repaired. In fact I see that a lot unfortunately. JPG-Repair does several analysis on each file it processes that may help you determine why a file can not be repaired.

JPEG data has certain properties due to the fact that it is encoded and compressed. For example, all byte values are used/present in a JPEG, unlike for example a text document. Also, due to compression the file data has high entropy (chaotic, unpredictable).
Assume following uncompressed data: AAAAAABBAACAAAABCCCAAAA = 23 characters. Let’s try compress this using the simplest method I can come up with right now: 6A2B2AC4AB3C4A = 14 characters. Instead of writing out 6 A’s, we simply indicate by 6A that uncompressed data contains AAAAAA. Followed by 2 * B, 2 * A, C, 4 * A etc.. When we compare the compressed and the uncompressed data we see uncompressed data is less random and less predictable. Compressed data appears more random. Cutting corners here, but you could call that higher entropy. And this is sort of what we see in JPEG files as well.

JPG-Repair shows entropy and a byte histogram

Entropy in a JPEG file is somewhere around 7.6 – 7.9 bits per byte. A tad higher? Then the data is probably encrypted which is what I see a lot with JPEGs copied from Android devices such as smart-phones. In that case the file can not be repaired. The byte histogram shows you occurrence of bytes with specific values. Above shows a quite normal JPEG. Note that the zero value (blue bar on the left) is highest, this is common for JPEG files. Below are examples of files that are beyond repair:

 Only lower half of byte values used, probably other file format. So, this NOT mean only half the file is filled. There are simply only byte values found in range 0 – 128.

 File is filled with zeros, see blue bar on left. This file can of course not be repaired. Often caused by fake memory card.

 File is filled with a pattern, see bar at right, value 255 (equals FF in hex). Can be symptom of files being saved to a fake memory card.

It is also possible to simply inspect the file visually, click the right button under tools to open a hex viewer.
Only half the image because data is missing

Only half the image because data is missing. At some point if file there are only zeros.