By Pritesh Tailor
I see a lot of photos with distortion, particularly when it comes to architecture. Don't get me wrong, you can and should use distortion creatively.
Distortion is the change in shape (often unintentional but not always) that occurs in the composition taken by the photographer. Distortion isn't always obvious, a good way to spot, is by enabling the grid in the tool you use, Photoshop, Lightroom etc. From there, mapping any lines in your composition to the grid, will help you see what type of distortion it is, whether it has any creative value. If not, it helps you understand what you need to fix.
So what are the types? Optical & Perspective.
Barrel distortion changes the shape by replacing straightened lines in a scene with a semi-circular curve outwards. Its common with wide angle lenses, which elongate the foreground, so when an object is placed on the edges of the frame, the object will appear distorted. Distortion can be more visible on crop sensor cameras, particularly when the field of view is wider than the camera sensor.
Pincushion is the counterpart to the wide angle lens distortion. This occurs at the long end of telephoto lenses, due to the field of view being narrower than that of the sensor. The size of the sensor in combination with working on the extreme end of a telephoto zoom lenses will make the distortion more visible. The scene, particularly on the edges will appear to be going inwards.
Perspective distortion is caused by the photographer rather than the lens. It's usually caused by the angle and perspective you shoot at. I see this type of distortion in plenty of architectural shots.
The image below was shot using a 15-45mm lens at 17mm on a crop sensor camera. I took the composition at the bottom of the stairs and suffers from both perspective and optical (barrel) distortion. The camera was pointing up towards the top of the building and I was shooting from a lower position, which resulted in the image appearing to lean back.

The below image was produced after I applied both the optical and perspective distortion fixes using Lightroom. Whenever you try to fix distortion, it will most often result in the need to crop the image, as below.

NOTE: if distortion does have creative merit in your photo, it's your choice whether to include it as part of your composition.
The fixes
Understanding your lens
To understand where distortion becomes more visible on your lens, you could stick an image of a grid on a wall and take a series of shots at different focal lengths. Having imported these photos into Lightroom/Photoshop, you can then identify at what focal lengths, distortion has an impact. Next time you're out on a photography trip, you'll be better prepared for creating compositions that reduce your time fixing distortion problems later in post processing.
Optical Distortion in Lightroom
Inside of the develop module, under the lens correction tab, you can select 'Enable Profile Corrections', this will look through a database of lens profiles and retrospectively remove the distortion based on the lens. This will automatically work if you've shot in raw and imported your photos with your exif data (and lightroom has a profile for your lens). If not, you can manually select the lens profile yourself, after selecting 'Enable Profile Corrections'. This option does remove optical distortion fairly well, however, it won't solve the problem of perspective distortion.
TIP: To save time on fixing optical distortion, you can setup a preset that includes lens correction, which you can apply when you import your photos.
Perspective Distortion in Lightroom
With perspective distortion there's two options, buying a tilt and shift lens or adding a fix in post process. I'll run through how I corrected the distortion problems in the image above.
1. First I enabled the grid, by going to 'View', 'Loupe Overlay' and then 'Grid'.

2. Under the develop module, you'll find the 'Transform' tool. The tool provides 4 default options for distortion correction, Auto, Level, Vertical and Full. Sometimes these options will correct the distortion issues. However, if not, there's fifth option called 'guided'. With this option, it allows you to put guides along the distorted lines, giving you more control to correct distortion. Below is an example of using this. You'll notice the bottom half of the image has been cropped off. This has happened because I've constrained the crop.

3. In the screenshot below, i've taken off the constraint, leaving me with a corrected photo. However, because of those corrections, I now need to manually crop the image to finish off this edit.

4. Here's a comparison of the before and after. You can see that due to fix, we've cropped a part of the photo. It emphasises the need to understand the impact of how your shooting location will impact the work you need to do later.

Some tips
Don't place important objects in the corner of the frame, this will more than likely get distorted depending on the lenses (particular wide angle). Instead, you can use the rule of thirds to avoid extreme distortion by placing the most important elements of your composition on the grid intersections (another potential use of ).
Leave plenty of room around the subject, so your composition has enough breathing room. When you attempt to correct the perspective, you will likely need to crop the image.
Some links I found useful & some more detailed guides.