Unwanted padding for pictures with padding?

If you ever put a caption to a picture on a wordpress website then you may have noticed that on the left and right there is suddenly 5px of space added.

This is because standard WordPress increases the width of the div with 10px as the captions shortcode is used. If you use your own WordPress theme, this can be very annoying. Fortunately, there is also a WordPress filter that you can use here.
This code I didn't written by himself but comes directly from Mightyminnow.com where I found it when I ran into this problem:

1 2 3 4 56 7 8 9 10
/**  * Remove WordPress's default padding on images with captions  *  * @param int $width Default WP .wp-caption width (image width + 10px)  * @return int Updated width to remove 10px padding */ function remove_caption_padding( $width ) {     return $width - 10; } add_filter( 'img_caption_shortcode_width', 'remove_caption_padding' );

Put the above code in your functions.php and your problem is solved. I've been using it on this website and it works perfectly.
By default, $width has the value of 10. On line 8 of the code you actually read that padding is 10-10= 0
You can now also change this for something else if you want. For example; you want padding but 4px is enough for you. Just change line 8 in  $width - 6; . Because 10-6 = 4. Have fun!