diff --git a/lib/ibandit/iban.rb b/lib/ibandit/iban.rb
index <HASH>..<HASH> 100644
--- a/lib/ibandit/iban.rb
+++ b/lib/ibandit/iban.rb
@@ -20,7 +20,7 @@ module Ibandit
 
     def to_s(format = :compact)
       case format
-      when :compact   then iban
+      when :compact   then iban.to_s
       when :formatted then formatted
       else raise ArgumentError, "invalid format '#{format}'"
       end
@@ -215,7 +215,7 @@ module Ibandit
     end
 
     def formatted
-      iban.gsub(/(.{4})/, '\1 ').strip
+      iban.to_s.gsub(/(.{4})/, '\1 ').strip
     end
   end
 end
diff --git a/spec/ibandit/iban_spec.rb b/spec/ibandit/iban_spec.rb
index <HASH>..<HASH> 100644
--- a/spec/ibandit/iban_spec.rb
+++ b/spec/ibandit/iban_spec.rb
@@ -91,6 +91,12 @@ describe Ibandit::IBAN do
     end
 
     specify { expect { iban.to_s(:russian) }.to raise_error ArgumentError }
+
+    context 'with the IBAN is nil' do
+      let(:arg) { { country_code: 'GB' } }
+      its(:to_s) { is_expected.to_not be_nil }
+      specify { expect(iban.to_s(:formatted)).to be_empty }
+    end
   end
 
   ###############
Don't ever return nil from IBAN#to_s, even if IBAN#iban is nil